|
@@ -1,6 +1,7 @@
|
|
import Vue from "vue";
|
|
import Vue from "vue";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
import router from "../router";
|
|
import router from "../router";
|
|
|
|
+import { loadProgressBar } from "axios-progress-bar";
|
|
|
|
|
|
const ERROR_MSG_CONFIG = require("./errorMsgConfig").default;
|
|
const ERROR_MSG_CONFIG = require("./errorMsgConfig").default;
|
|
|
|
|
|
@@ -15,8 +16,8 @@ let config = {
|
|
withCredentials: true // Check cross-site Access-Control
|
|
withCredentials: true // Check cross-site Access-Control
|
|
};
|
|
};
|
|
|
|
|
|
-const _axios = axios.create(config);
|
|
|
|
-const _axiosWithoutResponseInterceptors = axios.create(config);
|
|
|
|
|
|
+const _$httpWith500Msg = axios.create(config);
|
|
|
|
+const _$http = axios.create(config); // no auto 500 error UI
|
|
|
|
|
|
/**
|
|
/**
|
|
* A. token lifecycle
|
|
* A. token lifecycle
|
|
@@ -29,7 +30,15 @@ const _axiosWithoutResponseInterceptors = axios.create(config);
|
|
let wk_token, wk_key;
|
|
let wk_token, wk_key;
|
|
let wk_orgId;
|
|
let wk_orgId;
|
|
|
|
|
|
-_axios.interceptors.request.use(
|
|
|
|
|
|
+function getRootOrgId() {
|
|
|
|
+ if (location.hostname.includes("qmth.com.cn")) {
|
|
|
|
+ return "";
|
|
|
|
+ } else {
|
|
|
|
+ return "?orgId=" + (wk_orgId === undefined ? "" : wk_orgId);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+_$httpWith500Msg.interceptors.request.use(
|
|
function(config) {
|
|
function(config) {
|
|
// Do something before request is sent
|
|
// Do something before request is sent
|
|
if (
|
|
if (
|
|
@@ -47,7 +56,7 @@ _axios.interceptors.request.use(
|
|
// } else {
|
|
// } else {
|
|
// router.push("/login");
|
|
// router.push("/login");
|
|
// }
|
|
// }
|
|
- router.push("/login/" + "?orgId=" + wk_orgId);
|
|
|
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return;
|
|
return;
|
|
@@ -76,7 +85,8 @@ _axios.interceptors.request.use(
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
|
|
-_axiosWithoutResponseInterceptors.interceptors.request.use(
|
|
|
|
|
|
+_$http.interceptors.request.use(
|
|
|
|
+ // no auto 500 error UI
|
|
function(config) {
|
|
function(config) {
|
|
// Do something before request is sent
|
|
// Do something before request is sent
|
|
if (config.url.includes("/login") === false) {
|
|
if (config.url.includes("/login") === false) {
|
|
@@ -86,7 +96,7 @@ _axiosWithoutResponseInterceptors.interceptors.request.use(
|
|
Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
confirmButtonText: "确定",
|
|
confirmButtonText: "确定",
|
|
callback: () => {
|
|
callback: () => {
|
|
- router.push("/login/" + "?orgId=" + wk_orgId);
|
|
|
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return;
|
|
return;
|
|
@@ -116,8 +126,14 @@ _axiosWithoutResponseInterceptors.interceptors.request.use(
|
|
);
|
|
);
|
|
|
|
|
|
// Add a response interceptor
|
|
// Add a response interceptor
|
|
-_axios.interceptors.response.use(
|
|
|
|
|
|
+_$httpWith500Msg.interceptors.response.use(
|
|
response => {
|
|
response => {
|
|
|
|
+ window._hmt.push([
|
|
|
|
+ "_trackEvent",
|
|
|
|
+ `页面-${location.pathname}`,
|
|
|
|
+ "网络请求-响应",
|
|
|
|
+ new URL(response.config.url, "http://www.qmth.com.cn").pathname
|
|
|
|
+ ]);
|
|
return response;
|
|
return response;
|
|
},
|
|
},
|
|
error => {
|
|
error => {
|
|
@@ -140,7 +156,7 @@ _axios.interceptors.response.use(
|
|
Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
confirmButtonText: "确定",
|
|
confirmButtonText: "确定",
|
|
callback: () => {
|
|
callback: () => {
|
|
- router.push("/login/" + "?orgId=" + wk_orgId);
|
|
|
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
@@ -148,7 +164,7 @@ _axios.interceptors.response.use(
|
|
Vue.prototype.$alert("没有权限!", "提示", {
|
|
Vue.prototype.$alert("没有权限!", "提示", {
|
|
confirmButtonText: "确定",
|
|
confirmButtonText: "确定",
|
|
callback: () => {
|
|
callback: () => {
|
|
- router.push("/login/" + "?orgId=" + wk_orgId);
|
|
|
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
@@ -191,8 +207,15 @@ _axios.interceptors.response.use(
|
|
);
|
|
);
|
|
|
|
|
|
// Add a response interceptor
|
|
// Add a response interceptor
|
|
-_axiosWithoutResponseInterceptors.interceptors.response.use(
|
|
|
|
|
|
+_$http.interceptors.response.use(
|
|
|
|
+ // no auto 500 error UI
|
|
response => {
|
|
response => {
|
|
|
|
+ window._hmt.push([
|
|
|
|
+ "_trackEvent",
|
|
|
|
+ `页面-${location.pathname}`,
|
|
|
|
+ "网络请求-响应",
|
|
|
|
+ new URL(response.config.url, "http://www.qmth.com.cn").pathname
|
|
|
|
+ ]);
|
|
return response;
|
|
return response;
|
|
},
|
|
},
|
|
error => {
|
|
error => {
|
|
@@ -212,7 +235,7 @@ _axiosWithoutResponseInterceptors.interceptors.response.use(
|
|
Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
confirmButtonText: "确定",
|
|
confirmButtonText: "确定",
|
|
callback: () => {
|
|
callback: () => {
|
|
- router.push("/login/" + "?orgId=" + wk_orgId);
|
|
|
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
@@ -220,7 +243,7 @@ _axiosWithoutResponseInterceptors.interceptors.response.use(
|
|
Vue.prototype.$alert("没有权限!", "提示", {
|
|
Vue.prototype.$alert("没有权限!", "提示", {
|
|
confirmButtonText: "确定",
|
|
confirmButtonText: "确定",
|
|
callback: () => {
|
|
callback: () => {
|
|
- router.push("/login/" + "?orgId=" + wk_orgId);
|
|
|
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
@@ -238,19 +261,33 @@ _axiosWithoutResponseInterceptors.interceptors.response.use(
|
|
);
|
|
);
|
|
|
|
|
|
Plugin.install = function(Vue) {
|
|
Plugin.install = function(Vue) {
|
|
- Vue.$http = _axiosWithoutResponseInterceptors;
|
|
|
|
|
|
+ Vue.$http = _$http; // no auto 500 error UI
|
|
Object.defineProperties(Vue.prototype, {
|
|
Object.defineProperties(Vue.prototype, {
|
|
$http: {
|
|
$http: {
|
|
get() {
|
|
get() {
|
|
- return _axiosWithoutResponseInterceptors;
|
|
|
|
|
|
+ return _$http; // no auto 500 error UI
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- Vue.$httpWithMsg = _axios;
|
|
|
|
|
|
+
|
|
|
|
+ Vue.$httpWithMsg = _$httpWith500Msg;
|
|
Object.defineProperties(Vue.prototype, {
|
|
Object.defineProperties(Vue.prototype, {
|
|
$httpWithMsg: {
|
|
$httpWithMsg: {
|
|
get() {
|
|
get() {
|
|
- return _axios;
|
|
|
|
|
|
+ return _$httpWith500Msg;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // for below request
|
|
|
|
+ // config.url.includes("/api/ecs_ques/paper/") === false &&
|
|
|
|
+ // config.url.includes("/api/ecs_ques/questionAudio") === false
|
|
|
|
+ const _a = axios.create(config);
|
|
|
|
+ Vue.$httpWithoutAuth = _a;
|
|
|
|
+ Object.defineProperties(Vue.prototype, {
|
|
|
|
+ $httpWithoutAuth: {
|
|
|
|
+ get() {
|
|
|
|
+ return _a;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -258,4 +295,9 @@ Plugin.install = function(Vue) {
|
|
|
|
|
|
Vue.use(Plugin);
|
|
Vue.use(Plugin);
|
|
|
|
|
|
|
|
+loadProgressBar({}, Vue.$http);
|
|
|
|
+loadProgressBar({}, Vue.$httpWithMsg);
|
|
|
|
+loadProgressBar({}, Vue.$httpWithoutAuth);
|
|
|
|
+
|
|
|
|
+import "axios-progress-bar/dist/nprogress.css";
|
|
export default Plugin;
|
|
export default Plugin;
|