diff --git a/src/stores/modules/user.ts b/src/stores/modules/user.ts index 2177c24..cab57b5 100644 --- a/src/stores/modules/user.ts +++ b/src/stores/modules/user.ts @@ -1,8 +1,5 @@ import { defineStore } from 'pinia' import type { UserState } from './types' -import { resetRouter } from '@/router' -import api from '@/api' -const { apiGetUserRoleInfo, apiLogout } = api.login import menuList from '@/config/menuList.ts' const useUserStore = defineStore('user', { @@ -52,9 +49,9 @@ const useUserStore = defineStore('user', { // 退出登录 onLogout() { return new Promise((resolve) => { - apiLogout.get!().then(() => { + api.login.apiLogout.get!().then(() => { this.RESET_STATE() - resetRouter() + window.location.href = '/login' resolve(null) }) }) diff --git a/src/utils/request.ts b/src/utils/request.ts index 5e4c689..dfaedeb 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -4,7 +4,7 @@ import axios, { type AxiosResponse } from 'axios' import { ElMessage, ElMessageBox } from 'element-plus' -import useStore from '@/stores' +import useUserStore from '@/stores/modules/user' // 创建 axios 实例 const service = axios.create({ @@ -43,8 +43,8 @@ service.interceptors.request.use( config.params = {} config.url = url } - const { user } = useStore() - user.tokenValue && (config.headers[user.tokenName] = user.tokenValue) + const userStore = useUserStore() + userStore.tokenValue && (config.headers[userStore.tokenName] = userStore.tokenValue) return config }, (error: any) => {