From 65e578ca585acfe6035b7cb881263dba11ce97ed Mon Sep 17 00:00:00 2001 From: zygalaxy Date: Fri, 5 Sep 2025 18:32:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(token):=20=E7=BB=9F=E4=B8=80=E5=AF=BC?= =?UTF-8?q?=E5=87=BAtoken=20store=E5=92=8C=E4=BF=AE=E5=A4=8Dtoken=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BB=A5=E5=8F=8A=E6=B7=BB=E5=8A=A0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/http/interceptor.ts | 7 ++++--- src/store/index.ts | 3 ++- src/store/token.ts | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/http/interceptor.ts b/src/http/interceptor.ts index 1c758a3..377302f 100644 --- a/src/http/interceptor.ts +++ b/src/http/interceptor.ts @@ -1,5 +1,5 @@ import type { CustomRequestOptions } from '@/http/types' -import { useUserStore } from '@/store' +import { useTokenStore } from '@/store' import { getEnvBaseUrl } from '@/utils' import { platform } from '@/utils/platform' import { stringifyQuery } from './tools/queryString' @@ -47,8 +47,9 @@ const httpInterceptor = { ...options.header, } // 3. 添加 token 请求头标识 - const userStore = useUserStore() - const { token } = userStore.userInfo as unknown as IUserToken + const tokenStore = useTokenStore() + const token = tokenStore.validToken + if (token) { options.header.Authorization = `Bearer ${token}` } diff --git a/src/store/index.ts b/src/store/index.ts index 0b98dbc..d5e3770 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -13,6 +13,7 @@ store.use( export default store -export * from './theme' // 模块统一导出 +export * from './theme' +export * from './token' export * from './user' diff --git a/src/store/token.ts b/src/store/token.ts index 6b36bca..73f0c5f 100644 --- a/src/store/token.ts +++ b/src/store/token.ts @@ -266,6 +266,7 @@ export const useTokenStore = defineStore( // 内部系统使用的方法 refreshToken, tryGetValidToken, + validToken: getValidToken, // 调试或特殊场景可能需要直接访问的信息 tokenInfo,