From 6102ec95d25bd23781bc8e7516a89111523df0c0 Mon Sep 17 00:00:00 2001 From: lizhuoran <625237490@qq.com> Date: Mon, 9 Mar 2026 13:24:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=98=B6=E6=AE=B5=E5=9B=9B):=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=20SOP=20=E6=A8=A1=E6=9D=BF=E7=8A=B6=E6=80=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建发布 Action(PublishSopTemplateAction) - 创建归档 Action(ArchiveSopTemplateAction) - 创建预览 Action(PreviewSopTemplateAction) - 发布前验证模板是否有步骤 - 发布时自动创建版本快照 - 预览模式显示完整模板内容 --- .../Actions/ArchiveSopTemplateAction.php | 50 +++++++++++ .../Actions/PreviewSopTemplateAction.php | 90 +++++++++++++++++++ .../Actions/PublishSopTemplateAction.php | 85 ++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 app/Filament/Actions/ArchiveSopTemplateAction.php create mode 100644 app/Filament/Actions/PreviewSopTemplateAction.php create mode 100644 app/Filament/Actions/PublishSopTemplateAction.php 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(); + }); + } +}