From 706410480bc77ad0a7337d84017b9efc0658389e Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Mon, 8 Feb 2021 11:26:54 +0800 Subject: [PATCH] =?UTF-8?q?update:=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/database/seeds/DomainMenusSeed.php | 91 ++++++++++--------- catch/permissions/controller/Role.php | 31 ++++--- catch/system/controller/Module.php | 8 +- 3 files changed, 67 insertions(+), 63 deletions(-) diff --git a/catch/domain/database/seeds/DomainMenusSeed.php b/catch/domain/database/seeds/DomainMenusSeed.php index 9808999..dbbd82a 100644 --- a/catch/domain/database/seeds/DomainMenusSeed.php +++ b/catch/domain/database/seeds/DomainMenusSeed.php @@ -31,7 +31,7 @@ class DomainMenusSeed extends Seeder return array ( 0 => array ( - 'id' => 72, + 'id' => 82, 'permission_name' => '域名管理', 'parent_id' => 0, 'level' => '', @@ -47,50 +47,53 @@ class DomainMenusSeed extends Seeder 'hidden' => 1, 'sort' => 1, 'created_at' => 1601105834, - 'updated_at' => 1601105834, - 'deleted_at' => 0, - ), - 1 => - array ( - 'id' => 73, - 'permission_name' => '域名设置', - 'parent_id' => 72, - 'level' => '72', - 'route' => '/domain/index', - 'icon' => 'el-icon-setting', - 'module' => 'domain', - 'creator_id' => 1, - 'permission_mark' => 'domain', - 'component' => 'domain', - 'redirect' => '', - 'keepalive' => 1, - 'type' => 1, - 'hidden' => 1, - 'sort' => 8, - 'created_at' => 1601105879, - 'updated_at' => 1601112604, - 'deleted_at' => 0, - ), - 2 => - array ( - 'id' => 84, - 'permission_name' => '域名记录', - 'parent_id' => 72, - 'level' => '72', - 'route' => '/domain/record/:domain', - 'icon' => 'el-icon-document', - 'module' => 'domain', - 'creator_id' => 1, - 'permission_mark' => 'domainRecord', - 'component' => 'domainRecord', - 'redirect' => '', - 'keepalive' => 1, - 'type' => 1, - 'hidden' => 2, - 'sort' => 1, - 'created_at' => 1601112569, - 'updated_at' => 1601112606, + 'updated_at' => 1612754299, 'deleted_at' => 0, + 'children' => + array ( + 0 => + array ( + 'id' => 83, + 'permission_name' => '域名设置', + 'parent_id' => 82, + 'level' => '82', + 'route' => '/domain/index', + 'icon' => 'el-icon-setting', + 'module' => 'domain', + 'creator_id' => 1, + 'permission_mark' => 'domain', + 'component' => 'domain', + 'redirect' => '', + 'keepalive' => 1, + 'type' => 1, + 'hidden' => 1, + 'sort' => 8, + 'created_at' => 1601105879, + 'updated_at' => 1612754299, + 'deleted_at' => 0, + ), + 1 => + array ( + 'id' => 84, + 'permission_name' => '域名记录', + 'parent_id' => 82, + 'level' => '82', + 'route' => '/domain/record/:domain', + 'icon' => 'el-icon-document', + 'module' => 'domain', + 'creator_id' => 1, + 'permission_mark' => 'domainRecord', + 'component' => 'domainRecord', + 'redirect' => '', + 'keepalive' => 1, + 'type' => 1, + 'hidden' => 2, + 'sort' => 1, + 'created_at' => 1601112569, + 'updated_at' => 1612754299, + 'deleted_at' => 0, + ), + ), ), ); } diff --git a/catch/permissions/controller/Role.php b/catch/permissions/controller/Role.php index 53f34ed..3c2da56 100644 --- a/catch/permissions/controller/Role.php +++ b/catch/permissions/controller/Role.php @@ -46,11 +46,12 @@ class Role extends CatchController } $this->role->storeBy($params); - $permissions = $params['permissions']; - if (!empty($permissions)) { - $this->role->attachPermissions(array_unique($permissions)); + // 分配权限 + if (count($params['permissions'])) { + $this->role->attachPermissions(array_unique($params['permissions'])); } - if (!empty($params['departments'])) { + // 分配部门 + if (count($params['departments'])) { $this->role->attachDepartments($params['departments']); } // 添加角色 @@ -168,24 +169,24 @@ class Role extends CatchController { $parentRoleHasPermissionIds = []; if ($request->param('parent_id')) { - $permissions = $this->role->findBy($request->param('parent_id'))->getPermissions(); - foreach ($permissions as $_permission) { - $parentRoleHasPermissionIds[] = $_permission->pivot->permission_id; - } + $this->role->findBy($request->param('parent_id')) + ->getPermissions() + ->each(function ($permission) use (&$parentRoleHasPermissionIds){ + $parentRoleHasPermissionIds[] = $permission->pivot->permission_id; + }); } - $permissions = Permissions::whereIn('id', $parentRoleHasPermissionIds)->select()->toTree(); - $permissionIds = []; if ($request->param('role_id')) { - $roleHasPermissions = $this->role->findBy($request->param('role_id'))->getPermissions(); - foreach ($roleHasPermissions as $_permission) { - $permissionIds[] = $_permission->pivot->permission_id; - } + $this->role->findBy($request->param('role_id')) + ->getPermissions() + ->each(function ($permission) use (&$roleHasPermissions){ + $permissionIds[] = $permission->pivot->permission_id; + }); } return CatchResponse::success([ - 'permissions' => $permissions, + 'permissions' => Permissions::whereIn('id', $parentRoleHasPermissionIds)->select()->toTree(), 'hasPermissions' => $permissionIds, ]); } diff --git a/catch/system/controller/Module.php b/catch/system/controller/Module.php index d518499..6d6723f 100644 --- a/catch/system/controller/Module.php +++ b/catch/system/controller/Module.php @@ -17,7 +17,7 @@ class Module extends CatchController * * @return Json */ - public function index() + public function index(): Json { $modules = []; @@ -51,7 +51,7 @@ class Module extends CatchController * @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\DataNotFoundException */ - public function disOrEnable(string $module) + public function disOrEnable(string $module): Json { $moduleInfo = CatchAdmin::getModuleInfo(CatchAdmin::directory() . $module); @@ -71,7 +71,7 @@ class Module extends CatchController * @time 2020年09月21日 * @return Json */ - public function cache() + public function cache(): Json { return CatchResponse::success(CatchAdmin::cacheServices()); } @@ -82,7 +82,7 @@ class Module extends CatchController * @time 2020年09月21日 * @return Json */ - public function clear() + public function clear(): Json { return !file_exists(CatchAdmin::getCacheServicesFile()) ? CatchResponse::fail('模块没有缓存') :