Skip to content

Commit

Permalink
重构产品模块代码结构并添加新功能
Browse files Browse the repository at this point in the history
- 删除了旧的构建脚本和配置文件
- 更新了产品模块的命名空间和类名
- 添加了新的资源类和页面类
- 实现了品牌、产品分类、属性组等资源的创建、编辑和列表显示功能
- 优化了代码结构,提高了可维护性和扩展性
  • Loading branch information
liushoukun committed Oct 7, 2024
1 parent f62ae8c commit 657d2fa
Show file tree
Hide file tree
Showing 58 changed files with 2,678 additions and 157 deletions.
50 changes: 0 additions & 50 deletions bin/build.js

This file was deleted.

14 changes: 8 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@
"extra": {
"laravel": {
"providers": [
"Redjasmine\\FilamentProduct\\FilamentProductServiceProvider"
],
"aliases": {
"FilamentProduct": "Redjasmine\\FilamentProduct\\Facades\\FilamentProduct"
}
"RedJasmine\\FilamentProduct\\FilamentProductServiceProvider"
]
},
"branch-alias": {
"dev-master": "1.0.x-dev",
"dev-main": "1.0.x-dev",
"dev-develop": "1.0.x-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
2 changes: 1 addition & 1 deletion config/product.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// config for Redjasmine/FilamentProduct
// config for RedJasmine/FilamentProduct
return [

];
19 changes: 0 additions & 19 deletions database/factories/ModelFactory.php

This file was deleted.

19 changes: 0 additions & 19 deletions database/migrations/create_product_table.php.stub

This file was deleted.

1 change: 0 additions & 1 deletion resources/css/index.css

This file was deleted.

Empty file removed resources/dist/.gitkeep
Empty file.
Empty file removed resources/js/index.js
Empty file.
2 changes: 2 additions & 0 deletions resources/lang/en/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
// translations for Redjasmine/FilamentProduct
return [
//

'label'=>'Product',
];
8 changes: 8 additions & 0 deletions resources/lang/zh_CN/product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

// translations for RedJasmine/FilamentProduct
return [
//

'label' => '商品',
];
25 changes: 25 additions & 0 deletions src/Clusters/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace RedJasmine\FilamentProduct\Clusters;


use Filament\Clusters\Cluster;

class Product extends Cluster
{
protected static ?string $navigationIcon = 'heroicon-o-shopping-bag';


public static function getNavigationLabel() : string
{

return __('filament-product::product.label');
}


public static function getClusterBreadcrumb() : ?string
{
return __('filament-product::product.label');
}

}
56 changes: 56 additions & 0 deletions src/Clusters/Product/Pages/Dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace RedJasmine\FilamentProduct\Clusters\Product\Pages;


use Filament\Pages\Page;
use Filament\Widgets\Widget;
use Filament\Widgets\WidgetConfiguration;
use Illuminate\Contracts\Support\Htmlable;
use RedJasmine\FilamentProduct\Clusters\Product;

class Dashboard extends Page
{



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

public static function getNavigationLabel() : string
{
return '商品中心';
}


public function getTitle() : string|Htmlable
{
return '商品中心';
}

protected static ?string $slug = 'dashboard';
protected static ?int $navigationSort = -3;
protected static ?string $cluster = Product::class;
protected static string $view = 'filament-panels::pages.dashboard';

/**
* @return array<class-string<Widget> | WidgetConfiguration>
*/
public function getVisibleWidgets() : array
{
return $this->filterVisibleWidgets($this->getWidgets());
}

public function getWidgets() : array
{

return [

];
}

public function getColumns() : int|string|array
{
return 2;
}

}
142 changes: 142 additions & 0 deletions src/Clusters/Product/Resources/BrandResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

namespace RedJasmine\FilamentProduct\Clusters\Product\Resources;

use App\Filament\Clusters\Product\Resources\BrandResource\RelationManagers;
use CodeWithDennis\FilamentSelectTree\SelectTree;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use RedJasmine\FilamentCore\FilamentResource\ResourcePageHelper;
use RedJasmine\FilamentProduct\Clusters\Product;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\BrandResource\Pages\CreateBrand;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\BrandResource\Pages\EditBrand;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\BrandResource\Pages\ListBrands;
use RedJasmine\Product\Application\Brand\Services\BrandCommandService;
use RedJasmine\Product\Application\Brand\Services\BrandQueryService;
use RedJasmine\Product\Application\Brand\UserCases\Commands\BrandCreateCommand;
use RedJasmine\Product\Application\Brand\UserCases\Commands\BrandDeleteCommand;
use RedJasmine\Product\Application\Brand\UserCases\Commands\BrandUpdateCommand;
use RedJasmine\Product\Domain\Brand\Models\Brand;
use RedJasmine\Product\Domain\Brand\Models\Enums\BrandStatusEnum;

class BrandResource extends Resource
{
protected static ?int $navigationSort = 2;
protected static ?string $cluster = Product::class;
protected static ?string $model = Brand::class;

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

use ResourcePageHelper;

protected static ?string $commandService = BrandCommandService::class;
protected static ?string $queryService = BrandQueryService::class;
protected static ?string $createCommand = BrandCreateCommand::class;
protected static ?string $updateCommand = BrandUpdateCommand::class;
protected static ?string $deleteCommand = BrandDeleteCommand::class;


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

public static function form(Form $form) : Form
{
return $form
->schema([
SelectTree::make('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()
->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(),
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),
])->columns(1);
}

public static function table(Table $table) : Table
{

return $table
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('parent.name'),
Tables\Columns\TextColumn::make('name')
->label(__('red-jasmine.product::brand.fields.name'))
->searchable(),

Tables\Columns\TextColumn::make('initial')
->label(__('red-jasmine.product::brand.fields.initial')),
Tables\Columns\TextColumn::make('english_name')
->label(__('red-jasmine.product::brand.fields.english_name')),
Tables\Columns\ImageColumn::make('logo')->label(__('red-jasmine.product::brand.fields.logo')),
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()),


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

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

public static function getPages() : array
{
return [
'index' => ListBrands::route('/'),
'create' => CreateBrand::route('/create'),
'edit' => EditBrand::route('/{record}/edit'),
];
}
}
19 changes: 19 additions & 0 deletions src/Clusters/Product/Resources/BrandResource/Pages/CreateBrand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

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

use Filament\Resources\Pages\CreateRecord;
use RedJasmine\FilamentCore\FilamentResource\ResourcePageHelper;
use RedJasmine\FilamentProduct\Clusters\Product\Resources\BrandResource;

class CreateBrand extends CreateRecord
{

use ResourcePageHelper;

protected static string $resource = BrandResource::class;


}


Loading

0 comments on commit 657d2fa

Please sign in to comment.