Skip to content

Commit

Permalink
优化产品模块各资源的表单和表格配置
Browse files Browse the repository at this point in the history
- 调整了多个资源的表单布局和字段配置,优化了整体结构
- 更新了部分字段的显示方式,如使用ToggleButtons替代Radio
- 增加了部分字段的过滤器功能,提升了筛选效率
- 修正了一些字段的默认值和验证规则
  • Loading branch information
liushoukun committed Oct 14, 2024
1 parent 6272c66 commit 37b007b
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 120 deletions.
42 changes: 25 additions & 17 deletions src/Clusters/Product/Resources/BrandResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
class BrandResource extends Resource
{
protected static ?int $navigationSort = 2;
protected static ?string $cluster = Product::class;
protected static ?string $model = Brand::class;
protected static ?string $cluster = Product::class;
protected static ?string $model = Brand::class;

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

Expand All @@ -50,7 +50,7 @@ public static function form(Form $form) : Form
return $form
->schema([
SelectTree::make('parent_id')
->label(__('red-jasmine-product::brand.fields.parent.name'))
->label(__('red-jasmine-product::brand.fields.parent.name'))
->relationship(
relationship: 'parent',
titleAttribute: 'name',
Expand All @@ -60,32 +60,40 @@ public static function form(Form $form) : Form
)
// ->required()
->searchable()
->default(0)
->defaultZero()
->enableBranchNode()
->parentNullValue(0)
,
Forms\Components\TextInput::make('name')
->label(__('red-jasmine-product::brand.fields.name'))
->required(),
Forms\Components\TextInput::make('description')
->label(__('red-jasmine-product::brand.fields.description'))

->maxLength(255),
Forms\Components\TextInput::make('english_name')
->label(__('red-jasmine-product::brand.fields.english_name'))
->required(),
,
Forms\Components\TextInput::make('initial')
->maxLength(1)
->label(__('red-jasmine-product::brand.fields.initial'))->required(),
->label(__('red-jasmine-product::brand.fields.initial'))
,
Forms\Components\TextInput::make('description')
->label(__('red-jasmine-product::brand.fields.description'))
->maxLength(255),
Forms\Components\FileUpload::make('logo')
->label(__('red-jasmine-product::brand.fields.logo'))
->image(),
Forms\Components\Radio::make('is_show')
->label(__('red-jasmine-product::brand.fields.is_show'))
->boolean()
->inline()
->default(true),
Forms\Components\TextInput::make('sort')
->label(__('red-jasmine-product::brand.fields.sort'))
->default(0)->required()->numeric()->minValue(0),
Forms\Components\Radio::make('is_show')
->label(__('red-jasmine-product::brand.fields.is_show'))
->boolean()->inline()->default(true),
Forms\Components\Radio::make('status')->label(__('red-jasmine-product::brand.fields.status'))
->options(BrandStatusEnum::options())
->inline()->default(BrandStatusEnum::ENABLE->value),

Forms\Components\ToggleButtons::make('status')->label(__('red-jasmine-product::brand.fields.status'))
->inline()
->grouped()
->useEnum(BrandStatusEnum::class)
,

...static::operateFormSchemas()
])->columns(1);
Expand All @@ -110,7 +118,7 @@ public static function table(Table $table) : Table
Tables\Columns\IconColumn::make('is_show')->label(__('red-jasmine-product::brand.fields.is_show'))->boolean(),
Tables\Columns\TextColumn::make('sort')->label(__('red-jasmine-product::brand.fields.sort'))->sortable(),
Tables\Columns\TextColumn::make('status')->label(__('red-jasmine-product::brand.fields.status'))
->badge()->formatStateUsing(fn($state) => $state->label())->color(fn($state) => $state->color()),
->useEnum(),


...static::operateTableColumns()
Expand Down
59 changes: 36 additions & 23 deletions src/Clusters/Product/Resources/ProductCategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use RedJasmine\FilamentCore\Filters\TreeParent;
use RedJasmine\FilamentProduct\Clusters\Product;
use RedJasmine\FilamentCore\Helpers\ResourcePageHelper;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductCategoryResource\Pages\CreateProductCategory;
Expand All @@ -27,8 +29,8 @@
class ProductCategoryResource extends Resource
{
protected static ?int $navigationSort = 3;
protected static ?string $cluster = Product::class;
protected static ?string $model = ProductCategory::class;
protected static ?string $cluster = Product::class;
protected static ?string $model = ProductCategory::class;

use ResourcePageHelper;

Expand All @@ -48,15 +50,15 @@ public static function getModelLabel() : string
public static function form(Form $form) : Form
{
return $form
->columns(1)
->schema([

SelectTree::make('parent_id')
->label(__('red-jasmine-product::product-category.fields.parent_id'))
->label(__('red-jasmine-product::product-category.fields.parent_id'))
->relationship(relationship: 'parent', titleAttribute: 'name', parentAttribute: 'parent_id',
modifyQueryUsing: fn($query, Forms\Get $get, ?Model $record) => $query->when($record?->getKey(), fn($query, $value) => $query->where('id', '<>', $value)),
modifyChildQueryUsing: fn($query, Forms\Get $get, ?Model $record) => $query->when($record?->getKey(), fn($query, $value) => $query->where('id', '<>', $value)),
)
// ->required()
->searchable()
->default(0)
->enableBranchNode()
Expand All @@ -78,19 +80,24 @@ public static function form(Form $form) : Form
->label(__('red-jasmine-product::product-category.fields.sort'))
->required()
->default(0),
Forms\Components\Toggle::make('is_leaf')
->label(__('red-jasmine-product::product-category.fields.is_leaf'))
->required()
->default(0),
Forms\Components\Toggle::make('is_show')
->label(__('red-jasmine-product::product-category.fields.is_show'))
->required()
->default(1),
Forms\Components\Radio::make('status')
->label(__('red-jasmine-product::product-category.fields.status'))
Forms\Components\Radio::make('is_leaf')
->label(__('red-jasmine-product::product-category.fields.is_leaf'))
->required()
->default(CategoryStatusEnum::ENABLE)
->options(CategoryStatusEnum::options()),
->boolean()
->inline()
->default(0),
Forms\Components\Radio::make('is_show')
->label(__('red-jasmine-product::product-category.fields.is_show'))
->required()
->boolean()
->inline()
->default(1),
Forms\Components\ToggleButtons::make('status')
->label(__('red-jasmine-product::product-category.fields.status'))
->required()
->grouped()
->default(CategoryStatusEnum::ENABLE)
->useEnum(CategoryStatusEnum::class),
]);
}

Expand Down Expand Up @@ -125,30 +132,36 @@ public static function table(Table $table) : Table
->sortable(),
Tables\Columns\TextColumn::make('status')
->label(__('red-jasmine-product::product-category.fields.status'))
->enum(),
->useEnum(),

... static::operateTableColumns(),

])
->filters([
//

TreeParent::make('tree')->label(__('red-jasmine-product::product-category.fields.parent_id')),
Tables\Filters\SelectFilter::make('status')
->label(__('red-jasmine-product::product-category.fields.status'))
->options(CategoryStatusEnum::options()),

])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
// Tables\Actions\DeleteBulkAction::make(),
// Tables\Actions\DeleteBulkAction::make(),
]),
]);
}



