|
@@ -14,6 +14,7 @@ let config = {
|
|
};
|
|
};
|
|
|
|
|
|
const _axios = axios.create(config);
|
|
const _axios = axios.create(config);
|
|
|
|
+const _axiosWithoutResponseInterceptors = axios.create(config);
|
|
|
|
|
|
/**
|
|
/**
|
|
* A. token lifecycle
|
|
* A. token lifecycle
|
|
@@ -56,6 +57,36 @@ _axios.interceptors.request.use(
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+_axiosWithoutResponseInterceptors.interceptors.request.use(
|
|
|
|
+ function(config) {
|
|
|
|
+ // Do something before request is sent
|
|
|
|
+ if (config.url.includes("/login") === false) {
|
|
|
|
+ if (!wk_token) {
|
|
|
|
+ const user = JSON.parse(window.sessionStorage.getItem("user"));
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+);
|
|
|
|
+
|
|
// Add a response interceptor
|
|
// Add a response interceptor
|
|
_axios.interceptors.response.use(
|
|
_axios.interceptors.response.use(
|
|
response => {
|
|
response => {
|
|
@@ -116,9 +147,17 @@ _axios.interceptors.response.use(
|
|
);
|
|
);
|
|
|
|
|
|
Plugin.install = function(Vue) {
|
|
Plugin.install = function(Vue) {
|
|
- Vue.$http = _axios;
|
|
|
|
|
|
+ Vue.$http = _axiosWithoutResponseInterceptors;
|
|
Object.defineProperties(Vue.prototype, {
|
|
Object.defineProperties(Vue.prototype, {
|
|
$http: {
|
|
$http: {
|
|
|
|
+ get() {
|
|
|
|
+ return _axiosWithoutResponseInterceptors;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ Vue.$httpWithMsg = _axios;
|
|
|
|
+ Object.defineProperties(Vue.prototype, {
|
|
|
|
+ $httpWithMsg: {
|
|
get() {
|
|
get() {
|
|
return _axios;
|
|
return _axios;
|
|
}
|
|
}
|