添加退出登录

This commit is contained in:
李志鹏
2025-10-27 14:02:26 +08:00
parent 7807f12367
commit 5c5766f4c4
3 changed files with 31 additions and 9 deletions

View File

@@ -1,10 +1,8 @@
import axios from 'axios'
import { showToast, showNotify, showConfirmDialog, closeToast } from 'vant'
import { useUserInfoStore } from '@/stores/modules/userInfo'
const store = useUserInfoStore()
import { getLocal } from '@/utils/local'
import router from '@/router/index'
import { useOverallStore, useGenerateStore } from '@/stores'
import { useOverallStore, useGenerateStore, useUserInfoStore } from '@/stores'
// 扩展 AxiosRequestConfig 接口
declare module 'axios' {
@@ -47,8 +45,9 @@ service.interceptors.request.use(
}
// 如果登录了有token则请求携带token
// Do something before request is sent
if (store.state.token) {
config.headers.Authorization = getLocal('token') // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改
const token = useUserInfoStore().state.token
if (token) {
config.headers.Authorization = token // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改
// config.headers['X-Token'] = getLocal('token') // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改
}
return config