55 lines
1.5 KiB
Plaintext
55 lines
1.5 KiB
Plaintext
import axios from 'axios';
|
||
import qs from 'qs';
|
||
import { Message } from 'element-ui'
|
||
|
||
|
||
|
||
//axios.defaults.baseURL = process.env.NODE_ENV=='development'?'':'http://new713.imwork.net/ecp/';
|
||
const wsAxios = axios.create({
|
||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||
// baseURL: process.env.VUE_APP_BASE_API,
|
||
baseURL: '/ws',
|
||
// 超时
|
||
timeout: 10000
|
||
})
|
||
// 添加请求拦截器
|
||
wsAxios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
||
wsAxios.interceptors.request.use(function(config) {
|
||
// console.log("请求拦截器::::",config)
|
||
// console.log("pcp",config)
|
||
if (config.data&&config.data.paramsType) {
|
||
config.data.paramsType=undefined;
|
||
config.headers['Content-Type'] = 'application/json';
|
||
return config;
|
||
}else{
|
||
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||
}
|
||
// 在发送请求之前做些什么
|
||
config.data = qs.stringify(config.data);//序列化参数
|
||
// console.log(".../",config)
|
||
return config;
|
||
}, function(error) {
|
||
// 对请求错误做些什么
|
||
return Promise.reject(error);
|
||
});
|
||
|
||
// 添加响应拦截器
|
||
wsAxios.interceptors.response.use(function(response) {
|
||
if(response.data.type==="application/force-download"){
|
||
return response;
|
||
}
|
||
if(response.data.type==="application/octet-stream"){
|
||
return response;
|
||
}
|
||
if (response.data.code!='200'){
|
||
Message.error(response.data.message)
|
||
}
|
||
return response;
|
||
}, function(error) {
|
||
// 对响应错误做点什么
|
||
return Promise.reject(error);
|
||
});
|
||
|
||
|
||
export default wsAxios;
|