Skip to content

Commit

Permalink
新增商品标签功能
Browse files Browse the repository at this point in the history
- 添加商品标签相关的数据模型、仓库和应用服务
- 实现商品标签的创建、编辑和列表展示页面- 在数据库中创建商品标签表
- 更新导航栏显示,增加商品标签相关功能
  • Loading branch information
liushoukun committed Oct 12, 2024
1 parent e3f1760 commit d653b0d
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/Clusters/Product/Resources/ProductGroupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,21 @@
class ProductGroupResource extends Resource
{

use ResourcePageHelper;


protected static ?int $navigationSort = 4;
protected static ?string $cluster = Product::class;
protected static ?string $model = ProductGroup::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-group';


use ResourcePageHelper;
protected static ?string $commandService = ProductGroupCommandService::class;
protected static ?string $queryService = ProductGroupQueryService::class;
protected static ?string $createCommand = ProductGroupCreateCommand::class;
protected static ?string $updateCommand = ProductGroupUpdateCommand::class;
protected static ?string $deleteCommand = ProductGroupDeleteCommand::class;
protected static bool $onlyOwner = true;

public function __construct()
{
}

public static function getModelLabel() : string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function getModelLabel() : string

public static function getNavigationGroup() : ?string
{
return __('red-jasmine-product::product-property.labels.product-property');
return __('red-jasmine-product::product-property.labels.property');
}

public static function form(Form $form) : Form
Expand Down
2 changes: 1 addition & 1 deletion src/Clusters/Product/Resources/ProductPropertyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function getModelLabel() : string

public static function getNavigationGroup() : ?string
{
return __('red-jasmine-product::product-property.labels.product-property');
return __('red-jasmine-product::product-property.labels.property');
}

public static function form(Form $form) : Form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function getModelLabel() : string

public static function getNavigationGroup() : ?string
{
return __('red-jasmine-product::product-property.labels.product-property');
return __('red-jasmine-product::product-property.labels.property');
}

public static function form(Form $form) : Form
Expand Down
168 changes: 168 additions & 0 deletions src/Clusters/Product/Resources/ProductTagResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php

namespace RedJasmine\FilamentProduct\Clusters\Product\Resources;

use RedJasmine\FilamentCore\Helpers\ResourcePageHelper;
use RedJasmine\FilamentProduct\Clusters\Product;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductTagResource\Pages;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductTagResource\RelationManagers;
use RedJasmine\Product\Application\Tag\Services\ProductTagCommandService;
use RedJasmine\Product\Application\Tag\Services\ProductTagQueryService;
use RedJasmine\Product\Application\Tag\UserCases\Commands\ProductTagCreateCommand;
use RedJasmine\Product\Application\Tag\UserCases\Commands\ProductTagDeleteCommand;
use RedJasmine\Product\Application\Tag\UserCases\Commands\ProductTagUpdateCommand;
use RedJasmine\Product\Domain\Tag\Models\Enums\TagStatusEnum;
use RedJasmine\Product\Domain\Tag\Models\ProductTag;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class ProductTagResource extends Resource
{
protected static ?string $model = ProductTag::class;

protected static ?string $navigationIcon = 'heroicon-o-tag';

protected static ?string $cluster = Product::class;
protected static ?int $navigationSort = 5;

use ResourcePageHelper;

protected static ?string $commandService = ProductTagCommandService::class;
protected static ?string $queryService = ProductTagQueryService::class;
protected static ?string $createCommand = ProductTagCreateCommand::class;
protected static ?string $updateCommand = ProductTagUpdateCommand::class;
protected static ?string $deleteCommand = ProductTagDeleteCommand::class;
protected static bool $onlyOwner = true;

public static function getModelLabel() : string
{
return __('red-jasmine-product::product-tag.labels.tag');
}

public static function form(Form $form) : Form
{
return $form
->schema([
...static::ownerFormSchemas(),
Forms\Components\TextInput::make('name')
->label(__('red-jasmine-product::product-tag.fields.name'))
->required()
->maxLength(255),
Forms\Components\TextInput::make('description')
->label(__('red-jasmine-product::product-tag.fields.description'))
->maxLength(255),
Forms\Components\TextInput::make('icon')
->label(__('red-jasmine-product::product-tag.fields.icon'))
->maxLength(255),
Forms\Components\ColorPicker::make('color')
->label(__('red-jasmine-product::product-tag.fields.color'))
,
Forms\Components\TextInput::make('cluster')
->label(__('red-jasmine-product::product-tag.fields.cluster'))
->maxLength(255),
Forms\Components\TextInput::make('sort')
->label(__('red-jasmine-product::product-tag.fields.sort'))
->required()
->numeric()
->default(0),
Forms\Components\Toggle::make('is_show')
->label(__('red-jasmine-product::product-tag.fields.is_show'))
->required()
->default(1),
Forms\Components\Toggle::make('is_public')
->label(__('red-jasmine-product::product-tag.fields.is_public'))
->required()
->default(0),
Forms\Components\Radio::make('status')
->label(__('red-jasmine-product::product-tag.fields.status'))
->required()
->inlineLabel()
->inline()
->default(TagStatusEnum::ENABLE)
->options(TagStatusEnum::options()),
...static::operateFormSchemas(),
]);
}

public static function table(Table $table) : Table
{
return $table
->columns([
...static::ownerTableColumns(),
Tables\Columns\TextColumn::make('name')
->label(__('red-jasmine-product::product-tag.fields.name'))
->searchable(),
Tables\Columns\TextColumn::make('description')
->label(__('red-jasmine-product::product-tag.fields.description'))
->searchable(),
Tables\Columns\TextColumn::make('icon')
->label(__('red-jasmine-product::product-tag.fields.icon'))
,
Tables\Columns\ColorColumn::make('color')
->label(__('red-jasmine-product::product-tag.fields.color'))
,
Tables\Columns\TextColumn::make('cluster')
->label(__('red-jasmine-product::product-tag.fields.cluster'))
->searchable(),
Tables\Columns\TextColumn::make('sort')
->label(__('red-jasmine-product::product-tag.fields.sort'))
->numeric()
->sortable(),
Tables\Columns\IconColumn::make('is_show')
->label(__('red-jasmine-product::product-tag.fields.is_show'))
->boolean()
->sortable(),
Tables\Columns\IconColumn::make('is_public')
->label(__('red-jasmine-product::product-tag.fields.is_public'))
->boolean()
->sortable(),
Tables\Columns\TextColumn::make('status')
->label(__('red-jasmine-product::product-tag.fields.status'))
->enum(),

...static::operateTableColumns()
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]);
}

public static function getRelations() : array
{
return [
//
];
}

public static function getPages() : array
{
return [
'index' => Pages\ListProductTags::route('/'),
'create' => Pages\CreateProductTag::route('/create'),
'edit' => Pages\EditProductTag::route('/{record}/edit'),
];
}

public static function getEloquentQuery() : Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductTagResource\Pages;

use RedJasmine\FilamentCore\Helpers\ResourcePageHelper;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductTagResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateProductTag extends CreateRecord
{
protected static string $resource = ProductTagResource::class;
use ResourcePageHelper;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductTagResource\Pages;

use RedJasmine\FilamentCore\Helpers\ResourcePageHelper;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductTagResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditProductTag extends EditRecord
{
protected static string $resource = ProductTagResource::class;
use ResourcePageHelper;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductTagResource\Pages;

use RedJasmine\FilamentCore\Helpers\ResourcePageHelper;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductTagResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListProductTags extends ListRecords
{
use ResourcePageHelper;
protected static string $resource = ProductTagResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

0 comments on commit d653b0d

Please sign in to comment.