- 创建发布 Action(PublishSopTemplateAction) - 创建归档 Action(ArchiveSopTemplateAction) - 创建预览 Action(PreviewSopTemplateAction) - 发布前验证模板是否有步骤 - 发布时自动创建版本快照 - 预览模式显示完整模板内容
51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Actions;
|
|
|
|
use App\Models\SopTemplate;
|
|
use Filament\Actions\Action;
|
|
use Filament\Notifications\Notification;
|
|
|
|
class ArchiveSopTemplateAction extends Action
|
|
{
|
|
public static function getDefaultName(): ?string
|
|
{
|
|
return 'archive';
|
|
}
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->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();
|
|
});
|
|
}
|
|
}
|