|
|
@@ -1,160 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace App\Module\System\AdminControllers;
|
|
|
-
|
|
|
-use App\Module\System\AdminControllers\Helper\FilterHelper;
|
|
|
-use App\Module\System\AdminControllers\Helper\FormHelper;
|
|
|
-use App\Module\System\AdminControllers\Helper\GridHelper;
|
|
|
-use App\Module\System\AdminControllers\Helper\ShowHelper;
|
|
|
-use App\Module\System\Enums\VIEW_TYPE;
|
|
|
-use App\Module\System\Models\ViewConfig;
|
|
|
-use App\Module\System\Services\ViewConfigService;
|
|
|
-use Dcat\Admin\Form;
|
|
|
-use Dcat\Admin\Grid;
|
|
|
-use Dcat\Admin\Show;
|
|
|
-use Spatie\RouteAttributes\Attributes\Resource;
|
|
|
-use UCore\DcatAdmin\AdminController;
|
|
|
-
|
|
|
-/**
|
|
|
- * 视图配置管理控制器
|
|
|
- */
|
|
|
-#[Resource('system-view-configs', names: 'dcat.admin.system-view-configs')]
|
|
|
-class ViewConfigController extends AdminController
|
|
|
-{
|
|
|
- /**
|
|
|
- * 页面标题
|
|
|
- *
|
|
|
- * @var string
|
|
|
- */
|
|
|
- protected $title = '视图配置管理';
|
|
|
-
|
|
|
- /**
|
|
|
- * 视图配置服务
|
|
|
- *
|
|
|
- * @var ViewConfigService
|
|
|
- */
|
|
|
- protected $service;
|
|
|
-
|
|
|
- /**
|
|
|
- * 构造函数
|
|
|
- */
|
|
|
- public function __construct()
|
|
|
- {
|
|
|
- $this->service = new ViewConfigService();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 列表页面
|
|
|
- *
|
|
|
- * @return Grid
|
|
|
- */
|
|
|
- protected function grid()
|
|
|
- {
|
|
|
- return Grid::make(new ViewConfig(), function (Grid $grid) {
|
|
|
- $helper = new GridHelper($grid, $this);
|
|
|
-
|
|
|
- $helper->columnId();
|
|
|
- $helper->columnTitle();
|
|
|
- $helper->columnViewType();
|
|
|
- $helper->columnRouterName();
|
|
|
- $grid->column('p1', '参数')->display(function ($value) {
|
|
|
- return is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
|
|
|
- })->limit(30);
|
|
|
- $helper->columnAdminId();
|
|
|
- $helper->columnCreatedAt();
|
|
|
- $helper->columnUpdatedAt();
|
|
|
-
|
|
|
- // 添加刷新缓存按钮
|
|
|
- $grid->tools(function (Grid\Tools $tools) {
|
|
|
- $tools->append(new \Dcat\Admin\Grid\Tools\BatchAction('刷新缓存', function () {
|
|
|
- $this->service->refreshCache();
|
|
|
- return $this->response()->success('缓存刷新成功')->refresh();
|
|
|
- }));
|
|
|
- });
|
|
|
-
|
|
|
- // 筛选器
|
|
|
- $grid->filter(function (Grid\Filter $filter) {
|
|
|
- $helper = new FilterHelper($filter, $this);
|
|
|
- $helper->equalId();
|
|
|
- $helper->likeTitle();
|
|
|
- $helper->equalViewType();
|
|
|
- $helper->likeRouterName();
|
|
|
- $helper->equalAdminId();
|
|
|
- $helper->betweenCreatedAt();
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 详情页面
|
|
|
- *
|
|
|
- * @param mixed $id
|
|
|
- * @return Show
|
|
|
- */
|
|
|
- protected function detail($id)
|
|
|
- {
|
|
|
- return Show::make($id, new ViewConfig(), function (Show $show) {
|
|
|
- $helper = new ShowHelper($show, $this);
|
|
|
-
|
|
|
- $helper->fieldId();
|
|
|
- $helper->fieldTitle();
|
|
|
- $helper->fieldViewType();
|
|
|
- $helper->fieldRouterName();
|
|
|
- $helper->fieldParams();
|
|
|
- $helper->fieldAdminId();
|
|
|
- $helper->fieldCreatedAt();
|
|
|
- $helper->fieldUpdatedAt();
|
|
|
- $helper->fieldDeletedAt();
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 表单页面
|
|
|
- *
|
|
|
- * @return Form
|
|
|
- */
|
|
|
- protected function form()
|
|
|
- {
|
|
|
- return Form::make(new ViewConfig(), function (Form $form) {
|
|
|
- $helper = new FormHelper($form, $this);
|
|
|
-
|
|
|
- $form->display('id', 'ID');
|
|
|
- $helper->textTitle();
|
|
|
- $helper->selectViewType();
|
|
|
- $helper->textRouterName();
|
|
|
- $helper->textareaParams();
|
|
|
-
|
|
|
- $form->display('admin_id', '管理员ID');
|
|
|
- $form->display('created_at', '创建时间');
|
|
|
- $form->display('updated_at', '更新时间');
|
|
|
-
|
|
|
- // 保存前回调
|
|
|
- $form->saving(function (Form $form) {
|
|
|
- // 处理参数
|
|
|
- if ($form->p1) {
|
|
|
- try {
|
|
|
- $params = json_decode($form->p1, true);
|
|
|
- if (json_last_error() !== JSON_ERROR_NONE) {
|
|
|
- return $form->response()->error('参数不是有效的JSON格式');
|
|
|
- }
|
|
|
- $form->p1 = $params;
|
|
|
- } catch (\Exception $e) {
|
|
|
- return $form->response()->error('参数处理失败: ' . $e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 设置管理员ID
|
|
|
- if ($form->isCreating()) {
|
|
|
- $form->admin_id = auth('admin')->id() ?: 0;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 保存后回调
|
|
|
- $form->saved(function (Form $form) {
|
|
|
- // 刷新缓存
|
|
|
- $this->service->refreshCache();
|
|
|
- return $form->response()->success('保存成功,缓存已刷新');
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-}
|