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');
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 () => {
// 监听布局配置弹窗点击打开