|
|
@@ -1,7 +1,7 @@
|
|
|
import axios from 'axios'
|
|
|
-import { useUserStore } from '@/stores/user'
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
import { ACCESS_TOKEN } from '@/utils/constants'
|
|
|
+import { logout, getToken } from '@/utils/micro'
|
|
|
|
|
|
const request = axios.create({
|
|
|
baseURL: import.meta.env.VITE_BASE_API
|
|
|
@@ -11,7 +11,6 @@ const request = axios.create({
|
|
|
const errorHandler = (error: any) => {
|
|
|
const status = error.response.status
|
|
|
const data = error.response.data
|
|
|
- const userStore = useUserStore()
|
|
|
|
|
|
if (status === 400) {
|
|
|
ElMessage.error(data.msg)
|
|
|
@@ -22,7 +21,7 @@ const errorHandler = (error: any) => {
|
|
|
center: true,
|
|
|
confirmButtonText: '重新登录'
|
|
|
}).then(() => {
|
|
|
- userStore.logout()
|
|
|
+ logout()
|
|
|
})
|
|
|
} else if (status === 403) {
|
|
|
ElMessage.error('无权限访问')
|
|
|
@@ -36,8 +35,7 @@ const errorHandler = (error: any) => {
|
|
|
}
|
|
|
|
|
|
request.interceptors.request.use(config => {
|
|
|
- const userStore = useUserStore()
|
|
|
- const token = 'Bearer ' + userStore.token
|
|
|
+ const token = 'Bearer ' + getToken()
|
|
|
config.headers = config.headers || {}
|
|
|
|
|
|
if (token) {
|
|
|
@@ -53,8 +51,7 @@ request.interceptors.response.use(res => {
|
|
|
return data
|
|
|
} else {
|
|
|
if (data.code === 201 && data.msg === '登录超时,请登录') {
|
|
|
- const userStore = useUserStore()
|
|
|
- userStore.logout()
|
|
|
+ logout()
|
|
|
} else {
|
|
|
ElMessage.error(data.msg)
|
|
|
}
|