feat(menu): 增加获取模块菜单功能并优化菜单逻辑
- 新增 model_menu_lists 方法,用于根据 ID 获取模块菜单 - 修改 getMenuByAdminId 方法,增加获取顶级菜单的功能 - 实现 getModelList 方法,用于获取指定模型的菜单列表
This commit is contained in:
parent
c1eae91e2c
commit
2b5e27bb87
@ -130,5 +130,16 @@ class MenuController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id获取模块菜单
|
||||
*/
|
||||
public function model_menu_lists()
|
||||
{
|
||||
$id=$this->request->get('id',0);
|
||||
if($id==0){
|
||||
return $this->fail('缺少参数');
|
||||
}
|
||||
$list=MenuLogic::getModelList($id,$this->adminId);
|
||||
return $this->success('操作成功', $list);
|
||||
}
|
||||
}
|
@ -233,6 +233,8 @@ class AdminLogic extends BaseLogic
|
||||
$result['user'] = $admin;
|
||||
// 当前管理员角色拥有的菜单
|
||||
$result['menu'] = MenuLogic::getMenuByAdminId($params['id']);
|
||||
$result['top_menu'] = MenuLogic::getMenuByAdminId($params['id'],true);
|
||||
|
||||
// 当前管理员橘色拥有的按钮权限
|
||||
$result['permissions'] = AuthLogic::getBtnAuthByRoleId($admin);
|
||||
return $result;
|
||||
|
@ -41,19 +41,26 @@ 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'])->column('menu_id');
|
||||
if($is_top==true){
|
||||
$menu_where[]=['is_top','=',1];
|
||||
$where[] = ['pid', '=', 0];
|
||||
}
|
||||
if ($admin['root'] != 1 || $is_top==true) {
|
||||
if(!empty($admin['role_id'])){
|
||||
$menu_where[]=['role_id','in',$admin['role_id']];
|
||||
}
|
||||
$roleMenu = SystemRoleMenu::where($menu_where)->column('menu_id');
|
||||
$where[] = ['id', 'in', $roleMenu];
|
||||
}
|
||||
|
||||
$menu = SystemMenu::where($where)
|
||||
->order(['sort' => 'desc', 'id' => 'asc'])
|
||||
->select();
|
||||
@ -181,4 +188,25 @@ class MenuLogic extends BaseLogic
|
||||
return linear_to_tree($data, 'children');
|
||||
}
|
||||
|
||||
public static function getModelList($id,$adminId){
|
||||
$where = [];
|
||||
$where[] = ['is_disable', '=', 0];
|
||||
$where[] = ['id', '=', $id];
|
||||
$model_name = SystemMenu::where($where)->value('paths');
|
||||
if($model_name){
|
||||
unset($where[1]);
|
||||
$where[] = ['type', 'in', ['M', 'C']];
|
||||
$where[] = ['model_name', '=', $model_name];
|
||||
$admin = Admin::findOrEmpty($adminId);
|
||||
if ($admin['root'] != 1) {
|
||||
$roleMenu = SystemRoleMenu::whereIn('role_id', $admin['role_id'])->column('menu_id');
|
||||
$where[] = ['id', 'in', $roleMenu];
|
||||
}
|
||||
$menu = SystemMenu::where($where)
|
||||
->order(['sort' => 'desc', 'id' => 'asc'])
|
||||
->select();
|
||||
return linear_to_tree($menu, 'children','id','pid',$id);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user