From 13c8318adc5aa28cb90cc55d1de9eb7ba1ae14cc Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 9 Jan 2026 23:05:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=201.=20=E7=94=A8=20ref=20=E5=8C=85?= =?UTF-8?q?=E8=A3=85=20flag;=202.=20=E5=9C=A8=E6=9C=80=E5=90=8E=20?= =?UTF-8?q?=E6=B8=85=E7=90=86=20flag;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/src/store/auth.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/playground/src/store/auth.ts b/playground/src/store/auth.ts index 9d461d15..1fec5c04 100644 --- a/playground/src/store/auth.ts +++ b/playground/src/store/auth.ts @@ -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() {