diff --git a/app/Controller/Admin/System.php b/app/Controller/Admin/System.php index 4a141e0..2d6df1a 100644 --- a/app/Controller/Admin/System.php +++ b/app/Controller/Admin/System.php @@ -26,6 +26,10 @@ use App\Request\AssetCategory as acRequest; use App\Model\SystemConfig as scModel; use App\Request\SystemConfig as scRequest; use App\Model\Asset as asModel; +use App\Model\Dict as dtModel; +use App\Request\Dict as dtRequest; +use App\Model\DictData as ddModel; +use App\Request\DictData as ddRequest; use App\Utils\AppInfoHelper; use App\Utils\CpuHelper; use App\Utils\DiskInfoHelper; @@ -814,4 +818,106 @@ class System extends Base $ids = $this->request->input("ids"); return $this->toAjax(scModel::del($ids)); } + + #[GetMapping(path: "dict/list")] + #[Auth(auth: "dict:list")] + public function dictList() + { + $param = Param::only(["dict_name", "dict_type", "limit"=>10]); + return $this->success("列表接口", dtModel::list($param)); + } + + #[GetMapping(path: "dict/option")] + #[Auth(needAuth: false)] + public function dictOption() + { + return $this->success(dtModel::options()); + } + + #[GetMapping(path: "dict/info")] + #[Auth(auth: "dict:info")] + public function dictInfo() + { + $id = $this->request->input("id"); + return $this->success(dtModel::getById($id)); + } + + #[PostMapping(path: "dict/add")] + #[Auth(auth: "dict:add")] + public function dictAdd() + { + $request = $this->container->get(dtRequest::class); + $request->scene('add')->validateResolved(); + $data = Param::only(["dict_name", "dict_type", "remark"]); + return $this->toAjax(dtModel::add($data)); + } + + #[PutMapping(path: "dict/edit")] + #[Auth(auth: "dict:edit")] + public function dictEdit() + { + $request = $this->container->get(dtRequest::class); + $request->scene('edit')->validateResolved(); + $data = Param::only(["dict_id", "dict_name", "dict_type", "remark"]); + return $this->toAjax(dtModel::edit($data)); + } + + #[DeleteMapping(path: "dict/del")] + #[Auth(auth: "dict:del")] + public function dictDel() + { + $ids = $this->request->input("ids"); + return $this->toAjax(dtModel::del($ids)); + } + + #[GetMapping(path: "dict_data/list")] + #[Auth(auth: "dict_data:list")] + public function dictDataList() + { + $param = Param::only(["dict_id", "dict_label", "status", "limit"=>10]); + return $this->success("列表接口", ddModel::list($param)); + } + + #[GetMapping(path: "dict_data/option")] + #[Auth(needAuth: false)] + public function dictDataOption() + { + return $this->success(ddModel::options()); + } + + #[GetMapping(path: "dict_data/info")] + #[Auth(auth: "dict_data:info")] + public function dictDataInfo() + { + $id = $this->request->input("id"); + return $this->success(ddModel::getById($id)); + } + + #[PostMapping(path: "dict_data/add")] + #[Auth(auth: "dict_data:add")] + public function dictDataAdd() + { + $request = $this->container->get(ddRequest::class); + $request->scene('add')->validateResolved(); + $data = Param::only(["dict_id", "dict_label", "dict_value", "is_default", "rank", "status", "remark"]); + return $this->toAjax(ddModel::add($data)); + } + + #[PutMapping(path: "dict_data/edit")] + #[Auth(auth: "dict_data:edit")] + public function dictDataEdit() + { + $request = $this->container->get(ddRequest::class); + $request->scene('edit')->validateResolved(); + $data = Param::only(["data_id", "dict_id", "dict_label", "dict_value", "is_default", "rank", "status", "remark"]); + return $this->toAjax(ddModel::edit($data)); + } + + #[DeleteMapping(path: "dict_data/del")] + #[Auth(auth: "dict_data:del")] + public function dictDataDel() + { + $ids = $this->request->input("ids"); + return $this->toAjax(ddModel::del($ids)); + } } \ No newline at end of file diff --git a/app/Model/Dict.php b/app/Model/Dict.php new file mode 100644 index 0000000..5be2998 --- /dev/null +++ b/app/Model/Dict.php @@ -0,0 +1,53 @@ + 'integer']; + + public static function list(array $param) + { + $model = self::query(); + if (isset($param['dict_name']) && $param['dict_name'] != '') { + $model = $model->where('dict_name', "like", "%{$param['dict_name']}%"); + } + if (isset($param['dict_type']) && $param['dict_type'] != '') { + $model = $model->where('dict_type', "like", "%{$param['dict_type']}%"); + } + return $model->orderByDesc("dict_id") + ->select(["dict_id", "dict_name", "dict_type", "remark", "create_time", "update_time"]) + ->paginate((int)$param['limit']); + } + + public static function options() + { + return self::select(["dict_id", "dict_name"])->get()->toArray(); + } +} diff --git a/app/Model/DictData.php b/app/Model/DictData.php new file mode 100644 index 0000000..5249abb --- /dev/null +++ b/app/Model/DictData.php @@ -0,0 +1,60 @@ + 'integer', 'dict_id' => 'integer', 'is_default' => 'integer', 'rank' => 'integer', 'status' => 'integer']; + + public static function list(array $param) + { + $model = self::query(); + if (isset($param['dict_id']) && $param['dict_id'] != '') { + $model = $model->where('dict_id', $param['dict_id']); + } + if (isset($param['dict_label']) && $param['dict_label'] != '') { + $model = $model->where('dict_label', 'like', "%{$param['dict_label']}%"); + } + if (isset($param['status']) && $param['status'] != '') { + $model = $model->where('status', $param['status']); + } + return $model->orderByDesc("rank") + ->orderByDesc("dict_id") + ->select(["data_id", "dict_id", "dict_label", "dict_value", "is_default", "rank", "status", "remark", "create_time", "update_time"]) + ->paginate((int)$param['limit']); + } + + public static function options() + { + return self::select(["data_id", "data_name"])->get()->toArray(); + } +} diff --git a/app/Request/Dict.php b/app/Request/Dict.php new file mode 100644 index 0000000..887e8e1 --- /dev/null +++ b/app/Request/Dict.php @@ -0,0 +1,44 @@ + ["dict_name", "dict_type"], + 'edit' => ["dict_id", "dict_name", "dict_type"], + ]; + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize(): bool + { + return true; + } + + /** + * Get the validation rules that apply to the request. + */ + public function rules(): array + { + return [ + 'dict_id' => 'required', + 'dict_name' => 'required', + 'dict_type' => 'required', + 'remark' => 'required', + ]; + } + + public function messages(): array + { + return [ + 'dict_id.required' => 'ID必传!', + 'dict_name.required' => '字典名称必传!', + 'dict_type.required' => '字典类型必传!', + 'remark.required' => '备注必传!', + ]; + } +} diff --git a/app/Request/DictData.php b/app/Request/DictData.php new file mode 100644 index 0000000..274fd7c --- /dev/null +++ b/app/Request/DictData.php @@ -0,0 +1,51 @@ + ["dict_id", "dict_label", "dict_value", "is_default"], + 'edit' => ["data_id", "dict_id", "dict_label", "dict_value", "is_default"], + ]; + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize(): bool + { + return true; + } + + /** + * Get the validation rules that apply to the request. + */ + public function rules(): array + { + return [ + 'data_id' => 'required', + 'dict_id' => 'required', + 'dict_label' => 'required', + 'dict_value' => 'required', + 'is_default' => 'required', + 'rank' => 'required', + 'status' => 'required' + ]; + } + + public function messages(): array + { + return [ + 'data_id.required' => 'ID必传!', + 'dict_id.required' => '字典ID必传!', + 'dict_label.required' => '字典标签必传!', + 'dict_value.required' => '字典键值必传!', + 'is_default.required' => '是否默认必传!', + 'rank.required' => '排序必传!', + 'status.required' => '是否启用必传!', + 'remark.required' => '备注必传!', + ]; + } +} diff --git a/static/view/templates/index.vue.twig b/static/view/templates/index.vue.twig index e3e3381..ea3de9f 100644 --- a/static/view/templates/index.vue.twig +++ b/static/view/templates/index.vue.twig @@ -121,15 +121,18 @@ } //编辑 - async function edit(row) { + function edit(row) { dialogShow.value = true nextTick(() => { + if (row instanceof PointerEvent) { + row = selection.value[0] + } dialogRef.value.open('edit', row) }) } //查看 - async function show(row) { + function show(row) { dialogShow.value = true nextTick(() => { dialogRef.value.open('show', row) diff --git a/static/view/templates/save.vue.twig b/static/view/templates/save.vue.twig index fb90701..5fc03f6 100644 --- a/static/view/templates/save.vue.twig +++ b/static/view/templates/save.vue.twig @@ -96,5 +96,5 @@ emit('success') visible.value = false; proxy.$message.success(res.msg) - }} + }