diff --git a/app/Filament/Actions/ArchiveSopTemplateAction.php b/app/Filament/Actions/ArchiveSopTemplateAction.php new file mode 100644 index 0000000..87caeac --- /dev/null +++ b/app/Filament/Actions/ArchiveSopTemplateAction.php @@ -0,0 +1,50 @@ +label('归档模板'); + + $this->icon('heroicon-o-archive-box'); + + $this->color('warning'); + + $this->requiresConfirmation(); + + $this->modalHeading('归档 SOP 模板'); + + $this->modalDescription('归档后,模板将不再对用户显示。确定要归档吗?'); + + $this->modalSubmitActionLabel('确认归档'); + + $this->visible(function ($record) { + return $record instanceof SopTemplate && $record->status === 'published'; + }); + + $this->action(function (SopTemplate $record) { + $record->update([ + 'status' => 'archived', + ]); + + Notification::make() + ->title('归档成功') + ->body('SOP 模板已成功归档') + ->success() + ->send(); + }); + } +} diff --git a/app/Filament/Actions/PreviewSopTemplateAction.php b/app/Filament/Actions/PreviewSopTemplateAction.php new file mode 100644 index 0000000..34340ab --- /dev/null +++ b/app/Filament/Actions/PreviewSopTemplateAction.php @@ -0,0 +1,90 @@ +label('预览模板'); + + $this->icon('heroicon-o-eye'); + + $this->color('info'); + + $this->modalHeading('SOP 模板预览'); + + $this->modalWidth('7xl'); + + $this->modalSubmitAction(false); + + $this->modalCancelActionLabel('关闭'); + + $this->infolist(function (SopTemplate $record): Infolist { + return Infolist::make() + ->record($record) + ->schema([ + Infolists\Components\Section::make('模板信息') + ->schema([ + Infolists\Components\TextEntry::make('name') + ->label('模板名称') + ->size(Infolists\Components\TextEntry\TextEntrySize::Large) + ->weight('bold'), + + Infolists\Components\TextEntry::make('description') + ->label('模板描述') + ->columnSpanFull(), + + Infolists\Components\TextEntry::make('category') + ->label('分类') + ->badge(), + + Infolists\Components\TextEntry::make('version') + ->label('版本'), + ]) + ->columns(2), + + Infolists\Components\Section::make('操作步骤') + ->schema([ + Infolists\Components\RepeatableEntry::make('steps') + ->label('') + ->schema([ + Infolists\Components\TextEntry::make('step_number') + ->label('步骤') + ->badge() + ->color('primary'), + + Infolists\Components\TextEntry::make('title') + ->label('标题') + ->weight('bold'), + + Infolists\Components\TextEntry::make('content') + ->label('内容') + ->html() + ->columnSpanFull(), + + Infolists\Components\TextEntry::make('is_required') + ->label('必需') + ->badge() + ->formatStateUsing(fn (bool $state): string => $state ? '是' : '否') + ->color(fn (bool $state): string => $state ? 'success' : 'gray'), + ]) + ->columns(3) + ->contained(false), + ]), + ]); + }); + } +} diff --git a/app/Filament/Actions/PublishSopTemplateAction.php b/app/Filament/Actions/PublishSopTemplateAction.php new file mode 100644 index 0000000..18852b2 --- /dev/null +++ b/app/Filament/Actions/PublishSopTemplateAction.php @@ -0,0 +1,85 @@ +label('发布模板'); + + $this->icon('heroicon-o-check-circle'); + + $this->color('success'); + + $this->requiresConfirmation(); + + $this->modalHeading('发布 SOP 模板'); + + $this->modalDescription('发布后,模板将对所有用户可见。确定要发布吗?'); + + $this->modalSubmitActionLabel('确认发布'); + + $this->form([ + Forms\Components\Textarea::make('change_log') + ->label('变更说明') + ->placeholder('请描述本次发布的主要变更内容...') + ->rows(3), + ]); + + $this->visible(function ($record) { + return $record instanceof SopTemplate && $record->status === 'draft'; + }); + + $this->action(function (SopTemplate $record, array $data) { + // 验证模板是否有步骤 + if ($record->steps()->count() === 0) { + Notification::make() + ->title('发布失败') + ->body('模板至少需要包含一个步骤才能发布') + ->danger() + ->send(); + + return; + } + + // 创建版本快照 + SopTemplateVersion::create([ + 'sop_template_id' => $record->id, + 'version' => $record->version, + 'change_log' => $data['change_log'] ?? '首次发布', + 'content_snapshot' => [ + 'template' => $record->toArray(), + 'steps' => $record->steps->toArray(), + ], + 'created_by' => auth()->id(), + 'created_at' => now(), + ]); + + // 更新模板状态 + $record->update([ + 'status' => 'published', + 'published_at' => now(), + ]); + + Notification::make() + ->title('发布成功') + ->body('SOP 模板已成功发布') + ->success() + ->send(); + }); + } +}