From 9fb3c511928408efe00ee077c043cc4ef6621c68 Mon Sep 17 00:00:00 2001 From: smail Date: Thu, 3 Sep 2026 01:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=B7=E6=96=B0=E5=90=8E?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=8A=B6=E6=80=81=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fe/src/App.vue | 8 +---- fe/src/main.js | 11 +++++-- fe/src/stores/useGlobalStatusStore.js | 46 ++++++++++++++++----------- fe/src/utils/axios.js | 6 ++-- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/fe/src/App.vue b/fe/src/App.vue index 272b659..4b111c5 100644 --- a/fe/src/App.vue +++ b/fe/src/App.vue @@ -3,7 +3,7 @@ import {RouterView, useRoute} from 'vue-router' import HomeHeader from '@/views/components/HomeHeader/HomeHeader.vue' import HomeAside from '@/views/components/HomeAside/HomeAside.vue'; import RecoverySetupPrompt from '@/views/components/RecoverySetupPrompt/RecoverySetupPrompt.vue' -import {ref, watch, onMounted} from 'vue' +import {ref, watch} from 'vue' import {useGlobalStatusStore} from "@/stores/useGlobalStatusStore"; const route = useRoute() @@ -11,12 +11,6 @@ const pageName = ref(route.name) const globalStatus = useGlobalStatusStore(); const standalonePages = ['login', 'login-verification', 'force-password-change', 'setup', 'forgot-password', 'reset-blocked'] -onMounted(() => { - if (!standalonePages.includes(route.name)) { - globalStatus.init(() => {}); - } -}); - watch( () => route.fullPath, () => { diff --git a/fe/src/main.js b/fe/src/main.js index e0e2b44..9a98b3c 100644 --- a/fe/src/main.js +++ b/fe/src/main.js @@ -29,7 +29,12 @@ if (isReservedResetPath(window.location.pathname)) { } const app = createApp(App) +const pinia = createPinia() + +app.use(pinia) app.use(router) -app.use(createPinia()) -app.use(ElementPlus) -app.mount('#app') +app.use(ElementPlus) + +router.isReady().then(() => { + app.mount('#app') +}) diff --git a/fe/src/stores/useGlobalStatusStore.js b/fe/src/stores/useGlobalStatusStore.js index c23e00b..f9724fd 100644 --- a/fe/src/stores/useGlobalStatusStore.js +++ b/fe/src/stores/useGlobalStatusStore.js @@ -1,6 +1,8 @@ import { defineStore } from "pinia"; import { http } from "@/utils/axios"; +let authRefreshPromise = null; + const useGlobalStatusStore = defineStore("useGlobalStatusStore", { state() { return { @@ -27,33 +29,39 @@ const useGlobalStatusStore = defineStore("useGlobalStatusStore", { } }, actions: { - async refresh() { - if (this.authLoading) { - return this.isLogin; + refresh() { + if (authRefreshPromise) { + return authRefreshPromise; } this.authLoading = true; - try { - const response = await http.post("/api/v1/user/info", {}); - if (response.errorNo === 0 && response.data) { - this.setUser(response.data, false); - this.authChecked = true; - return true; + authRefreshPromise = (async () => { + try { + const response = await http.post("/api/v1/user/info", {}); + if (response.errorNo === 0 && response.data) { + this.setUser(response.data, false); + this.authChecked = true; + return true; + } + this.clear(); + return false; + } catch (error) { + this.clear(); + return false; + } finally { + this.authLoading = false; + authRefreshPromise = null; } - this.clear(); - return false; - } catch (error) { - this.clear(); - return false; - } finally { - this.authLoading = false; - } + })(); + + return authRefreshPromise; }, init(callback) { - this.refresh().then(() => { + return this.refresh().then((authenticated) => { if (typeof callback === "function") { - callback(); + callback(authenticated); } + return authenticated; }); }, clear() { diff --git a/fe/src/utils/axios.js b/fe/src/utils/axios.js index e92203c..5362b8d 100644 --- a/fe/src/utils/axios.js +++ b/fe/src/utils/axios.js @@ -63,7 +63,7 @@ http.interceptors.response.use(async (response) => { await router.replace({ path: '/login', query: { - redirect: router.currentRoute.fullPath + redirect: router.currentRoute.value.fullPath } }); } @@ -72,7 +72,7 @@ http.interceptors.response.use(async (response) => { await router.replace({ path: '/setup', query: { - redirect: router.currentRoute.fullPath + redirect: router.currentRoute.value.fullPath } }); } @@ -95,7 +95,7 @@ http.interceptors.response.use(async (response) => { await router.replace({ path: '/login', query: { - redirect: router.currentRoute.fullPath + redirect: router.currentRoute.value.fullPath } }); }