diff --git a/app/Controller/Admin/System.php b/app/Controller/Admin/System.php index 3ac19a3..4a141e0 100644 --- a/app/Controller/Admin/System.php +++ b/app/Controller/Admin/System.php @@ -23,6 +23,8 @@ use App\Request\Role as rRequest; use App\Request\GenTable as gtRequest; use App\Model\AssetCategory as acModel; 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\Utils\AppInfoHelper; use App\Utils\CpuHelper; @@ -609,6 +611,7 @@ class System extends Base // 搜搜字段 $query_fields = []; $insert_fields = []; + $edit_fields = []; $list_fields = []; $required_fields = []; $fields = $table['gen_table_columns']; @@ -634,8 +637,8 @@ class System extends Base 'request.php' => $this->render->getContents('templates/request.php.twig', compact("controller_name", "insert_fields", "fields", "required_fields", "edit_fields")), 'controller.php' => $this->render->getContents('templates/controller.php.twig', compact("controller_name", "module_name", "query_fields", "insert_fields", "edit_fields", "table_name", "name1", "name2")), 'api.ts' => $this->render->getContents('templates/api.ts.twig', compact('table_name')), - 'index.vue' => $this->render->getContents('templates/index.vue.twig', compact('table_name', 'list_fields', 'query_fields')), - 'save.vue' => $this->render->getContents('templates/save.vue.twig', compact('table_name', 'insert_fields', 'required_fields')) + 'index.vue' => $this->render->getContents('templates/index.vue.twig', compact('table_name', 'list_fields', 'query_fields', 'name2')), + 'save.vue' => $this->render->getContents('templates/save.vue.twig', compact('table_name', 'insert_fields', 'required_fields', 'edit_fields')) ]; return $this->success("模板信息", $data); } @@ -760,4 +763,55 @@ class System extends Base } return $this->error("上传失败"); } + + #[GetMapping(path: "system_config/list")] + #[Auth(auth: "system_config:list")] + public function systemConfigList() + { + $param = Param::only(["config_name", "config_key", "limit" => 10]); + return $this->success("列表接口", scModel::list($param)); + } + + #[GetMapping(path: "system_config/option")] + #[Auth(needAuth: false)] + public function systemConfigOption() + { + return $this->success(scModel::options()); + } + + #[GetMapping(path: "system_config/info")] + #[Auth(auth: "system_config:info")] + public function systemConfigInfo() + { + $id = $this->request->input("id"); + return $this->success(scModel::getById($id)); + } + + #[PostMapping(path: "system_config/add")] + #[Auth(auth: "system_config:add")] + public function systemConfigAdd() + { + $request = $this->container->get(scRequest::class); + $request->scene('add')->validateResolved(); + $data = Param::only(["config_name", "config_key", "config_value", "remark"]); + return $this->toAjax(scModel::add($data)); + } + + #[PutMapping(path: "system_config/edit")] + #[Auth(auth: "system_config:edit")] + public function systemConfigEdit() + { + $request = $this->container->get(scRequest::class); + $request->scene('edit')->validateResolved(); + $data = Param::only(["config_id", "config_name", "config_key", "config_value", "remark"]); + return $this->toAjax(scModel::edit($data)); + } + + #[DeleteMapping(path: "system_config/del")] + #[Auth(auth: "system_config:del")] + public function systemConfigDel() + { + $ids = $this->request->input("ids"); + return $this->toAjax(scModel::del($ids)); + } } \ No newline at end of file diff --git a/app/Model/GenTable.php b/app/Model/GenTable.php index 626c155..ab60e79 100644 --- a/app/Model/GenTable.php +++ b/app/Model/GenTable.php @@ -176,7 +176,7 @@ class GenTable extends Model 'php_type' => Str::typeMysqlToPhp($column->Type), 'php_field' => $column->Field, 'is_insert' => Str::isInsert($column->Field, $column->Extra), - 'is_edit' => Str::isEdit($column->Field, $column->Extra), + 'is_edit' => Str::isEdit($column->Field), 'is_list' => Str::isList($column->Field, $column->Extra), 'is_query' => Str::isQuery($column->Field, $column->Extra), 'is_required' => 0, diff --git a/app/Model/SystemConfig.php b/app/Model/SystemConfig.php new file mode 100644 index 0000000..f0bad16 --- /dev/null +++ b/app/Model/SystemConfig.php @@ -0,0 +1,54 @@ + 'integer']; + + public static function list(array $param) + { + $model = self::query(); + if (isset($param['config_name']) && $param['config_name'] != '') { + $model = $model->where('config_name', "like", "%{$param['config_name']}%"); + } + if (isset($param['config_key']) && $param['config_key'] != '') { + $model = $model->where('config_key', "like", "%{$param['config_key']}%"); + } + return $model->orderByDesc("config_id") + ->select(["config_id", "config_name", "config_key", "config_value", "remark", "create_time", "update_time"]) + ->paginate((int)$param['limit']); + } + + public static function options() + { + return self::select(["config_id", "config_name"])->get()->toArray(); + } +} diff --git a/app/Request/SystemConfig.php b/app/Request/SystemConfig.php new file mode 100644 index 0000000..85a99e0 --- /dev/null +++ b/app/Request/SystemConfig.php @@ -0,0 +1,45 @@ + ["config_name", "config_key"], + 'edit' => ["config_id", "config_name", "config_key"], + ]; + + /** + * 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 [ + 'config_id' => 'required', + 'config_name' => 'required', + 'config_key' => 'required', + 'config_value' => 'required', + 'remark' => 'required', + ]; + } + + public function messages(): array + { + return [ + 'config_name.required' => '参数名称必传!', + 'config_key.required' => '参数键名必传!', + 'config_value.required' => '参数键值必传!', + 'remark.required' => '备注必传!', + ]; + } +} diff --git a/app/Utils/Str.php b/app/Utils/Str.php index 706ddf0..1edbf6d 100644 --- a/app/Utils/Str.php +++ b/app/Utils/Str.php @@ -87,11 +87,8 @@ class Str return !in_array($field, ["deleted_at", "update_time"]) ? 1 : 0; } - public static function isEdit($field, $extra): int + public static function isEdit($field): int { - if ($extra == "auto_increment") { - return 0; - } return !in_array($field, ["deleted_at", "create_time"]) ? 1 : 0; } diff --git a/static/view/templates/controller.php.twig b/static/view/templates/controller.php.twig index 4ad1006..c943f5a 100644 --- a/static/view/templates/controller.php.twig +++ b/static/view/templates/controller.php.twig @@ -23,7 +23,7 @@ class {{ controller_name }} extends Base public function {{ name2 }}List() { $param = Param::only([{% for field in query_fields %}"{{ field.column_name }}"{% if not loop.last %}, {% endif %}{% endfor %}, "limit"=>10]); - return $this->success({{ name1 }}Model::list($param)); + return $this->success("列表接口", {{ name1 }}Model::list($param)); } #[GetMapping(path: "{{ table_name }}/option")] @@ -38,7 +38,7 @@ class {{ controller_name }} extends Base public function {{ name2 }}Info() { $id = $this->request->input("id"); - return $this->success({{ name1 }}Model::getById()); + return $this->success({{ name1 }}Model::getById($id)); } #[PostMapping(path: "{{ table_name }}/add")] diff --git a/static/view/templates/index.vue.twig b/static/view/templates/index.vue.twig index c1ce8cc..e3e3381 100644 --- a/static/view/templates/index.vue.twig +++ b/static/view/templates/index.vue.twig @@ -74,12 +74,12 @@