column('id', 'ID')->sortable(); $grid->column('plan_name', '计划名称')->sortable(); // 计划类型 $grid->column('plan_type', '计划类型')->using([ 1 => '全量清理', 2 => '模块清理', 3 => '分类清理', 4 => '自定义清理', 5 => '混合清理', ])->label([ 1 => 'danger', 2 => 'primary', 3 => 'info', 4 => 'warning', 5 => 'secondary', ])->sortable(); // 状态 $grid->column('is_template', '模板')->switch()->sortable(); $grid->column('is_enabled', '启用状态')->switch()->sortable(); // 统计信息 $grid->column('contents_count', '包含表数')->display(function () { return $this->contents()->count(); }); $grid->column('tasks_count', '关联任务数')->display(function () { return $this->tasks()->count(); }); // 时间 $grid->column('created_at', '创建时间')->sortable(); $grid->column('updated_at', '更新时间')->sortable(); // 筛选器 $grid->filter(function (Grid\Filter $filter) { $filter->equal('plan_type', '计划类型')->select([ 1 => '全量清理', 2 => '模块清理', 3 => '分类清理', 4 => '自定义清理', 5 => '混合清理', ]); $filter->equal('is_template', '模板')->select([ 1 => '是', 0 => '否', ]); $filter->equal('is_enabled', '启用状态')->select([ 1 => '启用', 0 => '禁用', ]); $filter->like('plan_name', '计划名称'); $filter->between('created_at', '创建时间')->datetime(); }); // 行操作 $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->append(new \App\Module\Cleanup\AdminControllers\Actions\ViewPlanContentsAction()); $actions->append(new \App\Module\Cleanup\AdminControllers\Actions\AddTableToPlanAction()); $actions->append(new \App\Module\Cleanup\AdminControllers\Actions\CreateTaskFromPlanAction()); $actions->append(new \App\Module\Cleanup\AdminControllers\Actions\PreviewPlanAction()); }); // 批量操作 $grid->batchActions([ new \App\Module\Cleanup\AdminControllers\Actions\BatchEnablePlanAction(), new \App\Module\Cleanup\AdminControllers\Actions\BatchDisablePlanAction(), ]); // 工具栏 $grid->tools([ new \App\Module\Cleanup\AdminControllers\Actions\CreatePlanFromTemplateAction(), ]); // 设置每页显示数量 $grid->paginate(20); }); } /** * 详情页面 */ protected function detail($id): Show { return Show::make($id, new CleanupPlanRepository(), function (Show $show) { $show->field('id', 'ID'); $show->field('plan_name', '计划名称'); $show->field('plan_type', '计划类型')->using([ 1 => '全量清理', 2 => '模块清理', 3 => '分类清理', 4 => '自定义清理', 5 => '混合清理', ]); $show->field('target_selection', '目标选择配置')->json(); $show->field('global_conditions', '全局清理条件')->json(); $show->field('backup_config', '备份配置')->json(); $show->field('is_template', '模板')->using([1 => '是', 0 => '否']); $show->field('is_enabled', '启用状态')->using([1 => '启用', 0 => '禁用']); $show->field('description', '计划描述'); $show->field('created_by', '创建者ID'); $show->field('created_at', '创建时间'); $show->field('updated_at', '更新时间'); // 显示计划内容 $show->relation('contents', '计划内容', function ($model) { $grid = new Grid(new \App\Module\Cleanup\Models\CleanupPlanContent()); $grid->model()->where('plan_id', $model->id); $grid->column('table_name', '表名'); $grid->column('cleanup_type', '清理类型')->using([ 1 => '清空表', 2 => '删除所有', 3 => '按时间删除', 4 => '按用户删除', 5 => '按条件删除', ]); $grid->column('priority', '优先级'); $grid->column('batch_size', '批处理大小'); $grid->column('is_enabled', '启用')->using([1 => '是', 0 => '否']); $grid->column('backup_enabled', '备份')->using([1 => '是', 0 => '否']); $grid->disableActions(); $grid->disableCreateButton(); $grid->disableFilter(); $grid->disablePagination(); return $grid; }); // 显示关联任务 $show->relation('tasks', '关联任务', function ($model) { $grid = new Grid(new \App\Module\Cleanup\Models\CleanupTask()); $grid->model()->where('plan_id', $model->id); $grid->column('id', 'ID'); $grid->column('task_name', '任务名称'); $grid->column('status', '状态')->using([ 1 => '待执行', 2 => '备份中', 3 => '执行中', 4 => '已完成', 5 => '已失败', 6 => '已取消', 7 => '已暂停', ]); $grid->column('progress', '进度')->display(function ($progress) { return $progress . '%'; }); $grid->column('created_at', '创建时间'); $grid->disableActions(); $grid->disableCreateButton(); $grid->disableFilter(); $grid->disablePagination(); return $grid; }); }); } /** * 创建/编辑表单 */ protected function form(): Form { return Form::make(new CleanupPlanRepository(), function (Form $form) { $form->display('id', 'ID'); $form->text('plan_name', '计划名称')->required(); $form->select('plan_type', '计划类型') ->options([ 1 => '全量清理', 2 => '模块清理', 3 => '分类清理', 4 => '自定义清理', 5 => '混合清理', ]) ->required(); $form->keyValue('target_selection', '目标选择配置') ->help('JSON格式的目标选择配置'); $form->keyValue('global_conditions', '全局清理条件') ->help('JSON格式的全局清理条件'); $form->keyValue('backup_config', '备份配置') ->help('JSON格式的备份配置'); $form->switch('is_template', '设为模板')->default(0); $form->switch('is_enabled', '启用状态')->default(1); $form->textarea('description', '计划描述'); $form->hidden('created_by')->value(admin_user_id()); $form->display('created_at', '创建时间'); $form->display('updated_at', '更新时间'); }); } }