From 2a6d65d4e7fdf2e4140c6dff6e6d6f88eb9f7e4a Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Mon, 15 May 2023 13:23:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=B3=BB=E7=BB=9F=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/DictionaryController.php | 72 +++++++ .../DictionaryValuesController.php | 66 ++++++ modules/System/Models/Dictionary.php | 56 +++++ modules/System/Models/DictionaryValues.php | 46 +++++ .../Providers/SystemServiceProvider.php | 20 ++ ..._05_08_043214_create_system_dictionary.php | 41 ++++ ...043740_create_system_dictionary_values.php | 43 ++++ .../database/seeder/SystemMenusSeeder.php | 193 ++++++++++++++++++ modules/System/routes/route.php | 17 ++ modules/System/views/dictionary/create.vue | 56 +++++ modules/System/views/dictionary/index.vue | 73 +++++++ .../System/views/dictionaryValues/create.vue | 65 ++++++ .../System/views/dictionaryValues/index.vue | 64 ++++++ 13 files changed, 812 insertions(+) create mode 100644 modules/System/Http/Controllers/DictionaryController.php create mode 100644 modules/System/Http/Controllers/DictionaryValuesController.php create mode 100644 modules/System/Models/Dictionary.php create mode 100644 modules/System/Models/DictionaryValues.php create mode 100644 modules/System/Providers/SystemServiceProvider.php create mode 100644 modules/System/database/migrations/2023_05_08_043214_create_system_dictionary.php create mode 100644 modules/System/database/migrations/2023_05_08_043740_create_system_dictionary_values.php create mode 100644 modules/System/database/seeder/SystemMenusSeeder.php create mode 100644 modules/System/routes/route.php create mode 100644 modules/System/views/dictionary/create.vue create mode 100644 modules/System/views/dictionary/index.vue create mode 100644 modules/System/views/dictionaryValues/create.vue create mode 100644 modules/System/views/dictionaryValues/index.vue diff --git a/modules/System/Http/Controllers/DictionaryController.php b/modules/System/Http/Controllers/DictionaryController.php new file mode 100644 index 0000000..f13dead --- /dev/null +++ b/modules/System/Http/Controllers/DictionaryController.php @@ -0,0 +1,72 @@ +model->getList(); + } + + /** + * @param Request $request + * @return mixed + */ + public function store(Request $request) + { + return $this->model->storeBy($request->all()); + } + + /** + * @param $id + * @return mixed + */ + public function show($id) + { + return $this->model->firstBy($id); + } + + /** + * @param Request $request + * @param $id + * @return mixed + */ + public function update($id, Request $request) + { + return $this->model->updateBy($id, $request->all()); + } + + /** + * @param $id + * @return mixed + */ + public function destroy($id) + { + $dictionary = $this->model->find($id); + + if ($this->model->deleteBy($id)) { + return $dictionary->values()->delete(); + } + + return false; + } + + public function enable($id) + { + return $this->model->toggleBy($id); + } +} diff --git a/modules/System/Http/Controllers/DictionaryValuesController.php b/modules/System/Http/Controllers/DictionaryValuesController.php new file mode 100644 index 0000000..edd5e58 --- /dev/null +++ b/modules/System/Http/Controllers/DictionaryValuesController.php @@ -0,0 +1,66 @@ +model->getList(); + } + + /** + * @param Request $request + * @return mixed + */ + public function store(Request $request) + { + return $this->model->storeBy($request->all()); + } + + /** + * @param $id + * @return mixed + */ + public function show($id) + { + return $this->model->firstBy($id); + } + + /** + * @param Request $request + * @param $id + * @return mixed + */ + public function update($id, Request $request) + { + return $this->model->updateBy($id, $request->all()); + } + + /** + * @param $id + * @return mixed + */ + public function destroy($id) + { + return $this->model->deleteBy($id); + } + + public function enable($id) + { + return $this->model->toggleBy($id); + } +} diff --git a/modules/System/Models/Dictionary.php b/modules/System/Models/Dictionary.php new file mode 100644 index 0000000..b48ea59 --- /dev/null +++ b/modules/System/Models/Dictionary.php @@ -0,0 +1,56 @@ + 'like', + 'key' => 'like', + 'status' => '=', + ]; + + + /** + * 字典值集合 + * + * @return HasMany + */ + public function values(): HasMany + { + return $this->hasMany(DictionaryValues::class, 'dic_id', 'id'); + } +} diff --git a/modules/System/Models/DictionaryValues.php b/modules/System/Models/DictionaryValues.php new file mode 100644 index 0000000..21af598 --- /dev/null +++ b/modules/System/Models/DictionaryValues.php @@ -0,0 +1,46 @@ + '=', + 'label' => 'like', + 'status' => '=', + ]; +} diff --git a/modules/System/Providers/SystemServiceProvider.php b/modules/System/Providers/SystemServiceProvider.php new file mode 100644 index 0000000..653d75c --- /dev/null +++ b/modules/System/Providers/SystemServiceProvider.php @@ -0,0 +1,20 @@ +id(); + $table->string('name', 100)->comment('字典名称'); + $table->string('key')->comment('字典 key'); + $table->tinyInteger('status')->default(1)->comment('状态 1 启用 2 禁用'); + $table->string('description', 1000)->comment('备注')->default(''); + $table->creatorId(); + $table->createdAt(); + $table->updatedAt(); + $table->deletedAt(); + + $table->engine='InnoDB'; + $table->comment('字段管理'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('system_dictionary'); + } +}; diff --git a/modules/System/database/migrations/2023_05_08_043740_create_system_dictionary_values.php b/modules/System/database/migrations/2023_05_08_043740_create_system_dictionary_values.php new file mode 100644 index 0000000..b1ab35c --- /dev/null +++ b/modules/System/database/migrations/2023_05_08_043740_create_system_dictionary_values.php @@ -0,0 +1,43 @@ +id(); + $table->integer('dic_id')->comment('字典ID'); + $table->string('label')->comment('值名称'); + $table->tinyInteger('value')->comment('对应值'); + $table->integer('sort')->default(0)->comment('排序'); + $table->tinyInteger('status')->default(1)->comment('状态 1 正常 2 禁用'); + $table->string('description', 1000)->comment('描述')->default(''); + $table->creatorId(); + $table->createdAt(); + $table->updatedAt(); + $table->deletedAt(); + + $table->engine='InnoDB'; + $table->comment('字典对应值'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('system_dictionary_values'); + } +}; diff --git a/modules/System/database/seeder/SystemMenusSeeder.php b/modules/System/database/seeder/SystemMenusSeeder.php new file mode 100644 index 0000000..eb1dee6 --- /dev/null +++ b/modules/System/database/seeder/SystemMenusSeeder.php @@ -0,0 +1,193 @@ +menus(); + + importTreeData($menus, 'permissions'); + } + + public function menus(): array + { + return array ( + 0 => + array ( + 'id' => 96, + 'parent_id' => 0, + 'permission_name' => '系统管理', + 'route' => '/system', + 'icon' => 'server-stack', + 'module' => 'system', + 'permission_mark' => '', + 'component' => '', + 'redirect' => NULL, + 'keepalive' => 1, + 'type' => 1, + 'hidden' => 1, + 'sort' => 1, + 'active_menu' => '', + 'creator_id' => 1, + 'created_at' => 1683535826, + 'updated_at' => 1683535826, + 'deleted_at' => 0, + ), + 1 => + array ( + 'id' => 97, + 'parent_id' => 96, + 'permission_name' => '字典管理', + 'route' => 'dictionary', + 'icon' => '', + 'module' => 'system', + 'permission_mark' => 'dictionary', + 'component' => '/System/views/dictionary/index.vue', + 'redirect' => '', + 'keepalive' => 1, + 'type' => 2, + 'hidden' => 1, + 'sort' => 1, + 'active_menu' => '', + 'creator_id' => 1, + 'created_at' => 1683535863, + 'updated_at' => 1683535874, + 'deleted_at' => 0, + ), + 2 => + array ( + 'id' => 103, + 'parent_id' => 97, + 'permission_name' => '删除', + 'route' => '', + 'icon' => '', + 'module' => 'system', + 'permission_mark' => 'dictionary@destroy', + 'component' => '', + 'redirect' => '', + 'keepalive' => 1, + 'type' => 3, + 'hidden' => 1, + 'sort' => 5, + 'active_menu' => '', + 'creator_id' => 1, + 'created_at' => 1683535980, + 'updated_at' => 1683535980, + 'deleted_at' => 0, + ), + 3 => + array ( + 'id' => 99, + 'parent_id' => 97, + 'permission_name' => '列表', + 'route' => '', + 'icon' => '', + 'module' => 'system', + 'permission_mark' => 'dictionary@index', + 'component' => '', + 'redirect' => '', + 'keepalive' => 1, + 'type' => 3, + 'hidden' => 1, + 'sort' => 1, + 'active_menu' => '', + 'creator_id' => 1, + 'created_at' => 1683535980, + 'updated_at' => 1683535980, + 'deleted_at' => 0, + ), + 4 => + array ( + 'id' => 101, + 'parent_id' => 97, + 'permission_name' => '读取', + 'route' => '', + 'icon' => '', + 'module' => 'system', + 'permission_mark' => 'dictionary@show', + 'component' => '', + 'redirect' => '', + 'keepalive' => 1, + 'type' => 3, + 'hidden' => 1, + 'sort' => 3, + 'active_menu' => '', + 'creator_id' => 1, + 'created_at' => 1683535980, + 'updated_at' => 1683535980, + 'deleted_at' => 0, + ), + 5 => + array ( + 'id' => 100, + 'parent_id' => 97, + 'permission_name' => '新增', + 'route' => '', + 'icon' => '', + 'module' => 'system', + 'permission_mark' => 'dictionary@store', + 'component' => '', + 'redirect' => '', + 'keepalive' => 1, + 'type' => 3, + 'hidden' => 1, + 'sort' => 2, + 'active_menu' => '', + 'creator_id' => 1, + 'created_at' => 1683535980, + 'updated_at' => 1683535980, + 'deleted_at' => 0, + ), + 6 => + array ( + 'id' => 102, + 'parent_id' => 97, + 'permission_name' => '更新', + 'route' => '', + 'icon' => '', + 'module' => 'system', + 'permission_mark' => 'dictionary@update', + 'component' => '', + 'redirect' => '', + 'keepalive' => 1, + 'type' => 3, + 'hidden' => 1, + 'sort' => 4, + 'active_menu' => '', + 'creator_id' => 1, + 'created_at' => 1683535980, + 'updated_at' => 1683535980, + 'deleted_at' => 0, + ), + 7 => + array ( + 'id' => 98, + 'parent_id' => 96, + 'permission_name' => '字典值管理', + 'route' => 'dictionary/values/:id', + 'icon' => '', + 'module' => 'system', + 'permission_mark' => 'dictionaryValues', + 'component' => '/System/views/dictionaryValues/index.vue', + 'redirect' => '', + 'keepalive' => 2, + 'type' => 2, + 'hidden' => 2, + 'sort' => 1, + 'active_menu' => '/system/dictionary', + 'creator_id' => 1, + 'created_at' => 1683535961, + 'updated_at' => 1683593856, + 'deleted_at' => 0, + ), +); + } +}; diff --git a/modules/System/routes/route.php b/modules/System/routes/route.php new file mode 100644 index 0000000..17966f2 --- /dev/null +++ b/modules/System/routes/route.php @@ -0,0 +1,17 @@ +group(function(){ + + Route::apiResource('dictionary', DictionaryController::class); + Route::put('dictionary/enable/{id}', [DictionaryController::class, 'enable']); + + Route::apiResource('dic/values', DictionaryValuesController::class); + Route::put('dic/values/enable/{id}', [DictionaryValuesController::class, 'enable']); + + //next +}); + diff --git a/modules/System/views/dictionary/create.vue b/modules/System/views/dictionary/create.vue new file mode 100644 index 0000000..e27560e --- /dev/null +++ b/modules/System/views/dictionary/create.vue @@ -0,0 +1,56 @@ + + + diff --git a/modules/System/views/dictionary/index.vue b/modules/System/views/dictionary/index.vue new file mode 100644 index 0000000..3daef93 --- /dev/null +++ b/modules/System/views/dictionary/index.vue @@ -0,0 +1,73 @@ + + + diff --git a/modules/System/views/dictionaryValues/create.vue b/modules/System/views/dictionaryValues/create.vue new file mode 100644 index 0000000..1c76b35 --- /dev/null +++ b/modules/System/views/dictionaryValues/create.vue @@ -0,0 +1,65 @@ + + + diff --git a/modules/System/views/dictionaryValues/index.vue b/modules/System/views/dictionaryValues/index.vue new file mode 100644 index 0000000..c66e261 --- /dev/null +++ b/modules/System/views/dictionaryValues/index.vue @@ -0,0 +1,64 @@ + + +