|
@@ -1,12 +1,12 @@
|
|
|
-import axios from "axios"; //引入axios
|
|
|
-import sysConfig from '@/config' //引入配置文件
|
|
|
+import axios from "axios"; //引入axios
|
|
|
+import sysConfig from '@/config' //引入配置文件
|
|
|
import store from "../store/index"
|
|
|
import qs from "qs"
|
|
|
|
|
|
// console.log(process.env.NODE_ENV)
|
|
|
|
|
|
-axios.defaults.baseURL = sysConfig.baseURL //设置请求时间
|
|
|
-axios.defaults.timeout = sysConfig.timeout //设置请求超时时间
|
|
|
+axios.defaults.baseURL = sysConfig.baseUrl //设置请求时间
|
|
|
+axios.defaults.timeout = sysConfig.timeout //设置请求超时时间
|
|
|
const ContentType = sysConfig.ContentType
|
|
|
|
|
|
//axios.defaults.headers["Content-Type"] = "application/json";
|
|
@@ -19,7 +19,7 @@ axios.defaults.headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
|
/** 请求发送前拦截,用于配置求情内容,如headers参数等 */
|
|
|
axios.interceptors.request.use(
|
|
|
(config) => {
|
|
|
- config.headers.token=window.localStorage.getItem('MZ_TOKEN');
|
|
|
+ config.headers.token = window.localStorage.getItem('MZ_TOKEN');
|
|
|
return config
|
|
|
},
|
|
|
(error) => {
|
|
@@ -27,34 +27,34 @@ axios.interceptors.request.use(
|
|
|
}
|
|
|
)
|
|
|
|
|
|
-function error1(res){
|
|
|
- if (res.status == 408 || res.status == 401) {// 需要重新登录
|
|
|
- store.commit('setPcToken',"");
|
|
|
- console.log(res.data);
|
|
|
+function error1(res) {
|
|
|
+ if (res.status == 408 || res.status == 401) { // 需要重新登录
|
|
|
+ store.commit('setPcToken', "");
|
|
|
+ console.log(res.data);
|
|
|
// window.xm.showToast({
|
|
|
// message:res.data
|
|
|
// })
|
|
|
- }else if(res.status === 404){
|
|
|
- console.log("404,路径找不到:"+res.data.path);
|
|
|
+ } else if (res.status === 404) {
|
|
|
+ console.log("404,路径找不到:" + res.data.path);
|
|
|
// window.xm.showToast({
|
|
|
// message:"404,路径找不到:"+res.data.path
|
|
|
// })
|
|
|
- }else if(res.status === 503){
|
|
|
+ } else if (res.status === 503) {
|
|
|
console.log("服务不可用");
|
|
|
// window.xm.showToast({
|
|
|
// message:"服务不可用"
|
|
|
// })
|
|
|
- }else if(res.status === 504){
|
|
|
+ } else if (res.status === 504) {
|
|
|
console.log("网络连接错误");
|
|
|
// window.xm.showToast({
|
|
|
// message:"网络连接错误"
|
|
|
// })
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
console.log(res.data);
|
|
|
// window.xm.showToast({
|
|
|
// message:res.data
|
|
|
// })
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** 请求发送后返回拦截,用于处理数据格式等 */
|
|
@@ -63,11 +63,11 @@ axios.interceptors.response.use(
|
|
|
return response
|
|
|
},
|
|
|
(error) => {
|
|
|
- if(error.request){
|
|
|
- error1(error.request);
|
|
|
- } else if(error.response){
|
|
|
+ if (error.request) {
|
|
|
+ error1(error.request);
|
|
|
+ } else if (error.response) {
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
return error
|
|
|
}
|
|
|
)
|
|
@@ -84,13 +84,13 @@ var http = {
|
|
|
* @param {*} config 请求的config相关配置
|
|
|
* @returns
|
|
|
*/
|
|
|
- get: function (url, params = {}, config = {}) {
|
|
|
+ get: function(url, params = {}, config = {}) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
axios({
|
|
|
- url: url+"?"+params,
|
|
|
+ url: url,
|
|
|
method: 'get',
|
|
|
- //params: qs.stringify(params),
|
|
|
- //params: params,
|
|
|
+ params: params,
|
|
|
+ // params: params,
|
|
|
config: config
|
|
|
}).then((response) => {
|
|
|
resolve(response.data)
|
|
@@ -109,7 +109,7 @@ var http = {
|
|
|
* @param {*} config 请求的config相关配置
|
|
|
* @returns
|
|
|
*/
|
|
|
- post: function (url, data = {}, params = {}, config = {}) {
|
|
|
+ post: function(url, data = {}, params = {}, config = {}) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
axios({
|
|
|
url: url,
|
|
@@ -119,11 +119,11 @@ var http = {
|
|
|
//params: qs.stringify(params),
|
|
|
config: config
|
|
|
}).then((response) => {
|
|
|
- //if(response.data && response.data.statusCode !== 200){
|
|
|
- // error(response.data);
|
|
|
- // reject(response.data)
|
|
|
- // }
|
|
|
- // resolve(response.data);
|
|
|
+ //if(response.data && response.data.statusCode !== 200){
|
|
|
+ // error(response.data);
|
|
|
+ // reject(response.data)
|
|
|
+ // }
|
|
|
+ // resolve(response.data);
|
|
|
|
|
|
resolve(response);
|
|
|
}).catch((error) => {
|
|
@@ -133,5 +133,4 @@ var http = {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export default http;
|
|
|
-
|
|
|
+export default http;
|