更新jwt问题
This commit is contained in:
@@ -17,7 +17,86 @@ use app\model\AdminUserGroup;
|
||||
class MenuController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取用户菜单接口
|
||||
* 获取当前登录用户的菜单接口
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getMyMenus()
|
||||
{
|
||||
try {
|
||||
$userInfo = $this->getAdminUserInfo();
|
||||
|
||||
if (!$userInfo || !isset($userInfo['id']) || $userInfo['id'] == 0) {
|
||||
return json([
|
||||
'code' => 401,
|
||||
'msg' => '用户ID不存在,请重新登录',
|
||||
'data' => null
|
||||
]);
|
||||
}
|
||||
|
||||
$user = AdminUser::where('id', $userInfo['id'])->find();
|
||||
|
||||
if (!$user) {
|
||||
return json([
|
||||
'code' => 404,
|
||||
'msg' => '用户不存在',
|
||||
'data' => null
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取用户组权限信息
|
||||
$userGroup = AdminUserGroup::where('id', $user['group_id'])
|
||||
->find();
|
||||
|
||||
if (!$userGroup) {
|
||||
return json([
|
||||
'code' => 404,
|
||||
'msg' => '用户组不存在',
|
||||
'data' => null
|
||||
]);
|
||||
}
|
||||
|
||||
// 解析权限数组
|
||||
$menuIds = [];
|
||||
if (!empty($userGroup['rights'])) {
|
||||
$menuIds = is_array($userGroup['rights']) ? $userGroup['rights'] : json_decode($userGroup['rights'], true);
|
||||
}
|
||||
|
||||
// 如果权限为空,返回空数组
|
||||
if (empty($menuIds)) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => 'success',
|
||||
'data' => []
|
||||
]);
|
||||
}
|
||||
|
||||
// 获取有权限的菜单
|
||||
$menus = SystemMenu::where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->whereIn('id', $menuIds)
|
||||
->field('id,pid,title,path,component_path,icon,sort')
|
||||
->order('sort', 'asc')
|
||||
->select();
|
||||
|
||||
// 将菜单转换为树形结构
|
||||
$treeMenus = $this->buildMenuTree($menus->toArray());
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => 'success',
|
||||
'data' => $treeMenus
|
||||
]);
|
||||
} catch (DbException $e) {
|
||||
return json([
|
||||
'code' => 500,
|
||||
'msg' => 'fail:' . $e->getMessage(),
|
||||
'data' => $e->getTraceAsString()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户菜单接口(需要传入用户ID)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getMenus(int $id)
|
||||
|
||||
Reference in New Issue
Block a user