diff --git a/catch/database/migrations/2022_11_14_034127_module.php b/catch/database/migrations/2022_11_14_034127_module.php index 6601bb1..4fbc5b9 100644 --- a/catch/database/migrations/2022_11_14_034127_module.php +++ b/catch/database/migrations/2022_11_14_034127_module.php @@ -16,6 +16,8 @@ return new class () extends Migration { Schema::create(config('catch.module.table_name'), function (Blueprint $table) { $table->increments('id'); + $table->string('title')->comment('模块标题'); + $table->string('name')->comment('模块名称'); $table->string('path', 20)->comment('模块目录'); diff --git a/catch/src/Support/Module/Driver/DatabaseDriver.php b/catch/src/Support/Module/Driver/DatabaseDriver.php index 90dca40..57b21e9 100644 --- a/catch/src/Support/Module/Driver/DatabaseDriver.php +++ b/catch/src/Support/Module/Driver/DatabaseDriver.php @@ -44,8 +44,8 @@ class DatabaseDriver implements ModuleRepositoryInterface public function all(array $search): Collection { return $this->model::query() - ->when($search['name'] ?? false, function ($query) use ($search) { - $query->where('name', 'like', '%'.$search['name'].'%'); + ->when($search['title'] ?? false, function ($query) use ($search) { + $query->where('title', 'like', '%'.$search['title'].'%'); })->get(); } @@ -60,7 +60,7 @@ class DatabaseDriver implements ModuleRepositoryInterface $this->hasSameModule($module); return $this->model->save([ - 'name' => $module['name'], + 'title' => $module['title'], 'path' => $module['path'], 'description' => $module['desc'], 'keywords' => $module['keywords'], @@ -91,7 +91,8 @@ class DatabaseDriver implements ModuleRepositoryInterface return $this->model->where('name', $name) ->update([ - 'name' => $module['name'], + 'title' => $module['title'], + 'name' => $module['path'], 'path' => $module['path'], 'description' => $module['desc'], 'keywords' => $module['keywords'], @@ -119,7 +120,7 @@ class DatabaseDriver implements ModuleRepositoryInterface { $module = $this->show($name); - $module->status = (int) $module->status; + $module->enable = (int) $module->enable; return $module->save(); } @@ -132,7 +133,7 @@ class DatabaseDriver implements ModuleRepositoryInterface public function getEnabled(): Collection { // TODO: Implement getEnabled() method. - return $this->model->where('status', Status::Enable->value())->get(); + return $this->model->where('enable', Status::Enable->value())->get(); } /** @@ -144,7 +145,7 @@ class DatabaseDriver implements ModuleRepositoryInterface public function enabled(string $moduleName): bool { // TODO: Implement enabled() method. - return $this->getEnabled()->pluck('path')->contains($moduleName); + return $this->getEnabled()->pluck('name')->contains($moduleName); } /** @@ -157,10 +158,6 @@ class DatabaseDriver implements ModuleRepositoryInterface if ($this->model->where('name', $module['name'])->first()) { throw new FailedException(sprintf('Module [%s] has been created', $module['name'])); } - - if ($this->model->where('path', $module['path'])->first()) { - throw new FailedException(sprintf('Module Alias [%s] has been exised', $module['alias'])); - } } /** diff --git a/catch/src/Support/Module/Driver/FileDriver.php b/catch/src/Support/Module/Driver/FileDriver.php index 709f8ce..3e70f26 100644 --- a/catch/src/Support/Module/Driver/FileDriver.php +++ b/catch/src/Support/Module/Driver/FileDriver.php @@ -55,14 +55,14 @@ class FileDriver implements ModuleRepositoryInterface $modules = Collection::make(\json_decode(File::get($this->moduleJson), true))->values(); - $name = $search['name'] ?? ''; + $title = $search['title'] ?? ''; - if (! $name) { + if (! $title) { return $modules; } - return $modules->filter(function ($module) use ($name) { - return Str::of($module['name'])->contains($name); + return $modules->filter(function ($module) use ($title) { + return Str::of($module['title'])->contains($title); }); } @@ -82,6 +82,8 @@ class FileDriver implements ModuleRepositoryInterface $module['version'] = '1.0.0'; $module['enable'] = true; + $this->removeDirs($module); + File::put($this->moduleJson, $modules->push($module)->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); return true; @@ -115,12 +117,13 @@ class FileDriver implements ModuleRepositoryInterface { File::put($this->moduleJson, $this->all()->map(function ($m) use ($module, $name) { if (Str::of($name)->exactly($m['name'])) { - $m['path'] = $module['path']; $m['name'] = $module['name']; + $m['title'] = $module['title']; $m['description'] = $module['description'] ?? ''; $m['keywords'] = $module['keywords'] ?? ''; $m['enable'] = $module['enable']; } + $this->removeDirs($m); return $m; })->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); @@ -180,7 +183,7 @@ class FileDriver implements ModuleRepositoryInterface public function enabled(string $moduleName): bool { // TODO: Implement enabled() method. - return $this->getEnabled()->pluck('path')->contains($moduleName); + return $this->getEnabled()->pluck('name')->contains($moduleName); } /** @@ -195,10 +198,18 @@ class FileDriver implements ModuleRepositoryInterface if ($modules->pluck('name')->contains($module['name'])) { throw new FailedException(sprintf('Module [%s] has been created', $module['name'])); } + } + } - if ($modules->pluck('path')->contains($module['path'])) { - throw new FailedException(sprintf('Module path [%s] has been existed', $module['path'])); - } + /** + * remove dirs + * + * @param array $modules + */ + protected function removeDirs(array &$modules) + { + if ($modules['dirs'] ?? false) { + unset($modules['dirs']); } } } diff --git a/catch/src/Support/Module/ModuleRepository.php b/catch/src/Support/Module/ModuleRepository.php index a7dfe8b..20994c4 100644 --- a/catch/src/Support/Module/ModuleRepository.php +++ b/catch/src/Support/Module/ModuleRepository.php @@ -59,6 +59,8 @@ class ModuleRepository */ public function create(array $module): bool { + $module['name'] = lcfirst($module['path']); + Event::dispatch(new Creating($module)); $this->moduleRepository->create($module); @@ -93,6 +95,8 @@ class ModuleRepository */ public function update(string $name, array $module): bool { + $module['name'] = lcfirst($module['path']); + Event::dispatch(new Updating($name, $module)); $this->moduleRepository->update($name, $module); diff --git a/modules/Develop/views/module/create.vue b/modules/Develop/views/module/create.vue index 3248812..501233a 100644 --- a/modules/Develop/views/module/create.vue +++ b/modules/Develop/views/module/create.vue @@ -2,7 +2,7 @@ - + { + close(() => emit('close')) +}) diff --git a/modules/Develop/views/module/index.vue b/modules/Develop/views/module/index.vue index becd5d5..39e8877 100644 --- a/modules/Develop/views/module/index.vue +++ b/modules/Develop/views/module/index.vue @@ -3,14 +3,14 @@
- + @@ -54,6 +54,6 @@ const tableData = computed(() => data.value?.data) onMounted(() => { search() - deleted() + deleted(reset) }) diff --git a/modules/Options/Repository/Components.php b/modules/Options/Repository/Components.php new file mode 100644 index 0000000..75ff606 --- /dev/null +++ b/modules/Options/Repository/Components.php @@ -0,0 +1,40 @@ + 'layout', + 'value' => '/admin/layout/index.vue' + ] + ]; + + public function get(): array + { + if ($module = request()->get('module')) { + $components = File::glob(CatchAdmin::getModuleViewsPath($module) . '*/*.vue'); + + foreach ($components as $component) { + $this->components[] = [ + 'label' => Str::of($component)->explode(DIRECTORY_SEPARATOR)->pop(2)->pop(), + + 'value' => Str::of($component)->replace(CatchAdmin::moduleRootPath(), '')->prepend('/') + ]; + } + + } + + return $this->components; + } + +} diff --git a/modules/Options/Repository/Controllers.php b/modules/Options/Repository/Controllers.php new file mode 100644 index 0000000..979159d --- /dev/null +++ b/modules/Options/Repository/Controllers.php @@ -0,0 +1,32 @@ +get('module')) { + $controllerFiles = File::glob(CatchAdmin::getModuleControllerPath($module) . '*.php'); + + foreach ($controllerFiles as $controllerFile) { + $controllers[] = [ + 'label' => Str::of(File::name($controllerFile))->remove('Controller'), + + 'value' => Str::of(File::name($controllerFile))->remove('Controller'), + ]; + } + + } + + return $controllers; + } + +} diff --git a/modules/Permissions/Http/Controllers/PermissionsController.php b/modules/Permissions/Http/Controllers/PermissionsController.php index b01ce8d..ad54b10 100644 --- a/modules/Permissions/Http/Controllers/PermissionsController.php +++ b/modules/Permissions/Http/Controllers/PermissionsController.php @@ -43,4 +43,15 @@ class PermissionsController extends Controller { return $this->model->deleteBy($id); } + + /** + * enable + * + * @param $id + * @return bool + */ + public function enable($id) + { + return $this->model->disOrEnable($id, 'hidden'); + } } diff --git a/modules/Permissions/Models/PermissionsModel.php b/modules/Permissions/Models/PermissionsModel.php index 7122f67..f9e6a95 100644 --- a/modules/Permissions/Models/PermissionsModel.php +++ b/modules/Permissions/Models/PermissionsModel.php @@ -55,4 +55,14 @@ class PermissionsModel extends Model { return self::query()->select($this->fieldsInList)->quickSearch()->get()->toTree(); } + + /** + * is hidden + * + * @return bool + */ + public function isHidden(): bool + { + return $this->hidden === 2; + } } diff --git a/modules/Permissions/database/migrations/2022_12_05_084442_create_roles.php b/modules/Permissions/database/migrations/2022_12_05_084442_create_roles.php index dfdc16b..cd29f45 100644 --- a/modules/Permissions/database/migrations/2022_12_05_084442_create_roles.php +++ b/modules/Permissions/database/migrations/2022_12_05_084442_create_roles.php @@ -4,7 +4,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class extends Migration +{ /** * Run the migrations. * @@ -12,6 +13,10 @@ return new class () extends Migration { */ public function up() { + if (Schema::hasTable('roles')) { + return ; + } + Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('role_name', 30)->comment('角色名称'); diff --git a/modules/Permissions/database/migrations/2022_12_06_110551_create_jobs.php b/modules/Permissions/database/migrations/2022_12_06_110551_create_jobs.php index f0a82b9..f6100bf 100644 --- a/modules/Permissions/database/migrations/2022_12_06_110551_create_jobs.php +++ b/modules/Permissions/database/migrations/2022_12_06_110551_create_jobs.php @@ -4,7 +4,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class extends Migration +{ /** * Run the migrations. * @@ -12,6 +13,10 @@ return new class () extends Migration { */ public function up() { + if (Schema::hasTable('jobs')) { + return ; + } + Schema::create('jobs', function (Blueprint $table) { $table->increments('id'); $table->string('job_name', 50)->comment('岗位名称'); diff --git a/modules/Permissions/database/migrations/2022_12_07_075441_create_departments.php b/modules/Permissions/database/migrations/2022_12_07_075441_create_departments.php index baa5357..741c9fd 100644 --- a/modules/Permissions/database/migrations/2022_12_07_075441_create_departments.php +++ b/modules/Permissions/database/migrations/2022_12_07_075441_create_departments.php @@ -4,7 +4,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class extends Migration +{ /** * Run the migrations. * @@ -12,6 +13,10 @@ return new class () extends Migration { */ public function up() { + if (Schema::hasTable('departments')) { + return; + } + Schema::create('departments', function (Blueprint $table) { $table->increments('id'); $table->integer('parent_id')->default(0)->comment('父级ID'); diff --git a/modules/Permissions/database/migrations/2022_12_07_102456_create_permissions.php b/modules/Permissions/database/migrations/2022_12_07_102456_create_permissions.php deleted file mode 100644 index 75a9610..0000000 --- a/modules/Permissions/database/migrations/2022_12_07_102456_create_permissions.php +++ /dev/null @@ -1,48 +0,0 @@ -increments('id'); - $table->string('permission_name', 30)->comment('菜单名称'); - $table->integer('parent_id')->default('1')->comment('父级菜单'); - $table->string('route', 50)->comment('路由'); - $table->string('icon', 50)->comment('菜单 icon'); - $table->string('module', 50)->comment('所属模块'); - $table->string('permission_mark')->comment('权限标识'); - $table->string('component')->comment('组件'); - $table->string('redirect')->comment('组件跳转'); - $table->tinyInteger('keepalive')->default('1')->comment('1 缓存 2 不缓存'); - $table->tinyInteger('type')->default('1')->comment('1 菜单 2 按钮'); - $table->tinyInteger('hidden')->default('1')->comment('1 显示 2 隐藏'); - $table->integer('sort')->default('1')->comment('排序'); - $table->creatorId(); - $table->createdAt(); - $table->updatedAt(); - $table->deletedAt(); - - $table->engine = 'InnoDB'; - $table->comment('权限模块'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('permissions'); - } -}; diff --git a/modules/Permissions/database/migrations/2022_12_07_103318_create_permissions.php b/modules/Permissions/database/migrations/2022_12_07_103318_create_permissions.php index a67fc3f..d45f2fd 100644 --- a/modules/Permissions/database/migrations/2022_12_07_103318_create_permissions.php +++ b/modules/Permissions/database/migrations/2022_12_07_103318_create_permissions.php @@ -12,6 +12,10 @@ return new class () extends Migration { */ public function up() { + if (Schema::hasTable('permissions')) { + return; + } + Schema::create('permissions', function (Blueprint $table) { $table->increments('id'); $table->integer('parent_id')->default(0)->comment('父级菜单'); @@ -19,7 +23,7 @@ return new class () extends Migration { $table->string('route', 50)->comment('前端路由'); $table->string('icon', 50)->comment('菜单 icon'); $table->string('module', 50)->comment('所属模块'); - $table->string('permission_mark', 100)->comment('权限标识,使用 @ 分割'); + $table->string('permission_mark', 100)->default('')->comment('权限标识,使用 @ 分割'); $table->string('component')->comment('组件'); $table->string('redirect')->nullable()->comment('跳转地址'); $table->tinyInteger('keepalive')->default('1')->comment('1 缓存 2 不缓存'); diff --git a/modules/Permissions/database/migrations/2022_12_10_061840_create_user_has_roles.php b/modules/Permissions/database/migrations/2022_12_10_061840_create_user_has_roles.php new file mode 100644 index 0000000..bbff75a --- /dev/null +++ b/modules/Permissions/database/migrations/2022_12_10_061840_create_user_has_roles.php @@ -0,0 +1,34 @@ +integer('user_id')->comment('users primary key'); + + $table->integer('role_id')->comment('roles primary key'); + + $table->comment('user relate roles'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + + } +}; diff --git a/modules/Permissions/database/migrations/2022_12_10_061857_create_role_has_permissions.php b/modules/Permissions/database/migrations/2022_12_10_061857_create_role_has_permissions.php new file mode 100644 index 0000000..a769472 --- /dev/null +++ b/modules/Permissions/database/migrations/2022_12_10_061857_create_role_has_permissions.php @@ -0,0 +1,34 @@ +integer('role_id')->comment('roles primary key'); + + $table->integer('permission_id')->comment('permissions primary key'); + + $table->comment('role relate permissions'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + + } +}; diff --git a/modules/Permissions/database/migrations/2022_12_10_061919_create_user_has_jobs.php b/modules/Permissions/database/migrations/2022_12_10_061919_create_user_has_jobs.php new file mode 100644 index 0000000..5411e51 --- /dev/null +++ b/modules/Permissions/database/migrations/2022_12_10_061919_create_user_has_jobs.php @@ -0,0 +1,34 @@ +integer('user_id')->comment('users primary key'); + + $table->integer('job_id')->comment('jobs primary key'); + + $table->comment('user relate jobs'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + + } +}; diff --git a/modules/Permissions/database/migrations/2022_12_10_061928_create_role_has_departments.php b/modules/Permissions/database/migrations/2022_12_10_061928_create_role_has_departments.php new file mode 100644 index 0000000..595de82 --- /dev/null +++ b/modules/Permissions/database/migrations/2022_12_10_061928_create_role_has_departments.php @@ -0,0 +1,34 @@ +integer('role_id')->comment('roles primary key'); + + $table->integer('department_id')->comment('departments primary key'); + + $table->comment('role relate departments'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + + } +}; diff --git a/modules/Permissions/route.php b/modules/Permissions/route.php index 72a5a92..8a0521f 100644 --- a/modules/Permissions/route.php +++ b/modules/Permissions/route.php @@ -16,5 +16,6 @@ Route::prefix('permissions')->group(function () { Route::put('departments/enable/{id}', [DepartmentsController::class, 'enable']); Route::apiResource('permissions', PermissionsController::class); + Route::put('permissions/enable/{id}', [PermissionsController::class, 'enable']); //next }); diff --git a/modules/Permissions/views/departments/create.vue b/modules/Permissions/views/departments/form/create.vue similarity index 100% rename from modules/Permissions/views/departments/create.vue rename to modules/Permissions/views/departments/form/create.vue diff --git a/modules/Permissions/views/departments/index.vue b/modules/Permissions/views/departments/index.vue index 01e941a..1122762 100644 --- a/modules/Permissions/views/departments/index.vue +++ b/modules/Permissions/views/departments/index.vue @@ -35,7 +35,7 @@ + + diff --git a/resources/admin/components/admin/status/index.vue b/resources/admin/components/admin/status/index.vue index 20372ae..3917009 100644 --- a/resources/admin/components/admin/status/index.vue +++ b/resources/admin/components/admin/status/index.vue @@ -1,10 +1,11 @@