修复优化后台报错

This commit is contained in:
2026-03-06 11:34:36 +08:00
parent 01f71a4871
commit 943d8f7b5f
2 changed files with 65 additions and 27 deletions

View File

@@ -33,26 +33,39 @@ class SystemController extends BaseController
*/
public function userInfo(): Response
{
if ($this->adminInfo === null || !is_array($this->adminInfo) || !isset($this->adminInfo['id'])) {
return $this->fail('登录已过期或用户信息无效,请重新登录', 401);
$adminInfo = $this->adminInfo;
if ($adminInfo === null || !is_array($adminInfo) || !isset($adminInfo['id'])) {
$token = getCurrentInfo();
if (!is_array($token) || empty($token['id'])) {
return $this->fail('登录已过期或用户信息无效,请重新登录', 401);
}
$adminInfo = UserInfoCache::getUserInfo($token['id']);
if (empty($adminInfo) || !isset($adminInfo['id'])) {
$adminInfo = UserInfoCache::setUserInfo($token['id']);
}
if (empty($adminInfo) || !isset($adminInfo['id'])) {
return $this->fail('登录已过期或用户信息无效,请重新登录', 401);
}
$this->adminInfo = $adminInfo;
}
$info = [];
$info['id'] = $this->adminInfo['id'];
$info['username'] = $this->adminInfo['username'];
$info['dashboard'] = $this->adminInfo['dashboard'] ?? '';
$info['avatar'] = $this->adminInfo['avatar'] ?? '';
$info['email'] = $this->adminInfo['email'] ?? '';
$info['phone'] = $this->adminInfo['phone'] ?? '';
$info['gender'] = $this->adminInfo['gender'] ?? '';
$info['signed'] = $this->adminInfo['signed'] ?? '';
$info['realname'] = $this->adminInfo['realname'] ?? '';
$info['department'] = $this->adminInfo['deptList'] ?? [];
if ((int) $this->adminInfo['id'] === 1) {
$info['id'] = $adminInfo['id'];
$info['username'] = $adminInfo['username'] ?? '';
$info['dashboard'] = $adminInfo['dashboard'] ?? '';
$info['avatar'] = $adminInfo['avatar'] ?? '';
$info['email'] = $adminInfo['email'] ?? '';
$info['phone'] = $adminInfo['phone'] ?? '';
$info['gender'] = $adminInfo['gender'] ?? '';
$info['signed'] = $adminInfo['signed'] ?? '';
$info['realname'] = $adminInfo['realname'] ?? '';
$info['department'] = $adminInfo['deptList'] ?? [];
if (isset($adminInfo['id']) && $adminInfo['id'] == 1) {
$info['buttons'] = ['*'];
$info['roles'] = ['super_admin'];
} else {
$info['buttons'] = UserAuthCache::getUserAuth($this->adminInfo['id']);
$info['roles'] = Arr::getArrayColumn($this->adminInfo['roleList'] ?? [], 'code');
$info['buttons'] = UserAuthCache::getUserAuth($adminInfo['id']);
$info['roles'] = Arr::getArrayColumn($adminInfo['roleList'] ?? [], 'code');
}
return $this->success($info);
}
@@ -72,7 +85,7 @@ class SystemController extends BaseController
*/
public function menu(): Response
{
if ($this->adminInfo === null || !is_array($this->adminInfo) || !isset($this->adminInfo['id'])) {
if (!$this->ensureAdminInfo()) {
return $this->fail('登录已过期或用户信息无效,请重新登录', 401);
}
$data = UserMenuCache::getUserMenu($this->adminInfo['id']);