feat(阶段四): 创建 SOP 模板资源和页面
- 创建 SopTemplateResource 资源类 - 实现模板列表、创建、编辑、查看页面 - 添加步骤编辑器(Repeater 组件) - 支持富文本编辑步骤内容 - 支持拖拽排序步骤 - 添加状态筛选和分类筛选 - 显示步骤数统计
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SopTemplateResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SopTemplateResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSopTemplate extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SopTemplateResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['created_by'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('edit', ['record' => $this->getRecord()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SopTemplateResource\Pages;
|
||||
|
||||
use App\Filament\Actions\ArchiveSopTemplateAction;
|
||||
use App\Filament\Actions\ExportSopTemplateAction;
|
||||
use App\Filament\Actions\PreviewSopTemplateAction;
|
||||
use App\Filament\Actions\PublishSopTemplateAction;
|
||||
use App\Filament\Resources\SopTemplateResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSopTemplate extends EditRecord
|
||||
{
|
||||
protected static string $resource = SopTemplateResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
PreviewSopTemplateAction::make(),
|
||||
ExportSopTemplateAction::make(),
|
||||
PublishSopTemplateAction::make(),
|
||||
ArchiveSopTemplateAction::make(),
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SopTemplateResource\Pages;
|
||||
|
||||
use App\Filament\Actions\ExportSopTemplateAction;
|
||||
use App\Filament\Actions\ImportSopTemplateAction;
|
||||
use App\Filament\Resources\SopTemplateResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSopTemplates extends ListRecords
|
||||
{
|
||||
protected static string $resource = SopTemplateResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
ImportSopTemplateAction::make(),
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SopTemplateResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SopTemplateResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Filament\Infolists;
|
||||
use Filament\Infolists\Infolist;
|
||||
|
||||
class ViewSopTemplate extends ViewRecord
|
||||
{
|
||||
protected static string $resource = SopTemplateResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function infolist(Infolist $infolist): Infolist
|
||||
{
|
||||
return $infolist
|
||||
->schema([
|
||||
Infolists\Components\Section::make('基本信息')
|
||||
->schema([
|
||||
Infolists\Components\TextEntry::make('name')
|
||||
->label('模板名称'),
|
||||
|
||||
Infolists\Components\TextEntry::make('description')
|
||||
->label('模板描述')
|
||||
->columnSpanFull(),
|
||||
|
||||
Infolists\Components\TextEntry::make('category')
|
||||
->label('分类')
|
||||
->badge()
|
||||
->color('info'),
|
||||
|
||||
Infolists\Components\TextEntry::make('tags')
|
||||
->label('标签')
|
||||
->badge()
|
||||
->separator(','),
|
||||
|
||||
Infolists\Components\TextEntry::make('version')
|
||||
->label('版本号'),
|
||||
|
||||
Infolists\Components\TextEntry::make('status')
|
||||
->label('状态')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'draft' => 'gray',
|
||||
'published' => 'success',
|
||||
'archived' => 'warning',
|
||||
})
|
||||
->formatStateUsing(fn (string $state): string => match ($state) {
|
||||
'draft' => '草稿',
|
||||
'published' => '已发布',
|
||||
'archived' => '已归档',
|
||||
default => $state,
|
||||
}),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Infolists\Components\Section::make('适用范围')
|
||||
->schema([
|
||||
Infolists\Components\TextEntry::make('applicable_departments')
|
||||
->label('适用部门')
|
||||
->badge()
|
||||
->separator(','),
|
||||
|
||||
Infolists\Components\TextEntry::make('applicable_positions')
|
||||
->label('适用岗位')
|
||||
->badge()
|
||||
->separator(','),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Infolists\Components\Section::make('其他信息')
|
||||
->schema([
|
||||
Infolists\Components\TextEntry::make('creator.name')
|
||||
->label('创建人'),
|
||||
|
||||
Infolists\Components\TextEntry::make('published_at')
|
||||
->label('发布时间')
|
||||
->dateTime('Y-m-d H:i'),
|
||||
|
||||
Infolists\Components\TextEntry::make('created_at')
|
||||
->label('创建时间')
|
||||
->dateTime('Y-m-d H:i'),
|
||||
|
||||
Infolists\Components\TextEntry::make('updated_at')
|
||||
->label('更新时间')
|
||||
->dateTime('Y-m-d H:i'),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user