update:优化部分代码
This commit is contained in:
parent
61ecd0629f
commit
706410480b
@ -31,7 +31,7 @@ class DomainMenusSeed extends Seeder
|
||||
return array (
|
||||
0 =>
|
||||
array (
|
||||
'id' => 72,
|
||||
'id' => 82,
|
||||
'permission_name' => '域名管理',
|
||||
'parent_id' => 0,
|
||||
'level' => '',
|
||||
@ -47,15 +47,16 @@ class DomainMenusSeed extends Seeder
|
||||
'hidden' => 1,
|
||||
'sort' => 1,
|
||||
'created_at' => 1601105834,
|
||||
'updated_at' => 1601105834,
|
||||
'updated_at' => 1612754299,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
1 =>
|
||||
'children' =>
|
||||
array (
|
||||
'id' => 73,
|
||||
0 =>
|
||||
array (
|
||||
'id' => 83,
|
||||
'permission_name' => '域名设置',
|
||||
'parent_id' => 72,
|
||||
'level' => '72',
|
||||
'parent_id' => 82,
|
||||
'level' => '82',
|
||||
'route' => '/domain/index',
|
||||
'icon' => 'el-icon-setting',
|
||||
'module' => 'domain',
|
||||
@ -68,15 +69,15 @@ class DomainMenusSeed extends Seeder
|
||||
'hidden' => 1,
|
||||
'sort' => 8,
|
||||
'created_at' => 1601105879,
|
||||
'updated_at' => 1601112604,
|
||||
'updated_at' => 1612754299,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
2 =>
|
||||
1 =>
|
||||
array (
|
||||
'id' => 84,
|
||||
'permission_name' => '域名记录',
|
||||
'parent_id' => 72,
|
||||
'level' => '72',
|
||||
'parent_id' => 82,
|
||||
'level' => '82',
|
||||
'route' => '/domain/record/:domain',
|
||||
'icon' => 'el-icon-document',
|
||||
'module' => 'domain',
|
||||
@ -89,9 +90,11 @@ class DomainMenusSeed extends Seeder
|
||||
'hidden' => 2,
|
||||
'sort' => 1,
|
||||
'created_at' => 1601112569,
|
||||
'updated_at' => 1601112606,
|
||||
'updated_at' => 1612754299,
|
||||
'deleted_at' => 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
@ -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('模块没有缓存') :
|
||||
|
Loading…
x
Reference in New Issue
Block a user