|
@@ -1,6 +1,8 @@
|
|
import axios from 'axios'
|
|
import axios from 'axios'
|
|
import { getToken, getUserId, getCodeToken } from '@/utils/auth'
|
|
import { getToken, getUserId, getCodeToken } from '@/utils/auth'
|
|
import { ElMessage } from 'element-plus'
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
+import { useUserStore } from '@/store/user'
|
|
|
|
+import router from '@/router'
|
|
let isMttoken
|
|
let isMttoken
|
|
// create an axios instance
|
|
// create an axios instance
|
|
const service = axios.create({
|
|
const service = axios.create({
|
|
@@ -16,7 +18,7 @@ const service = axios.create({
|
|
})
|
|
})
|
|
// request interceptor
|
|
// request interceptor
|
|
service.interceptors.request.use(
|
|
service.interceptors.request.use(
|
|
- (config) => {
|
|
|
|
|
|
+ (config: any) => {
|
|
// config.headers.common["content-type"] = "application/json"
|
|
// config.headers.common["content-type"] = "application/json"
|
|
if (config.istoken) {
|
|
if (config.istoken) {
|
|
config.headers['appSecret'] = PLATFROM_CONFIG.appKeyString
|
|
config.headers['appSecret'] = PLATFROM_CONFIG.appKeyString
|
|
@@ -31,9 +33,9 @@ service.interceptors.request.use(
|
|
if (getCodeToken() && !config.istoken) {
|
|
if (getCodeToken() && !config.istoken) {
|
|
config.headers['Authorization'] = getCodeToken()
|
|
config.headers['Authorization'] = getCodeToken()
|
|
}
|
|
}
|
|
- // if (store.getters.token) {
|
|
|
|
- // config.headers['Authorization'] = getToken()
|
|
|
|
- // }
|
|
|
|
|
|
+ if (useUserStore().token) {
|
|
|
|
+ config.headers['Authorization'] = getToken()
|
|
|
|
+ }
|
|
return config
|
|
return config
|
|
},
|
|
},
|
|
(error) => {
|
|
(error) => {
|
|
@@ -75,9 +77,9 @@ service.interceptors.response.use(
|
|
type: 'error',
|
|
type: 'error',
|
|
duration: 5 * 1000,
|
|
duration: 5 * 1000,
|
|
onClose: () => {
|
|
onClose: () => {
|
|
- // store.dispatch('user/resetToken').then(() => {
|
|
|
|
- // location.reload()
|
|
|
|
- // })
|
|
|
|
|
|
+ useUserStore().resetState()
|
|
|
|
+ router.push(`/login`)
|
|
|
|
+ location.reload()
|
|
},
|
|
},
|
|
})
|
|
})
|
|
}
|
|
}
|