|
@@ -1,11 +1,10 @@
|
|
|
-// import Vue from 'vue'
|
|
|
+import Vue from 'vue'
|
|
|
import axios from 'axios'
|
|
|
import store from '@/store'
|
|
|
import notification from 'ant-design-vue/es/notification'
|
|
|
-import modal from 'ant-design-vue/es/modal'
|
|
|
import { VueAxios } from './axios'
|
|
|
-// import { ACCESS_TOKEN } from '@/store/mutation-types'
|
|
|
-// console.log(process.env.VUE_APP_PRO_NAME)
|
|
|
+import { ACCESS_TOKEN } from '@/store/mutation-types'
|
|
|
+console.log(process.env.VUE_APP_PRO_NAME)
|
|
|
// 创建 axios 实例
|
|
|
const service = axios.create({
|
|
|
baseURL: process.env.VUE_APP_API_BASE_URL, // api base_url
|
|
@@ -13,62 +12,57 @@ const service = axios.create({
|
|
|
})
|
|
|
|
|
|
const err = (error) => {
|
|
|
- console.log(error.response.data.message, 'error')
|
|
|
if (error.response) {
|
|
|
- const status = error.response.status
|
|
|
- if ((status == 503 || status == 500) && window.location.pathname != '/user/login') {
|
|
|
- notification.destroy()
|
|
|
+ const data = error.response.data
|
|
|
+ if ((error.response.status == 403 || error.response.status == 401) && window.location.pathname != '/user/login') {
|
|
|
notification.error({
|
|
|
message: '提示',
|
|
|
- description: error.response.data.message
|
|
|
+ description: data.message
|
|
|
})
|
|
|
+ setTimeout(function () {
|
|
|
+ store.dispatch('Logout').then(() => {
|
|
|
+ window.location.reload()
|
|
|
+ })
|
|
|
+ }, 2000)
|
|
|
}
|
|
|
}
|
|
|
// 超时无法访问服务
|
|
|
if (error.message.indexOf('timeout') >= 0 && window.location.pathname != '/user/login') {
|
|
|
- notification.destroy()
|
|
|
notification.error({
|
|
|
message: '提示',
|
|
|
- description: '请求超时'
|
|
|
+ description: error.message
|
|
|
})
|
|
|
+ setTimeout(function () {
|
|
|
+ store.dispatch('Logout').then(() => {
|
|
|
+ window.location.reload()
|
|
|
+ })
|
|
|
+ }, 2000)
|
|
|
}
|
|
|
return Promise.reject(error)
|
|
|
}
|
|
|
|
|
|
// request interceptor
|
|
|
service.interceptors.request.use(config => {
|
|
|
- const token = store.getters.token
|
|
|
- config.headers['App-Type'] = 9 // 平台类型
|
|
|
+ const token = Vue.ls.get(ACCESS_TOKEN)
|
|
|
if (token) {
|
|
|
- config.headers['authorization'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
|
+ // config.headers['Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
|
}
|
|
|
return config
|
|
|
}, err)
|
|
|
|
|
|
// response interceptor
|
|
|
service.interceptors.response.use((response) => {
|
|
|
- // console.log(response, 'response.data.status')
|
|
|
- const et = sessionStorage.getItem('errorTips')
|
|
|
- if (response.data.status == '1001' && !et) {
|
|
|
- sessionStorage.setItem('errorTips', 1)
|
|
|
- modal.destroyAll()
|
|
|
- modal.error({
|
|
|
- title: '提示',
|
|
|
- content: response.data.message,
|
|
|
- onOk () {
|
|
|
- sessionStorage.setItem('errorTips', 0)
|
|
|
- store.dispatch('Logout').then(() => {
|
|
|
- window.location.reload()
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- if ((response.data.status == '401' || response.data.status == '900' || response.data.status == '500') && window.location.pathname != '/user/login') {
|
|
|
- notification.destroy()
|
|
|
+ console.log(response, 'responseresponseresponse')
|
|
|
+ if (response.data.status == '-1') {
|
|
|
notification.error({
|
|
|
message: '提示',
|
|
|
description: response.data.message
|
|
|
})
|
|
|
+ setTimeout(function () {
|
|
|
+ store.dispatch('Logout').then(() => {
|
|
|
+ window.location.reload()
|
|
|
+ })
|
|
|
+ }, 2000)
|
|
|
}
|
|
|
return response.data
|
|
|
}, err)
|