更新menu

This commit is contained in:
mkm 2023-11-09 16:05:20 +08:00
parent 138e50c86c
commit 681fc5159b
2 changed files with 11 additions and 7 deletions
app/adminapi/logic/auth

@ -232,7 +232,8 @@ class AdminLogic extends BaseLogic
$result['user'] = $admin;
// 当前管理员角色拥有的菜单
$result['menu'] = MenuLogic::getMenuByAdminId($params['id']);
$result['menu'] = MenuLogic::getMenuByAdminId($params['id'],false);
$result['top_menu'] = MenuLogic::getMenuByAdminId($params['id'],true);
// 当前管理员橘色拥有的按钮权限
$result['permissions'] = AuthLogic::getBtnAuthByRoleId($admin);
return $result;

@ -41,20 +41,23 @@ class MenuLogic extends BaseLogic
* @author 段誉
* @date 2022/7/1 10:50
*/
public static function getMenuByAdminId($adminId)
public static function getMenuByAdminId($adminId,$is_top=false)
{
$admin = Admin::findOrEmpty($adminId);
$where = [];
$menu_where=[];
$where[] = ['type', 'in', ['M', 'C']];
$where[] = ['is_disable', '=', 0];
if ($admin['root'] != 1) {
$roleMenu = SystemRoleMenu::whereIn('role_id', $admin['role_id'])->where('is_top', 1)->column('menu_id');
$where[] = ['id', 'in', $roleMenu];
} else {
if($is_top==true){
$menu_where[]=['is_top','=',1];
$where[] = ['pid', '=', 0];
}
if ($admin['root'] != 1) {
$roleMenu = SystemRoleMenu::whereIn('role_id', $admin['role_id'])->where($menu_where)->column('menu_id');
$where[] = ['id', 'in', $roleMenu];
}
$menu = SystemMenu::where($where)
->order(['sort' => 'desc', 'id' => 'asc'])