This commit is contained in:
zhoutc
2026-03-09 01:31:30 +08:00
parent 236e5f5594
commit 8575b5e0b1
3 changed files with 17 additions and 7 deletions

View File

@@ -65,7 +65,8 @@ async function validateCachedRoleId(): Promise<boolean> {
const cachedRoleId = Local.get('roleId'); const cachedRoleId = Local.get('roleId');
if (cachedRoleId == null || cachedRoleId === '') return false; if (cachedRoleId == null || cachedRoleId === '') return false;
try { try {
const res = await listAllRole(); // 使用 skipRoleHeader 避免带上无效的缓存角色导致接口 403确保首次即可拿到列表并清除缓存
const res = await listAllRole({ skipRoleHeader: true });
const data = res?.data; const data = res?.data;
const allRoles: any[] = Array.isArray(data) ? data : data && typeof data === 'object' ? (Object.values(data) as any[]).flat() : []; 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)); const exists = allRoles.some((r: any) => r && String(r.roleId) === String(cachedRoleId));
@@ -86,9 +87,17 @@ onMounted(() => {
mittBus.on('openRoleSelectDialog', () => { mittBus.on('openRoleSelectDialog', () => {
if (roleDialogOpenedThisSession) return; if (roleDialogOpenedThisSession) return;
roleDialogOpenedThisSession = true; roleDialogOpenedThisSession = true;
setTimeout(() => { const tryOpen = (attempt = 0) => {
changeRoleFirRef.value?.open(); const maxAttempts = 25; // 约 2.5 秒内每 100ms 重试
}, 300); if (changeRoleFirRef.value) {
changeRoleFirRef.value.open();
return;
}
if (attempt < maxAttempts) {
setTimeout(() => tryOpen(attempt + 1), attempt === 0 ? 300 : 100);
}
};
tryOpen();
}); });
nextTick(async () => { nextTick(async () => {
// 监听布局配置弹窗点击打开 // 监听布局配置弹窗点击打开

View File

@@ -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({ return request({
url: '/admin/role/listAllRole', url: '/admin/role/listAllRole',
method: 'get', method: 'get',
...options,
}); });
}; };

View File

@@ -55,11 +55,11 @@ service.interceptors.request.use(
} }
//统一增加 当前角色CODE //统一增加 当前角色CODE
const roleCode = Session.getRoleCode(); const roleCode = Session.getRoleCode();
if (roleCode) { if (roleCode && !(config as any).skipRoleHeader) {
config.headers![CommonHeaderEnum.ROLE_CODE] = roleCode; config.headers![CommonHeaderEnum.ROLE_CODE] = roleCode;
} }
const roleId = Session.getRoleId(); const roleId = Session.getRoleId();
if (roleId) { if (roleId && !(config as any).skipRoleHeader) {
config.headers![CommonHeaderEnum.RRID] = roleId; config.headers![CommonHeaderEnum.RRID] = roleId;
} }