public static function getPages() : array
{
return [
'index' => ListProductCategories::route('/'),
// 'create' => CreateProductCategory::route('/create'),
'edit' => EditProductCategory::route('/{record}/edit'),
'index' => ListProductCategories::route('/'),
// 'create' => CreateProductCategory::route('/create'),
'edit' => EditProductCategory::route('/{record}/edit'),
];
}
}
20 changes: 13 additions & 7 deletions src/Clusters/Product/Resources/ProductGroupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use RedJasmine\FilamentCore\Filters\TreeParent;
use RedJasmine\FilamentCore\Helpers\ResourcePageHelper;
use RedJasmine\FilamentProduct\Clusters\Product;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\ProductGroupResource\Pages\CreateProductGroup;
Expand Down Expand Up @@ -51,6 +52,7 @@ public static function getModelLabel() : string
public static function form(Form $form) : Form
{
return $form
->columns(1)
->schema([
...static::ownerFormSchemas(),

Expand Down Expand Up @@ -91,17 +93,18 @@ public static function form(Form $form) : Form
->default(0),
Forms\Components\Radio::make('is_leaf')
->label(__('red-jasmine-product::product-group.fields.is_leaf'))
->default(false)->boolean()->inline()->inlineLabel(false)->required(),
->default(false)->boolean()->inline()->required(),
Forms\Components\Radio::make('is_show')
->label(__('red-jasmine-product::product-group.fields.is_show'))
->default(true)->boolean()->inline()->inlineLabel(false)->required(),
->default(true)->boolean()->inline()->required(),

Forms\Components\Radio::make('status')
Forms\Components\ToggleButtons::make('status')
->label(__('red-jasmine-product::product-group.fields.status'))
->required()
->grouped()
->default(GroupStatusEnum::ENABLE)
->options(GroupStatusEnum::options())
->inline()->inlineLabel(false)->required(),
->useEnum(GroupStatusEnum::class)
,


... static::operateFormSchemas()
Expand Down Expand Up @@ -139,12 +142,15 @@ public static function table(Table $table) : Table

Tables\Columns\TextColumn::make('status')
->label(__('red-jasmine-product::product-group.fields.status'))
->enum(),
->useEnum(),
...static::operateTableColumns()

])
->filters([
//
TreeParent::make('tree')->label(__('red-jasmine-product::product-group.fields.parent_id')),
Tables\Filters\SelectFilter::make('status')
->label(__('red-jasmine-product::product-group.fields.status'))
->options(GroupStatusEnum::options()),
])
->actions([
Tables\Actions\EditAction::make(),
Expand Down
28 changes: 18 additions & 10 deletions src/Clusters/Product/Resources/ProductPropertyGroupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ProductPropertyGroupResource extends Resource
protected static ?string $createCommand = ProductPropertyGroupCreateCommand::class;
protected static ?string $updateCommand = ProductPropertyGroupUpdateCommand::class;
protected static ?string $deleteCommand = ProductPropertyGroupDeleteCommand::class;

protected static ?int $navigationSort = 6;

public static function getModelLabel() : string
{
Expand All @@ -59,22 +59,26 @@ public static function form(Form $form) : Form
->label(__('red-jasmine-product::product-property-group.fields.description'))
->maxLength(255),
Forms\Components\TextInput::make('sort')->label(__('red-jasmine-product::product-property-group.fields.sort'))
->required()->integer()->default(0),
Forms\Components\Radio::make('status')->label(__('red-jasmine-product::product-property-group.fields.status'))
->required()
->default(PropertyStatusEnum::ENABLE)->options(PropertyStatusEnum::options())
->inline()->inlineLabel(false)->required(),
->required()
->integer()
->default(0),
Forms\Components\ToggleButtons::make('status')->label(__('red-jasmine-product::product-property-group.fields.status'))
->inline()
->required()
->default(PropertyStatusEnum::ENABLE)
->useEnum(PropertyStatusEnum::class)
,

...static::operateFormSchemas()
])->columns(1);
])->columns(1);
}

public static function table(Table $table) : Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label(__('red-jasmine-product::product-property-group.fields.id'))
->label(__('red-jasmine-product::product-property-group.fields.id'))
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('name')->label(__('red-jasmine-product::product-property-group.fields.name'))
Expand All @@ -83,11 +87,15 @@ public static function table(Table $table) : Table
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('status')->label(__('red-jasmine-product::product-property-group.fields.status'))
->badge()->formatStateUsing(fn($state) => $state->label())->color(fn($state) => $state->color()),
->useEnum(),


...static::operateTableColumns()
])
])
->filters([
Tables\Filters\SelectFilter::make('status')
->label(__('red-jasmine-product::product-property-value.fields.status'))
->options(PropertyStatusEnum::options()),
Tables\Filters\TrashedFilter::make(),
])
->deferFilters()
Expand Down
Loading

0 comments on commit 37b007b

Please sign in to comment.