EditPlanContentAction.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Module\Cleanup\AdminControllers\Actions;
  3. use App\Module\Cleanup\Models\CleanupPlanContent;
  4. use App\Module\Cleanup\Services\CleanupService;
  5. use Dcat\Admin\Actions\Response;
  6. use Dcat\Admin\Grid\RowAction;
  7. use Dcat\Admin\Widgets\Form;
  8. /**
  9. * 编辑计划内容Action
  10. */
  11. class EditPlanContentAction extends RowAction
  12. {
  13. /**
  14. * 标题
  15. */
  16. protected $title = '编辑内容';
  17. /**
  18. * 处理请求
  19. */
  20. public function handle()
  21. {
  22. $id = $this->getKey();
  23. $data = $this->form;
  24. try {
  25. $content = CleanupPlanContent::findOrFail($id);
  26. // 更新计划内容
  27. $content->update([
  28. 'cleanup_type' => $data['cleanup_type'],
  29. 'conditions' => $data['conditions'] ?? [],
  30. 'priority' => $data['priority'],
  31. 'batch_size' => $data['batch_size'],
  32. 'is_enabled' => $data['is_enabled'] ?? 0,
  33. 'backup_enabled' => $data['backup_enabled'] ?? 0,
  34. 'notes' => $data['notes'] ?? '',
  35. ]);
  36. return $this->response()
  37. ->success('编辑成功')
  38. ->refresh();
  39. } catch (\Exception $e) {
  40. return $this->response()
  41. ->error('编辑失败:' . $e->getMessage());
  42. }
  43. }
  44. /**
  45. * 表单配置
  46. */
  47. public function form()
  48. {
  49. $content = CleanupPlanContent::findOrFail($this->getKey());
  50. return Form::make()->action($this->getHandleRoute())->body([
  51. // 基础信息(只读)
  52. Form::display('plan_name', '所属计划')->value($content->plan->plan_name ?? ''),
  53. Form::display('table_name', '表名')->value($content->table_name),
  54. // 清理配置
  55. Form::select('cleanup_type', '清理类型')
  56. ->options([
  57. 1 => '清空表',
  58. 2 => '删除所有',
  59. 3 => '按时间删除',
  60. 4 => '按用户删除',
  61. 5 => '按条件删除',
  62. ])
  63. ->value($content->cleanup_type)
  64. ->required(),
  65. Form::keyValue('conditions', '清理条件')
  66. ->value($content->conditions ?? [])
  67. ->help('JSON格式的清理条件配置'),
  68. // 执行配置
  69. Form::number('priority', '优先级')
  70. ->value($content->priority)
  71. ->min(1)
  72. ->max(999)
  73. ->help('数字越小优先级越高'),
  74. Form::number('batch_size', '批处理大小')
  75. ->value($content->batch_size)
  76. ->min(100)
  77. ->max(10000)
  78. ->help('每批处理的记录数量'),
  79. // 状态配置
  80. Form::switch('is_enabled', '启用状态')->value($content->is_enabled),
  81. Form::switch('backup_enabled', '备份启用')->value($content->backup_enabled),
  82. // 备注
  83. Form::textarea('notes', '备注说明')
  84. ->value($content->notes)
  85. ->help('对此清理配置的说明'),
  86. ]);
  87. }
  88. /**
  89. * 权限检查
  90. */
  91. public function allowed()
  92. {
  93. return true; // 根据实际需求设置权限
  94. }
  95. }