diff --git a/src/App.vue b/src/App.vue index 0324a27..386244a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -65,7 +65,8 @@ async function validateCachedRoleId(): Promise { const cachedRoleId = Local.get('roleId'); if (cachedRoleId == null || cachedRoleId === '') return false; try { - const res = await listAllRole(); + // 使用 skipRoleHeader 避免带上无效的缓存角色导致接口 403,确保首次即可拿到列表并清除缓存 + const res = await listAllRole({ skipRoleHeader: true }); const data = res?.data; const allRoles: any[] = Array.isArray(data) ? data : data && typeof data === 'object' ? (Object.values(data) as any[]).flat() : []; const exists = allRoles.some((r: any) => r && String(r.roleId) === String(cachedRoleId)); @@ -86,9 +87,17 @@ onMounted(() => { mittBus.on('openRoleSelectDialog', () => { if (roleDialogOpenedThisSession) return; roleDialogOpenedThisSession = true; - setTimeout(() => { - changeRoleFirRef.value?.open(); - }, 300); + const tryOpen = (attempt = 0) => { + const maxAttempts = 25; // 约 2.5 秒内每 100ms 重试 + if (changeRoleFirRef.value) { + changeRoleFirRef.value.open(); + return; + } + if (attempt < maxAttempts) { + setTimeout(() => tryOpen(attempt + 1), attempt === 0 ? 300 : 100); + } + }; + tryOpen(); }); nextTick(async () => { // 监听布局配置弹窗点击打开 diff --git a/src/api/admin/role.ts b/src/api/admin/role.ts index f9c5f21..83684a5 100644 --- a/src/api/admin/role.ts +++ b/src/api/admin/role.ts @@ -158,9 +158,10 @@ export function validateRoleName(rule: any, value: any, callback: any, isEdit: b }); } -export const listAllRole = () => { +export const listAllRole = (options?: { skipRoleHeader?: boolean }) => { return request({ url: '/admin/role/listAllRole', method: 'get', + ...options, }); }; diff --git a/src/utils/request.ts b/src/utils/request.ts index 9416dde..e28be7e 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -55,11 +55,11 @@ service.interceptors.request.use( } //统一增加 当前角色CODE const roleCode = Session.getRoleCode(); - if (roleCode) { + if (roleCode && !(config as any).skipRoleHeader) { config.headers![CommonHeaderEnum.ROLE_CODE] = roleCode; } const roleId = Session.getRoleId(); - if (roleId) { + if (roleId && !(config as any).skipRoleHeader) { config.headers![CommonHeaderEnum.RRID] = roleId; }