From d68ba1e9871b03ef7dad4c332a2430da3ba6c2a9 Mon Sep 17 00:00:00 2001 From: yueli Date: Thu, 23 Jul 2026 09:48:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A1=B5=E9=9D=A2=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E4=B8=BB=E5=8A=A8=E7=BB=AD=E6=9C=9F=20access=5Ftoken?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E8=BF=87=E6=9C=9F=20token=20?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=20401=20=E7=AB=9E=E6=80=81=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=9D=83=E9=99=90=E7=A9=BA=E7=99=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-web/src/App.vue | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/inventory-web/src/App.vue b/inventory-web/src/App.vue index e688e5b..7731ba3 100644 --- a/inventory-web/src/App.vue +++ b/inventory-web/src/App.vue @@ -16,11 +16,28 @@ const isLoginPage = computed(() => { }) // 页面加载时刷新权限 -onMounted(() => { +onMounted(async () => { if (userStore.token) { + // ★ 如果 access_token 可能已过期,先主动用 refresh_token 换新 token + // 避免后续 API 调用触发 401 → 刷新 → 重试的竞态导致权限空白 + try { + const refreshTokenValue = localStorage.getItem('refresh_token') + if (refreshTokenValue) { + const res = await fetch('/api/v1/auth/refresh', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ refresh_token: refreshTokenValue }) + }) + if (res.ok) { + const data = await res.json() + if (data.access_token) { + userStore.setToken(data.access_token) + } + } + } + } catch (e) { /* 静默,失败时走正常 401 刷新流程 */ } userStore.refreshUserPermissions() } - // 当 Vue 根组件挂载完毕,确保 Dify 图标一定会被加载 if (typeof (window as any).initDifyChatbot === 'function') { (window as any).initDifyChatbot() }