|
@@ -1,6 +1,16 @@
|
|
"use strict";
|
|
"use strict";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
import bus from "./bus.js";
|
|
import bus from "./bus.js";
|
|
|
|
+let store=null
|
|
|
|
+// 异步加载store模块 不异步加载的话,@/api/modules/oldApi.js的导入导出写法会有问题
|
|
|
|
+import('@/vuex/index.js')
|
|
|
|
+.then(module => {
|
|
|
|
+ store=module.default
|
|
|
|
+})
|
|
|
|
+.catch(err => {
|
|
|
|
+ console.error(err,'vuex加载错误');
|
|
|
|
+});
|
|
|
|
+
|
|
axios.defaults.withCredentials = true;
|
|
axios.defaults.withCredentials = true;
|
|
axios.defaults.timeout = 0;
|
|
axios.defaults.timeout = 0;
|
|
axios.interceptors.request.use(
|
|
axios.interceptors.request.use(
|
|
@@ -40,16 +50,29 @@ function getData(val, url) {
|
|
return val;
|
|
return val;
|
|
}
|
|
}
|
|
|
|
|
|
-function checkStatus(response) {
|
|
|
|
|
|
+function errorMsgShow(closableErrMsg,msg){
|
|
|
|
+ if(closableErrMsg){
|
|
|
|
+ let messageHint = bus.$message.error({
|
|
|
|
+ message:msg,
|
|
|
|
+ duration:0,
|
|
|
|
+ showClose:true
|
|
|
|
+ })
|
|
|
|
+ store.mutations.PUSH_CLOSABLE_HINT(store.state,messageHint)
|
|
|
|
+ }else{
|
|
|
|
+ bus.$message.error(msg);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function checkStatus(response,closableErrMsg) {
|
|
//处理响应数据
|
|
//处理响应数据
|
|
if (response && response.status === 200) {
|
|
if (response && response.status === 200) {
|
|
// loading,如果http状态码正常,则直接返回数据
|
|
// loading,如果http状态码正常,则直接返回数据
|
|
let res = bus.$parseData(response);
|
|
let res = bus.$parseData(response);
|
|
if (!res) {
|
|
if (!res) {
|
|
- bus.$message.error("服务器开了个小差");
|
|
|
|
|
|
+ errorMsgShow(closableErrMsg,'服务器开了个小差')
|
|
return false;
|
|
return false;
|
|
} else if (res.Ret == 403) {
|
|
} else if (res.Ret == 403) {
|
|
- bus.$message.error(res.Msg);
|
|
|
|
|
|
+ errorMsgShow(closableErrMsg,res.Msg)
|
|
} else if (res.Ret === 408) {
|
|
} else if (res.Ret === 408) {
|
|
localStorage.setItem("auth", "")
|
|
localStorage.setItem("auth", "")
|
|
localStorage.setItem("loginTime", "")
|
|
localStorage.setItem("loginTime", "")
|
|
@@ -63,14 +86,19 @@ function checkStatus(response) {
|
|
}
|
|
}
|
|
return res;
|
|
return res;
|
|
} else {
|
|
} else {
|
|
- bus.$message.error("网络异常");
|
|
|
|
|
|
+ errorMsgShow(closableErrMsg,'网络异常')
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-function checkCode(res) {
|
|
|
|
- bus.$message.error("网络异常");
|
|
|
|
|
|
+function checkCode(res,closableErrMsg) {
|
|
|
|
+ errorMsgShow(closableErrMsg,'网络异常')
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+function isFormData(obj) {
|
|
|
|
+ return typeof obj === 'object' && obj instanceof FormData;
|
|
|
|
+}
|
|
|
|
+
|
|
// 请求时间需要过长,取消限制
|
|
// 请求时间需要过长,取消限制
|
|
const cancelTimeoutUrlPost = ["/cloud_disk/resource/upload"];
|
|
const cancelTimeoutUrlPost = ["/cloud_disk/resource/upload"];
|
|
|
|
|
|
@@ -78,6 +106,16 @@ export default {
|
|
post(url, data) {
|
|
post(url, data) {
|
|
//post请求方式
|
|
//post请求方式
|
|
let timeout = cancelTimeoutUrlPost.includes(url) ? 0 : 600000;
|
|
let timeout = cancelTimeoutUrlPost.includes(url) ? 0 : 600000;
|
|
|
|
+ // 自定义参数
|
|
|
|
+ /**
|
|
|
|
+ * closableErrMsg123 -- 错误提示需要时可关闭类型的
|
|
|
|
+ */
|
|
|
|
+ let closableErrMsg=false
|
|
|
|
+ if(data){
|
|
|
|
+ // 区分formData格式
|
|
|
|
+ closableErrMsg = isFormData(data)?!!data.get('closableErrMsg123'):!!data.closableErrMsg123
|
|
|
|
+ isFormData(data)?data.delete('closableErrMsg123'):(data.closableErrMsg123=undefined)
|
|
|
|
+ }
|
|
return axios({
|
|
return axios({
|
|
method: "post",
|
|
method: "post",
|
|
url: url,
|
|
url: url,
|
|
@@ -87,13 +125,23 @@ export default {
|
|
headers: { "Content-Type": "application/json; charset=utf-8" },
|
|
headers: { "Content-Type": "application/json; charset=utf-8" },
|
|
})
|
|
})
|
|
.then((response) => {
|
|
.then((response) => {
|
|
- return checkStatus(response);
|
|
|
|
|
|
+ return checkStatus(response,closableErrMsg);
|
|
})
|
|
})
|
|
.catch((res) => {
|
|
.catch((res) => {
|
|
- return checkCode(res);
|
|
|
|
|
|
+ return checkCode(res,closableErrMsg);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
get(url, data, responseType = "json") {
|
|
get(url, data, responseType = "json") {
|
|
|
|
+ // 自定义参数
|
|
|
|
+ /**
|
|
|
|
+ * closableErrMsg123 -- 错误提示需要时可关闭类型的
|
|
|
|
+ */
|
|
|
|
+ let closableErrMsg=false
|
|
|
|
+ if(data){
|
|
|
|
+ closableErrMsg = !!data.closableErrMsg123
|
|
|
|
+ data.closableErrMsg123=undefined
|
|
|
|
+ }
|
|
|
|
+
|
|
//get请求方式
|
|
//get请求方式
|
|
return axios({
|
|
return axios({
|
|
method: "get",
|
|
method: "get",
|
|
@@ -120,10 +168,10 @@ export default {
|
|
if(responseType==='blob'){
|
|
if(responseType==='blob'){
|
|
return response
|
|
return response
|
|
}
|
|
}
|
|
- return checkStatus(response);
|
|
|
|
|
|
+ return checkStatus(response,closableErrMsg);
|
|
})
|
|
})
|
|
.catch((res) => {
|
|
.catch((res) => {
|
|
- return checkCode(res);
|
|
|
|
|
|
+ return checkCode(res,closableErrMsg);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
Base64,
|
|
Base64,
|