mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-07 23:31:08 +08:00
refactor: 1. 用 ref 包装 flag; 2. 在最后 清理 flag;
This commit is contained in:
@@ -78,31 +78,32 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
};
|
||||
}
|
||||
|
||||
let isLoggingOut = false; // 正在 logout 标识, 防止 /logout 死循环.
|
||||
const isLoggingOut = ref(false); // 正在 logout 标识, 防止 /logout 死循环.
|
||||
|
||||
async function logout(redirect: boolean = true) {
|
||||
if (isLoggingOut) return;
|
||||
isLoggingOut = true;
|
||||
if (isLoggingOut.value) return; // 正在登出中, 说明已进入循环, 直接返回.
|
||||
isLoggingOut.value = true; // 设置 标识
|
||||
|
||||
try {
|
||||
await logoutApi();
|
||||
|
||||
resetAllStores();
|
||||
accessStore.setLoginExpired(false);
|
||||
|
||||
// 回登录页带上当前路由地址
|
||||
await router.replace({
|
||||
path: LOGIN_PATH,
|
||||
query: redirect
|
||||
? {
|
||||
redirect: encodeURIComponent(router.currentRoute.value.fullPath),
|
||||
}
|
||||
: {},
|
||||
});
|
||||
} catch {
|
||||
// 不做任何处理
|
||||
} finally {
|
||||
isLoggingOut = false;
|
||||
isLoggingOut.value = false; // 重置 标识
|
||||
}
|
||||
|
||||
resetAllStores();
|
||||
accessStore.setLoginExpired(false);
|
||||
|
||||
// 回登录页带上当前路由地址
|
||||
await router.replace({
|
||||
path: LOGIN_PATH,
|
||||
query: redirect
|
||||
? {
|
||||
redirect: encodeURIComponent(router.currentRoute.value.fullPath),
|
||||
}
|
||||
: {},
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchUserInfo() {
|
||||
|
||||
Reference in New Issue
Block a user