Files

111 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2026-02-07 22:55:07 +08:00
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\AdSlotResource\Pages;
use App\Models\AdSlot;
use Filament\Forms;
use Filament\Forms\Components\Section;
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 AdSlotResource extends Resource
{
protected static ?string $model = AdSlot::class;
protected static ?string $navigationIcon = 'heroicon-o-megaphone';
protected static ?string $navigationLabel = '推广位';
protected static ?string $navigationGroup = '运营管理';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('基础信息')
->schema([
TextInput::make('name')
->label('名称')
->required()
->maxLength(255),
TextInput::make('key')
->label('标识键')
->helperText('前端模板使用 slotKey 识别')
->required()
->maxLength(64)
->unique(ignoreRecord: true),
Textarea::make('description')
->label('描述')
->rows(2)
->nullable(),
])->columns(2),
Section::make('配置')
->schema([
Toggle::make('is_active')
->label('启用')
->default(true),
TextInput::make('max_items')
->label('最大展示数')
->numeric()
->default(3),
TextInput::make('sort')
->label('排序')
->numeric()
->default(0),
])->columns(3),
]);
}
public static function table(Table $table): Table
{
return $table
->reorderable('sort')
->defaultSort('sort')
->columns([
TextColumn::make('name')->label('名称')->searchable()->sortable(),
TextColumn::make('key')->label('标识键')->searchable(),
IconColumn::make('is_active')->label('启用')->boolean(),
TextColumn::make('max_items')->label('最大展示')->sortable(),
TextColumn::make('ads_count')->label('广告数量')->counts('ads'),
TextColumn::make('sort')->label('排序')->sortable(),
TextColumn::make('created_at')->label('创建时间')->dateTime(),
])
->filters([
//
])
->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\ListAdSlots::route('/'),
'create' => Pages\CreateAdSlot::route('/create'),
'edit' => Pages\EditAdSlot::route('/{record}/edit'),
];
}
}