| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Module\Cleanup\AdminControllers\Actions;
- use App\Module\Cleanup\Services\CleanupService;
- use Dcat\Admin\Actions\RowAction;
- use Dcat\Admin\Actions\Response;
- use Illuminate\Http\Request;
- /**
- * 删除备份Action
- *
- * 用于删除备份记录和文件
- */
- class DeleteBackupAction extends RowAction
- {
- /**
- * 按钮标题
- */
- protected $title = '删除备份';
- /**
- * 处理请求
- */
- public function handle(Request $request)
- {
- try {
- $backupId = $this->getKey();
- $deleteFiles = $request->input('delete_files', true);
-
- // 调用服务删除备份
- $result = CleanupService::deleteBackup($backupId, $deleteFiles);
-
- if (!$result['success']) {
- return $this->response()
- ->error('删除失败:' . $result['message']);
- }
-
- $data = $result['data'];
-
- return $this->response()
- ->success('备份删除成功!')
- ->detail("
- 备份名称:{$data['backup_name']}<br>
- 删除文件数:{$data['deleted_files']}<br>
- 释放空间:{$data['freed_space']}
- ")
- ->refresh();
-
- } catch (\Exception $e) {
- return $this->response()
- ->error('删除失败:' . $e->getMessage());
- }
- }
- /**
- * 确认对话框
- */
- public function confirm()
- {
- return [
- '确认删除备份?',
- '⚠️ 删除后无法恢复,请谨慎操作!',
- [
- 'delete_files' => [
- 'type' => 'checkbox',
- 'label' => '同时删除备份文件',
- 'checked' => true,
- 'help' => '取消勾选则只删除记录,保留文件',
- ]
- ]
- ];
- }
- /**
- * 权限检查
- */
- public function allowed()
- {
- $row = $this->row;
- return $row->backup_status != 1; // 非进行中状态可以删除
- }
- /**
- * 渲染按钮
- */
- public function render()
- {
- return <<<HTML
- <a href="javascript:void(0);" class="btn btn-danger btn-xs" data-action="{$this->getHandleRoute()}">
- <i class="fa fa-trash"></i> {$this->title}
- </a>
- HTML;
- }
- }
|