fix: 优化登录相关权限问题 添加按键权限判断
This commit is contained in:
@@ -3,6 +3,7 @@ import type { RouteRecordRaw } from 'vue-router';
|
||||
import type { MenuNode, MenuItemRaw } from '@/types';
|
||||
import router, { resetRouter } from '@/router';
|
||||
import { fetchMenuTree } from '@/api/menu';
|
||||
import { auth } from '@/hooks/useAuth';
|
||||
import { pageModules } from '@/router/glob';
|
||||
import { FALLBACK_MENU_NODES } from '@/config/fallbackRoutes';
|
||||
|
||||
@@ -276,6 +277,8 @@ export function useMenuStore() {
|
||||
state.loaded = true;
|
||||
} catch (err) {
|
||||
console.error('加载菜单失败:', err);
|
||||
// 权限获取失败时会强制重新登录,此时不再降级兜底菜单,避免错误路由状态
|
||||
if (!auth.isLoggedIn()) return;
|
||||
// 降级:使用本地兜底菜单
|
||||
applyMenuTree(FALLBACK_MENU_NODES);
|
||||
state.loaded = true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { reactive, computed, toRefs } from 'vue';
|
||||
import type { PermissionCode } from '@/types';
|
||||
import { fetchAuthData } from '@/api/menu';
|
||||
import { auth } from '@/hooks/useAuth';
|
||||
|
||||
interface PermissionState {
|
||||
/** 权限编码集合 */
|
||||
@@ -31,6 +32,7 @@ export function usePermissionStore() {
|
||||
state.loaded = true;
|
||||
} catch (err) {
|
||||
console.error('加载权限失败:', err);
|
||||
if (!auth.isLoggedIn()) return;
|
||||
state.codes = new Set();
|
||||
state.roles = [];
|
||||
state.loaded = true;
|
||||
|
||||
Reference in New Issue
Block a user