fix 控制器分层时权限问题,优化多个菜单关联同一控制器时权限显示逻辑

This commit is contained in:
ichynul 2025-07-30 14:52:52 +08:00
parent 8a31906b6b
commit e48a9c1295
2 changed files with 14 additions and 2 deletions

View File

@ -159,6 +159,7 @@ class Role extends Controller
$urlBase = '';
$ids = [];
$controllerPermList = $this->permModel->order('controller,action')->select();
$menuUlrs = [];
if ($isEdit) {
$menuIds = $this->roleMenuModel->where(['role_id' => $data['id']])->column('menu_id');
@ -177,6 +178,10 @@ class Role extends Controller
$perIds = $this->rolePermModel->where(['role_id' => $data['id']])->column('permission_id');
}
foreach ($tree as $tr) {
$menuUlrs[] = $tr['url'];
}
foreach ($tree as $tr) {
if ($tr['parent_id'] == '0') {
$form->divider('', '', 12)->value('<h4><label class="label label-secondary">' . $tr['title'] . '</label></h4>')->size(0, 12)->showLabel(false);
@ -209,7 +214,14 @@ class Role extends Controller
if ($cprow['action'] == '#') {
continue;
}
if (in_array($cprow['url'], $menuUlrs) && $cprow['url'] != $tr['url']) {
continue;
}
if (isset($cprow['c']) && $cprow['url'] != $tr['url']) {
continue;
}
$permissions[] = $cprow;
$cprow['c'] = 1;
}
}
@ -219,7 +231,7 @@ class Role extends Controller
->optionsData($permissions, 'action_name')
->inline()
->size(2, 10)
->checkallBtn();
->checkallBtn(count($permissions) > 1 ? '全选' : '');
}
$otherPermList = $this->permModel->where('id', 'not in', $ids)->order('controller,action')->select();

View File

@ -152,7 +152,7 @@ class AdminUser extends Model
return false;
}
$url = implode('/', ['', $path[0], Str::snake($path[1]), strtolower($path[2])]);
$url = implode('/', ['', $path[0], str_replace('._', '.', Str::snake($path[1])), strtolower($path[2])]);
$noNeed = [
'/admin/index/index',