| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Module\Cleanup\AdminControllers\Actions;
- use App\Module\Cleanup\Models\CleanupPlan;
- use Dcat\Admin\Actions\RowAction;
- use Dcat\Admin\Actions\Response;
- use Illuminate\Http\Request;
- /**
- * 查看计划内容Action
- *
- * 用于查看清理计划的详细内容
- */
- class ViewPlanContentsAction extends RowAction
- {
- /**
- * 按钮标题
- */
- protected $title = '查看内容';
- /**
- * 处理请求
- */
- public function handle(Request $request)
- {
- try {
- $planId = $this->getKey();
-
- $plan = CleanupPlan::with('contents')->find($planId);
-
- if (!$plan) {
- return $this->response()
- ->error('计划不存在');
- }
-
- $contents = $plan->contents;
-
- if ($contents->isEmpty()) {
- return $this->response()
- ->info('该计划暂无内容');
- }
-
- $html = '<div class="table-responsive"><table class="table table-striped table-sm">';
- $html .= '<thead><tr><th>表名</th><th>清理类型</th><th>优先级</th><th>批处理大小</th><th>启用状态</th><th>备份</th></tr></thead>';
- $html .= '<tbody>';
-
- $cleanupTypes = [
- 1 => '清空表',
- 2 => '删除所有',
- 3 => '按时间删除',
- 4 => '按用户删除',
- 5 => '按条件删除',
- ];
-
- foreach ($contents as $content) {
- $cleanupType = $cleanupTypes[$content->cleanup_type] ?? '未知';
- $enabled = $content->is_enabled ? '<span class="badge badge-success">启用</span>' : '<span class="badge badge-secondary">禁用</span>';
- $backup = $content->backup_enabled ? '<span class="badge badge-info">是</span>' : '<span class="badge badge-secondary">否</span>';
-
- $html .= "<tr>";
- $html .= "<td>{$content->table_name}</td>";
- $html .= "<td>{$cleanupType}</td>";
- $html .= "<td>{$content->priority}</td>";
- $html .= "<td>" . number_format($content->batch_size) . "</td>";
- $html .= "<td>{$enabled}</td>";
- $html .= "<td>{$backup}</td>";
- $html .= "</tr>";
- }
-
- $html .= '</tbody></table></div>';
-
- return $this->response()
- ->success('计划内容')
- ->detail($html);
-
- } catch (\Exception $e) {
- return $this->response()
- ->error('查看失败:' . $e->getMessage());
- }
- }
- /**
- * 渲染按钮
- */
- public function render()
- {
- return <<<HTML
- <a href="javascript:void(0);" class="btn btn-primary btn-xs" data-action="{$this->getHandleRoute()}">
- <i class="fa fa-list"></i> {$this->title}
- </a>
- HTML;
- }
- }
|