refactor: 1. 用 ref 包装 flag; 2. 在最后 清理 flag;

This commit is contained in:
eric
2026-01-09 23:05:05 +08:00
parent 48ed797055
commit 13c8318adc

View File

@@ -78,18 +78,14 @@ export const useAuthStore = defineStore('auth', () => {
}; };
} }
let isLoggingOut = false; // 正在 logout 标识, 防止 /logout 死循环. const isLoggingOut = ref(false); // 正在 logout 标识, 防止 /logout 死循环.
async function logout(redirect: boolean = true) { async function logout(redirect: boolean = true) {
if (isLoggingOut) return; if (isLoggingOut.value) return; // 正在登出中, 说明已进入循环, 直接返回.
isLoggingOut = true; isLoggingOut.value = true; // 设置 标识
try { try {
await logoutApi(); await logoutApi();
} catch {
// 不做任何处理
} finally {
isLoggingOut = false;
}
resetAllStores(); resetAllStores();
accessStore.setLoginExpired(false); accessStore.setLoginExpired(false);
@@ -103,6 +99,11 @@ export const useAuthStore = defineStore('auth', () => {
} }
: {}, : {},
}); });
} catch {
// 不做任何处理
} finally {
isLoggingOut.value = false; // 重置 标识
}
} }
async function fetchUserInfo() { async function fetchUserInfo() {