1
This commit is contained in:
17
src/App.vue
17
src/App.vue
@@ -65,7 +65,8 @@ async function validateCachedRoleId(): Promise<boolean> {
|
||||
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 () => {
|
||||
// 监听布局配置弹窗点击打开
|
||||
|
||||
Reference in New Issue
Block a user