|
@@ -1,15 +1,15 @@
|
|
|
import axios from 'axios'
|
|
|
-import { Notification, MessageBox, Message, Loading } from 'element-ui'
|
|
|
+import {Notification, MessageBox, Message, Loading} from 'element-ui'
|
|
|
import store from '@/store'
|
|
|
-import { getToken } from '@/utils/auth'
|
|
|
+import {getToken} from '@/utils/auth'
|
|
|
import errorCode from '@/utils/errorCode'
|
|
|
-import { tansParams, blobValidate } from "@/utils/zkqy";
|
|
|
+import {tansParams, blobValidate} from "@/utils/zkqy";
|
|
|
import cache from '@/plugins/cache'
|
|
|
-import { saveAs } from 'file-saver'
|
|
|
+import {saveAs} from 'file-saver'
|
|
|
|
|
|
let downloadLoadingInstance;
|
|
|
// 是否显示重新登录
|
|
|
-export let isRelogin = { show: false };
|
|
|
+export let isRelogin = {show: false};
|
|
|
|
|
|
|
|
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
|
@@ -68,71 +68,73 @@ service.interceptors.request.use(config => {
|
|
|
|
|
|
// 响应拦截器
|
|
|
service.interceptors.response.use(res => {
|
|
|
- // 未设置状态码则默认成功状态
|
|
|
- const code = res.data.code || 200;
|
|
|
- // 获取错误信息
|
|
|
- const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
- // 二进制数据则直接返回
|
|
|
- if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
|
- return res.data
|
|
|
- }
|
|
|
- if (code === 401) {
|
|
|
- if (!isRelogin.show) {
|
|
|
- isRelogin.show = true;
|
|
|
- MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
+ // 未设置状态码则默认成功状态
|
|
|
+ const code = res.data.code || 200;
|
|
|
+ // 获取错误信息
|
|
|
+ const msg = errorCode[code] || res.data.msg || errorCode['default']
|
|
|
+ // 二进制数据则直接返回
|
|
|
+ if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
|
|
+ return res.data
|
|
|
+ }
|
|
|
+ if (code === 401) {
|
|
|
+ if (!isRelogin.show) {
|
|
|
+ isRelogin.show = true;
|
|
|
+ MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
+ confirmButtonText: '重新登录',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ isRelogin.show = false;
|
|
|
+ store.dispatch('LogOut')
|
|
|
+ // .then(() => {
|
|
|
+ // location.href = '/index';
|
|
|
+ // })
|
|
|
+ }).catch(() => {
|
|
|
+ isRelogin.show = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
+ } else if (code === 500) {
|
|
|
+ console.log(msg);
|
|
|
+ let resUrl = res.config.url;
|
|
|
+ if (resUrl == '/login') {
|
|
|
+ Message({message: msg, type: 'error'})
|
|
|
+ return Promise.reject(new Error(msg))
|
|
|
+ } else {
|
|
|
+ return Promise.resolve()
|
|
|
+ }
|
|
|
+ // Message({ message: msg, type: 'error' })
|
|
|
+ // return Promise.reject(new Error(msg))
|
|
|
+ // return Promise.resolve()
|
|
|
+ } else if (code === 601) {
|
|
|
+ Message({message: msg, type: 'warning'})
|
|
|
+ return Promise.reject('error')
|
|
|
+ } else if (code == 602) {
|
|
|
+ if (store.state.user.name == 'admin') return
|
|
|
+ MessageBox.confirm('数据源信息异常!请您联系管理员或尝试重新登录系统。', '系统提示', {
|
|
|
confirmButtonText: '重新登录',
|
|
|
cancelButtonText: '取消',
|
|
|
type: 'warning'
|
|
|
}).then(() => {
|
|
|
isRelogin.show = false;
|
|
|
- store.dispatch('LogOut').then(() => {
|
|
|
- location.href = '/index';
|
|
|
- })
|
|
|
+ store.dispatch('LogOut');
|
|
|
+ // .then(() => {
|
|
|
+ // location.href = '/index';
|
|
|
+ // })
|
|
|
}).catch(() => {
|
|
|
isRelogin.show = false;
|
|
|
});
|
|
|
- }
|
|
|
- return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
|
|
- } else if (code === 500) {
|
|
|
- console.log(msg);
|
|
|
- let resUrl = res.config.url;
|
|
|
- if (resUrl == '/login') {
|
|
|
- Message({ message: msg, type: 'error' })
|
|
|
- return Promise.reject(new Error(msg))
|
|
|
+ return Promise.reject('数据源信息异常!请您联系管理员或尝试重新登录系统。')
|
|
|
+ } else if (code !== 200) {
|
|
|
+ Notification.error({title: msg})
|
|
|
+ return Promise.reject('error')
|
|
|
} else {
|
|
|
- return Promise.resolve()
|
|
|
+ return res.data
|
|
|
}
|
|
|
- // Message({ message: msg, type: 'error' })
|
|
|
- // return Promise.reject(new Error(msg))
|
|
|
- // return Promise.resolve()
|
|
|
- } else if (code === 601) {
|
|
|
- Message({ message: msg, type: 'warning' })
|
|
|
- return Promise.reject('error')
|
|
|
- } else if (code == 602) {
|
|
|
- if (store.state.user.name == 'admin') return
|
|
|
- MessageBox.confirm('数据源信息异常!请您联系管理员或尝试重新登录系统。', '系统提示', {
|
|
|
- confirmButtonText: '重新登录',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning'
|
|
|
- }).then(() => {
|
|
|
- isRelogin.show = false;
|
|
|
- store.dispatch('LogOut').then(() => {
|
|
|
- location.href = '/index';
|
|
|
- })
|
|
|
- }).catch(() => {
|
|
|
- isRelogin.show = false;
|
|
|
- });
|
|
|
- return Promise.reject('数据源信息异常!请您联系管理员或尝试重新登录系统。')
|
|
|
- } else if (code !== 200) {
|
|
|
- Notification.error({ title: msg })
|
|
|
- return Promise.reject('error')
|
|
|
- } else {
|
|
|
- return res.data
|
|
|
- }
|
|
|
-},
|
|
|
+ },
|
|
|
error => {
|
|
|
console.log('err' + error)
|
|
|
- let { message } = error;
|
|
|
+ let {message} = error;
|
|
|
if (message == "Network Error") {
|
|
|
message = "后端接口连接异常";
|
|
|
} else if (message.includes("timeout")) {
|
|
@@ -140,7 +142,7 @@ service.interceptors.response.use(res => {
|
|
|
} else if (message.includes("Request failed with status code")) {
|
|
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
|
|
}
|
|
|
- Message({ message: message, type: 'error', duration: 5 * 1000 })
|
|
|
+ Message({message: message, type: 'error', duration: 5 * 1000})
|
|
|
return Promise.reject(error)
|
|
|
}
|
|
|
)
|
|
@@ -156,7 +158,7 @@ export function download(url, params, filename, config) {
|
|
|
transformRequest: [(params) => {
|
|
|
return tansParams(params)
|
|
|
}],
|
|
|
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
+ headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
|
|
responseType: 'blob',
|
|
|
...config
|
|
|
}).then(async (data) => {
|