|
@@ -2,9 +2,9 @@ import Vue from 'vue'
|
|
|
import axios from 'axios'
|
|
|
import store from '@/store'
|
|
|
import {Plugin as VueAxios} from '@/plugins/axios'
|
|
|
-import {Modal, Notification} from 'element-ui'
|
|
|
+import {Modal, MessageBox ,Notification} from 'element-ui'
|
|
|
import {ACCESS_TOKEN} from "@/store/mutation-types"
|
|
|
-
|
|
|
+import router from 'vue-router'
|
|
|
// 创建 axios 实例
|
|
|
|
|
|
if (process.env.NODE_ENV == 'development') {
|
|
@@ -25,45 +25,44 @@ const service = axios.create({
|
|
|
|
|
|
|
|
|
const err = (error) => {
|
|
|
- if (error.esponse) {
|
|
|
+ if (error.response) {
|
|
|
let data = error.response.data
|
|
|
const token = Vue.ls.get(ACCESS_TOKEN)
|
|
|
console.log("------异常响应------", token)
|
|
|
console.log("------异常响应------", error.response.status)
|
|
|
switch (error.response.status) {
|
|
|
case 403:
|
|
|
- Notification.error({message: '系统提示', description: '拒绝访问', duration: 4})
|
|
|
+ Notification.error({title: '系统提示', message: '拒绝访问', duration: 4})
|
|
|
break
|
|
|
case 500:
|
|
|
//notification.error({ message: '系统提示', description:'Token失效,请重新登录!',duration: 4})
|
|
|
- if (token && data.message == "Token失效,请重新登录") {
|
|
|
+ if (token && data.code == -1) {
|
|
|
// update-begin- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
|
|
// store.dispatch('Logout').then(() => {
|
|
|
// window.location.reload()
|
|
|
// })
|
|
|
- Modal.error({
|
|
|
- title: '登录已过期',
|
|
|
- content: '很抱歉,登录已过期,请重新登录',
|
|
|
- okText: '重新登录',
|
|
|
- mask: false,
|
|
|
- onOk: () => {
|
|
|
- store.dispatch('Logout').then(() => {
|
|
|
- Vue.ls.remove(ACCESS_TOKEN)
|
|
|
+ // Notification.error({title: '登录已过期', message: '很抱歉,登录已过期,请重新登录', duration: 4})
|
|
|
+ if (token) {
|
|
|
+ store.dispatch('Logout').then(() => {
|
|
|
+ setTimeout(() => {
|
|
|
window.location.reload()
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ // router.replace('/login')
|
|
|
+ }, 1500)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ break
|
|
|
+
|
|
|
// update-end- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
|
|
}
|
|
|
break
|
|
|
case 404:
|
|
|
- Notification.error({message: '系统提示', description: '很抱歉,资源未找到!', duration: 4})
|
|
|
+ Notification.error({title: '系统提示', message: '很抱歉,资源未找到!', duration: 4})
|
|
|
break
|
|
|
case 504:
|
|
|
- Notification.error({message: '系统提示', description: '网络超时'})
|
|
|
+ Notification.error({title: '系统提示', message: '网络超时'})
|
|
|
break
|
|
|
case 401:
|
|
|
- Notification.error({message: '系统提示', description: '未授权,请重新登录', duration: 4})
|
|
|
+ Notification.error({title: '系统提示', message: '未授权,请重新登录', duration: 4})
|
|
|
if (token) {
|
|
|
store.dispatch('Logout').then(() => {
|
|
|
setTimeout(() => {
|
|
@@ -74,8 +73,8 @@ const err = (error) => {
|
|
|
break
|
|
|
default:
|
|
|
Notification.error({
|
|
|
- message: '系统提示',
|
|
|
- description: data.message,
|
|
|
+ title: '系统提示',
|
|
|
+ message: data.message,
|
|
|
duration: 4
|
|
|
})
|
|
|
break
|
|
@@ -109,10 +108,11 @@ service.interceptors.response.use((response) => {
|
|
|
return response.data
|
|
|
}, (error) => {
|
|
|
console.log(error)
|
|
|
- Notification.error({
|
|
|
- title: '系统提示',
|
|
|
- message: '网络超时,请刷新页面'
|
|
|
- })
|
|
|
+ err(error)
|
|
|
+ // Notification.error({
|
|
|
+ // title: '系统提示',
|
|
|
+ // message: '网络超时,请刷新页面'
|
|
|
+ // })
|
|
|
return
|
|
|
})
|
|
|
|