89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\GuideResource\Pages;
|
|
|
|
use App\Filament\Resources\GuideResource;
|
|
use App\Models\Guide;
|
|
use App\Models\GuidePage;
|
|
use Filament\Forms;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use SolutionForest\FilamentTree\Actions;
|
|
use SolutionForest\FilamentTree\Resources\Pages\TreePage;
|
|
|
|
class ManageGuidePages extends TreePage
|
|
{
|
|
protected static string $resource = GuideResource::class;
|
|
|
|
protected ?string $treeTitle = '指引页面';
|
|
protected bool $enableTreeTitle = true;
|
|
|
|
protected static string $model = GuidePage::class;
|
|
|
|
protected function getTreeQuery(): Builder
|
|
{
|
|
return GuidePage::query()
|
|
->where('guide_id', $this->getOwnerRecord()->id);
|
|
}
|
|
|
|
public function getTreeRecordTitle(?Model $record = null): string
|
|
{
|
|
if (!$record) {
|
|
return '';
|
|
}
|
|
$prefix = $record->branch_option ? "[{$record->branch_option}] " : '';
|
|
$suffix = !empty($record->options) ? ' 📋' : '';
|
|
return $prefix . $record->title . $suffix;
|
|
}
|
|
|
|
protected function getFormSchema(): array
|
|
{
|
|
return [
|
|
Forms\Components\TextInput::make('page_number')
|
|
->label('页码')
|
|
->numeric()
|
|
->minValue(1),
|
|
|
|
Forms\Components\TextInput::make('title')
|
|
->label('页面标题')
|
|
->required()
|
|
->maxLength(255),
|
|
|
|
Forms\Components\TextInput::make('html_url')
|
|
->label('HTML页面URL')
|
|
->required()
|
|
->url()
|
|
->maxLength(500),
|
|
|
|
Forms\Components\TagsInput::make('options')
|
|
->label('选项按钮')
|
|
->helperText('此页面展示的选项按钮,如"前门12"、"后门"。留空=无分支。'),
|
|
|
|
Forms\Components\TextInput::make('branch_option')
|
|
->label('所属分支选项')
|
|
->maxLength(100)
|
|
->helperText('此页面对应父页面的哪个选项值(根页面留空)'),
|
|
];
|
|
}
|
|
|
|
protected function getTreeActions(): array
|
|
{
|
|
return [
|
|
Actions\ViewAction::make(),
|
|
Actions\EditAction::make()->slideOver(),
|
|
Actions\DeleteAction::make(),
|
|
];
|
|
}
|
|
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
$data['guide_id'] = $this->getOwnerRecord()->id;
|
|
return $data;
|
|
}
|
|
|
|
protected function getOwnerRecord(): Guide
|
|
{
|
|
return Guide::findOrFail(request()->route('record'));
|
|
}
|
|
}
|