| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Module\Cleanup\AdminControllers\Actions;
- use App\Module\Cleanup\Services\CleanupService;
- use Dcat\Admin\Grid\RowAction;
- use Dcat\Admin\Actions\Response;
- use Illuminate\Http\Request;
- /**
- * 启动任务Action
- *
- * 用于启动待执行的清理任务
- */
- class StartTaskAction extends RowAction
- {
- /**
- * 按钮标题
- */
- protected $title = '启动任务';
- /**
- * 处理请求
- */
- public function handle(Request $request)
- {
- try {
- $taskId = $this->getKey();
-
- // 调用服务启动任务
- $result = CleanupService::startTask($taskId);
-
- if (!$result['success']) {
- return $this->response()
- ->error('启动失败:' . $result['message']);
- }
-
- return $this->response()
- ->success('任务启动成功!')
- ->detail('任务已开始执行,请在任务列表中查看进度。')
- ->refresh();
-
- } catch (\Exception $e) {
- return $this->response()
- ->error('启动失败:' . $e->getMessage());
- }
- }
- /**
- * 确认对话框
- */
- public function confirm()
- {
- return [
- '确认启动任务?',
- '⚠️ 任务启动后将开始执行数据清理操作,请确保已做好备份!'
- ];
- }
- /**
- * 权限检查
- */
- public function allowed()
- {
- $row = $this->row;
- return $row->status == 1; // 只有待执行状态的任务可以启动
- }">
- <i class="fa fa-play"></i> {$this->title}
- </a>
- HTML;
- }
- }
|