|
@@ -19,6 +19,7 @@ let config = {
|
|
|
|
|
|
const _$httpWith500Msg = axios.create(config);
|
|
|
const _$http = axios.create(config); // no auto 500 error UI
|
|
|
+const _$httpWithoutBar = axios.create(config);
|
|
|
|
|
|
/**
|
|
|
* A. token lifecycle
|
|
@@ -299,6 +300,106 @@ _$http.interceptors.response.use(
|
|
|
}
|
|
|
);
|
|
|
|
|
|
+_$httpWithoutBar.interceptors.request.use(
|
|
|
+ // no auto 500 error UI
|
|
|
+ function(config) {
|
|
|
+ networkInformationHint();
|
|
|
+ // Do something before request is sent
|
|
|
+ if (config.url.includes("/login") === false) {
|
|
|
+ if (!wk_token) {
|
|
|
+ const user = JSON.parse(window.sessionStorage.getItem("user"));
|
|
|
+ if (!user) {
|
|
|
+ if (
|
|
|
+ window.___lastInvalidDate === undefined ||
|
|
|
+ window.___lastInvalidDate < Date.now() - 300
|
|
|
+ ) {
|
|
|
+ Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ callback: () => {
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ window.___lastInvalidDate = Date.now();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ wk_token = user.token;
|
|
|
+ wk_key = user.key;
|
|
|
+ wk_orgId = user.rootOrgId;
|
|
|
+ }
|
|
|
+ if (wk_token && config.headers.common["token"] == null) {
|
|
|
+ config.headers.common["token"] = wk_token;
|
|
|
+ config.headers.common["key"] = wk_key;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ wk_token = null;
|
|
|
+ }
|
|
|
+ return config;
|
|
|
+ },
|
|
|
+ function(error) {
|
|
|
+ // Do something with request error
|
|
|
+ Vue.prototype.$notify({
|
|
|
+ showClose: true,
|
|
|
+ message: error,
|
|
|
+ type: "error"
|
|
|
+ });
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
+);
|
|
|
+_$httpWithoutBar.interceptors.response.use(
|
|
|
+ // no auto 500 error UI
|
|
|
+ response => {
|
|
|
+ recordRequest(response);
|
|
|
+ return response;
|
|
|
+ },
|
|
|
+ error => {
|
|
|
+ if (!error.response) {
|
|
|
+ Vue.prototype.$notify({
|
|
|
+ showClose: true,
|
|
|
+ message: "网络连接异常,请检查网络设置。",
|
|
|
+ type: "error"
|
|
|
+ });
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
+ // 这里是返回状态码不为200时候的错误处理
|
|
|
+ let status = error.response.status;
|
|
|
+
|
|
|
+ // 登录失效 跳转登录页面
|
|
|
+ if (status == 403 || status == 401) {
|
|
|
+ if (
|
|
|
+ window.___lastInvalidDate === undefined ||
|
|
|
+ window.___lastInvalidDate < Date.now() - 300
|
|
|
+ ) {
|
|
|
+ Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ callback: () => {
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ window.___lastInvalidDate = Date.now();
|
|
|
+ }
|
|
|
+ return Promise.reject(error);
|
|
|
+ } else if (status == 405) {
|
|
|
+ Vue.prototype.$alert("没有权限!", "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ callback: () => {
|
|
|
+ router.push("/login/" + getRootOrgId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return Promise.reject(error);
|
|
|
+ } else if (status == 502) {
|
|
|
+ Vue.prototype.$alert("服务器异常!", "提示", {
|
|
|
+ confirmButtonText: "确定"
|
|
|
+ });
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (status != 200) {
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
Plugin.install = function(Vue) {
|
|
|
Vue.$http = _$http; // no auto 500 error UI
|
|
|
Object.defineProperties(Vue.prototype, {
|
|
@@ -330,6 +431,15 @@ Plugin.install = function(Vue) {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ Vue.$httpWithoutBar = _$httpWithoutBar;
|
|
|
+ Object.defineProperties(Vue.prototype, {
|
|
|
+ $httpWithoutBar: {
|
|
|
+ get() {
|
|
|
+ return _$httpWithoutBar;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
Vue.use(Plugin);
|