diff --git a/src/api/axios.ts b/src/api/axios.ts index 2b9f1aec..d20a89c0 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -23,10 +23,11 @@ axiosInstance.interceptors.request.use( if (!info) { routerTurnByName(PageEnum.BASE_LOGIN_NAME) return config - } + } + const userInfo = info[SystemStoreEnum.USER_INFO] config.headers = { ...config.headers, - [RequestHttpHeaderEnum.TOKEN]: info[SystemStoreEnum.USER_INFO][SystemStoreUserInfoEnum.USER_TOKEN] || '' + [userInfo[SystemStoreUserInfoEnum.TOKEN_NAME]]: userInfo[SystemStoreUserInfoEnum.USER_TOKEN] || '' } return config }, diff --git a/src/store/modules/systemStore/systemStore.d.ts b/src/store/modules/systemStore/systemStore.d.ts index 77f5c348..b1c01584 100644 --- a/src/store/modules/systemStore/systemStore.d.ts +++ b/src/store/modules/systemStore/systemStore.d.ts @@ -1,5 +1,6 @@ export enum SystemStoreUserInfoEnum { USER_TOKEN = 'userToken', + TOKEN_NAME = 'tokenName', USER_ID = 'userId', USER_NAME = 'userName', NICK_NAME = 'nickName', @@ -7,6 +8,7 @@ export enum SystemStoreUserInfoEnum { export interface UserInfoType { [SystemStoreUserInfoEnum.USER_TOKEN]?: string, + [SystemStoreUserInfoEnum.TOKEN_NAME]?: string, [SystemStoreUserInfoEnum.USER_ID]?: string, [SystemStoreUserInfoEnum.USER_NAME]?: string, [SystemStoreUserInfoEnum.NICK_NAME]?: string, diff --git a/src/views/login/index.vue b/src/views/login/index.vue index eaf1ab08..c45161ea 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -119,7 +119,7 @@ import { reactive, ref, onMounted } from 'vue' import shuffle from 'lodash/shuffle' import { carouselInterval } from '@/settings/designSetting' import { useSystemStore } from '@/store/modules/systemStore/systemStore' -import { SystemStoreEnum } from '@/store/modules/systemStore/systemStore.d' +import { SystemStoreUserInfoEnum, SystemStoreEnum } from '@/store/modules/systemStore/systemStore.d' import { GoThemeSelect } from '@/components/GoThemeSelect' import { GoLangSelect } from '@/components/GoLangSelect' import { LayoutHeader } from '@/layout/components/LayoutHeader' @@ -209,15 +209,17 @@ const handleSubmit = async (e: Event) => { password }) as unknown as MyResponseType if(res.data) { - const { tokenValue } = res.data.token + const { tokenValue, tokenName } = res.data.token const { nickname, username, id } = res.data.userinfo // 存储到 pinia systemStore.setItem(SystemStoreEnum.USER_INFO, { - userToken: tokenValue, - userId: id, - userName: username, - nickName: nickname, + [SystemStoreUserInfoEnum.USER_TOKEN]: tokenValue, + [SystemStoreUserInfoEnum.TOKEN_NAME]: tokenName, + [SystemStoreUserInfoEnum.USER_ID]: id, + [SystemStoreUserInfoEnum.USER_NAME]: username, + [SystemStoreUserInfoEnum.NICK_NAME]: nickname, + t }) window['$message'].success(t('login.login_success'))