forked from qiushanhe/dm-manage-web
提交
This commit is contained in:
@@ -1,16 +1,32 @@
|
||||
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/ruoyi';
|
||||
import {
|
||||
tansParams,
|
||||
blobValidate
|
||||
} from '@/utils/ruoyi';
|
||||
import cache from '@/plugins/cache';
|
||||
import { saveAs } from 'file-saver';
|
||||
import { successCode } from '@/global/global';
|
||||
import {
|
||||
saveAs
|
||||
} from 'file-saver';
|
||||
import {
|
||||
successCode
|
||||
} from '@/global/global';
|
||||
|
||||
let downloadLoadingInstance;
|
||||
// 是否显示重新登录
|
||||
export const isRelogin = { show: false };
|
||||
export const isRelogin = {
|
||||
show: false
|
||||
};
|
||||
|
||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
|
||||
// 创建axios实例
|
||||
@@ -31,6 +47,11 @@ service.interceptors.request.use(
|
||||
if (getToken() && !isToken) {
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
}
|
||||
if (config.url.includes("http")) {
|
||||
config.baseURL = "";
|
||||
} else if (config.url.includes("amap")) {
|
||||
config.baseURL = "";
|
||||
}
|
||||
// get请求映射params参数
|
||||
if (config.method === 'get' && config.params) {
|
||||
let url = config.url + '?' + tansParams(config.params);
|
||||
@@ -84,10 +105,10 @@ service.interceptors.response.use(
|
||||
if (!isRelogin.show) {
|
||||
isRelogin.show = true;
|
||||
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
||||
confirmButtonText: '重新登录',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
confirmButtonText: '重新登录',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(() => {
|
||||
isRelogin.show = false;
|
||||
store.dispatch('LogOut').then(() => {
|
||||
@@ -116,7 +137,9 @@ service.interceptors.response.use(
|
||||
},
|
||||
(error) => {
|
||||
console.log('err' + error);
|
||||
let { message } = error;
|
||||
let {
|
||||
message
|
||||
} = error;
|
||||
if (message === 'Network Error') {
|
||||
message = '后端接口连接异常';
|
||||
} else if (message.includes('timeout')) {
|
||||
@@ -147,7 +170,9 @@ export function download(url, params, filename, config) {
|
||||
return tansParams(params);
|
||||
}
|
||||
],
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
responseType: 'blob',
|
||||
...config
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user