|
@@ -1,10 +1,11 @@
|
|
|
-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
|
|
@@ -12,19 +13,15 @@ const service = axios.create({
|
|
|
})
|
|
|
|
|
|
const err = (error) => {
|
|
|
+ console.log(error.response.data.message, 'error')
|
|
|
if (error.response) {
|
|
|
- const data = error.response.data
|
|
|
- if ((error.response.status == 403 || error.response.status == 401) && window.location.pathname != '/user/login') {
|
|
|
+ const status = error.response.status
|
|
|
+ if ((status == 503 || status == 500) && window.location.pathname != '/user/login') {
|
|
|
notification.destroy()
|
|
|
notification.error({
|
|
|
message: '提示',
|
|
|
- description: data.message
|
|
|
+ description: error.response.data.message
|
|
|
})
|
|
|
- setTimeout(function () {
|
|
|
- store.dispatch('Logout').then(() => {
|
|
|
- window.location.reload()
|
|
|
- })
|
|
|
- }, 2000)
|
|
|
}
|
|
|
}
|
|
|
// 超时无法访问服务
|
|
@@ -32,47 +29,47 @@ const err = (error) => {
|
|
|
notification.destroy()
|
|
|
notification.error({
|
|
|
message: '提示',
|
|
|
- description: error.message
|
|
|
+ description: '请求超时'
|
|
|
})
|
|
|
- setTimeout(function () {
|
|
|
- store.dispatch('Logout').then(() => {
|
|
|
- window.location.reload()
|
|
|
- })
|
|
|
- }, 2000)
|
|
|
}
|
|
|
return Promise.reject(error)
|
|
|
}
|
|
|
|
|
|
// request interceptor
|
|
|
service.interceptors.request.use(config => {
|
|
|
- const token = Vue.ls.get(ACCESS_TOKEN)
|
|
|
+ const token = store.getters.token
|
|
|
+ config.headers['App-Type'] = 1 // 平台类型
|
|
|
if (token) {
|
|
|
- // config.headers['Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
|
+ config.headers['authorization'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
|
}
|
|
|
return config
|
|
|
}, err)
|
|
|
|
|
|
// response interceptor
|
|
|
service.interceptors.response.use((response) => {
|
|
|
- console.log(response, response.data.status, 'responseresponseresponse')
|
|
|
- if (window.location.pathname != '/user/login') {
|
|
|
- if (response.data.status == '900') {
|
|
|
- notification.destroy()
|
|
|
- notification.error({
|
|
|
- message: '提示',
|
|
|
- description: response.data.message
|
|
|
- })
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (response.data.status == '500') {
|
|
|
- notification.destroy()
|
|
|
- notification.error({
|
|
|
- message: '提示',
|
|
|
- description: response.data.message
|
|
|
- })
|
|
|
- }
|
|
|
+ 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()
|
|
|
+ notification.error({
|
|
|
+ message: '提示',
|
|
|
+ description: response.data.message
|
|
|
+ })
|
|
|
}
|
|
|
-
|
|
|
return response.data
|
|
|
}, err)
|
|
|
|