init
This commit is contained in:
233
web10/app/Filament/Resources/ProductResource.php
Normal file
233
web10/app/Filament/Resources/ProductResource.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\ProductResource\Pages;
|
||||
use App\Filament\Resources\ProductResource\RelationManagers;
|
||||
use App\Models\Product;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\MarkdownEditor;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ProductResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Product::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationLabel = '产品';
|
||||
protected static ?string $navigationGroup = '内容管理';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('基础信息')
|
||||
->schema([
|
||||
Select::make('category_id')
|
||||
->label('分类')
|
||||
->relationship('category', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
TextInput::make('name')
|
||||
->label('名称')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Textarea::make('summary')
|
||||
->label('简介')
|
||||
->required()
|
||||
->rows(2),
|
||||
MarkdownEditor::make('description')
|
||||
->label('详情')
|
||||
->columnSpanFull()
|
||||
->nullable(),
|
||||
])->columns(2),
|
||||
Section::make('媒体')
|
||||
->schema([
|
||||
FileUpload::make('cover')
|
||||
->label('封面')
|
||||
->disk('public')
|
||||
->directory('products/cover')
|
||||
->image()
|
||||
->imagePreviewHeight('120')
|
||||
->nullable(),
|
||||
FileUpload::make('screenshots')
|
||||
->label('截图')
|
||||
->disk('public')
|
||||
->directory('products/screenshots')
|
||||
->image()
|
||||
->multiple()
|
||||
->maxFiles(5)
|
||||
->nullable(),
|
||||
TextInput::make('video_url')
|
||||
->label('视频链接')
|
||||
->maxLength(255)
|
||||
->nullable(),
|
||||
])->columns(2),
|
||||
Section::make('业务信息')
|
||||
->schema([
|
||||
TextInput::make('website_url')
|
||||
->label('官网链接')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Select::make('pricing_type')
|
||||
->label('收费类型')
|
||||
->options([
|
||||
'free' => '免费',
|
||||
'paid' => '付费',
|
||||
'subscription' => '订阅',
|
||||
'trial' => '试用',
|
||||
])
|
||||
->nullable(),
|
||||
Select::make('platforms')
|
||||
->label('平台')
|
||||
->multiple()
|
||||
->options([
|
||||
'web' => 'Web',
|
||||
'ios' => 'iOS',
|
||||
'android' => 'Android',
|
||||
'chrome' => 'Chrome',
|
||||
'windows' => 'Windows',
|
||||
'mac' => 'Mac',
|
||||
])
|
||||
->nullable(),
|
||||
Select::make('tags')
|
||||
->label('标签')
|
||||
->multiple()
|
||||
->relationship('tags', 'name')
|
||||
->preload(),
|
||||
])->columns(2),
|
||||
Section::make('推荐与排序')
|
||||
->schema([
|
||||
Toggle::make('is_featured')
|
||||
->label('热门推荐'),
|
||||
DateTimePicker::make('featured_until')
|
||||
->label('推荐到期')
|
||||
->nullable(),
|
||||
Toggle::make('is_sponsored')
|
||||
->label('推广位'),
|
||||
DateTimePicker::make('sponsor_until')
|
||||
->label('推广到期')
|
||||
->nullable(),
|
||||
TextInput::make('sort')
|
||||
->label('排序')
|
||||
->numeric()
|
||||
->default(0),
|
||||
TextInput::make('hot_score')
|
||||
->label('热度')
|
||||
->numeric()
|
||||
->disabled()
|
||||
->dehydrated(false),
|
||||
TextInput::make('hot_override')
|
||||
->label('热度覆盖')
|
||||
->numeric()
|
||||
->nullable(),
|
||||
])->columns(3),
|
||||
Section::make('统计与状态')
|
||||
->schema([
|
||||
TextInput::make('view_count')
|
||||
->label('浏览量')
|
||||
->numeric()
|
||||
->disabled()
|
||||
->dehydrated(false),
|
||||
TextInput::make('click_count')
|
||||
->label('点击量')
|
||||
->numeric()
|
||||
->disabled()
|
||||
->dehydrated(false),
|
||||
Select::make('status')
|
||||
->label('状态')
|
||||
->options([
|
||||
'draft' => '草稿',
|
||||
'published' => '发布',
|
||||
])
|
||||
->required(),
|
||||
])->columns(3),
|
||||
Section::make('SEO')
|
||||
->schema([
|
||||
TextInput::make('seo_title')
|
||||
->label('SEO 标题')
|
||||
->maxLength(255)
|
||||
->nullable(),
|
||||
TextInput::make('seo_description')
|
||||
->label('SEO 描述')
|
||||
->maxLength(255)
|
||||
->nullable(),
|
||||
])->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->reorderable('sort')
|
||||
->defaultSort('sort')
|
||||
->columns([
|
||||
TextColumn::make('name')->label('名称')->searchable()->sortable(),
|
||||
TextColumn::make('category.name')->label('分类')->sortable(),
|
||||
TextColumn::make('status')->label('状态')->sortable(),
|
||||
IconColumn::make('is_featured')->label('推荐')->boolean(),
|
||||
IconColumn::make('is_sponsored')->label('推广')->boolean(),
|
||||
TextColumn::make('sort')->label('排序')->sortable(),
|
||||
TextColumn::make('hot_score')->label('热度')->sortable(),
|
||||
TextColumn::make('view_count')->label('浏览')->sortable(),
|
||||
TextColumn::make('click_count')->label('点击')->sortable(),
|
||||
TextColumn::make('created_at')->label('创建时间')->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('status')
|
||||
->label('状态')
|
||||
->options([
|
||||
'draft' => '草稿',
|
||||
'published' => '发布',
|
||||
]),
|
||||
Tables\Filters\TernaryFilter::make('is_featured')
|
||||
->label('推荐'),
|
||||
Tables\Filters\TernaryFilter::make('is_sponsored')
|
||||
->label('推广'),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListProducts::route('/'),
|
||||
'create' => Pages\CreateProduct::route('/create'),
|
||||
'edit' => Pages\EditProduct::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user