|
@@ -2,10 +2,12 @@ import Vue from "vue";
|
|
|
import axios from "axios";
|
|
|
// @ts-ignore
|
|
|
import { loadProgressBar } from "axios-progress-bar";
|
|
|
-import cachingGet from "./axiosCache";
|
|
|
import { notifyInvalidTokenThrottled } from "./axiosNotice";
|
|
|
+import { getToken, removeToken, getSessionId } from "../auth/auth";
|
|
|
import axiosRetry from "axios-retry";
|
|
|
+import { PLATFORM, DEVICE_ID } from "@/constants/constants";
|
|
|
import { message } from "ant-design-vue";
|
|
|
+import CryptoJS from "crypto-js";
|
|
|
import { useMainStore } from "@/store";
|
|
|
|
|
|
let store = null as unknown as ReturnType<typeof useMainStore>;
|
|
@@ -20,6 +22,19 @@ const cacheGetUrls: [RegExp] | [] = [];
|
|
|
const _axiosApp = axios.create(config);
|
|
|
axiosRetry(_axiosApp);
|
|
|
|
|
|
+function gToken(
|
|
|
+ method: "get" | "post",
|
|
|
+ url: string,
|
|
|
+ token: string,
|
|
|
+ time: number
|
|
|
+) {
|
|
|
+ const Authorization = `Token ${getSessionId()}:${CryptoJS.enc.Base64.stringify(
|
|
|
+ CryptoJS.SHA1("post&" + url + "&" + time + "&" + token)
|
|
|
+ )}`;
|
|
|
+
|
|
|
+ return Authorization;
|
|
|
+}
|
|
|
+
|
|
|
_axiosApp.interceptors.request.use(
|
|
|
function (config) {
|
|
|
if (!store) {
|
|
@@ -28,6 +43,21 @@ _axiosApp.interceptors.request.use(
|
|
|
if (config.setGlobalMask) {
|
|
|
store.globalMask = true;
|
|
|
}
|
|
|
+ const wk_token = getToken();
|
|
|
+ const time = Date.now();
|
|
|
+ if (wk_token) {
|
|
|
+ const completeURL = new URL("http://nasty.com" + config.url);
|
|
|
+ const path = completeURL.pathname;
|
|
|
+ config.headers.common["Authorization"] = gToken(
|
|
|
+ "post",
|
|
|
+ path,
|
|
|
+ wk_token,
|
|
|
+ time
|
|
|
+ );
|
|
|
+ }
|
|
|
+ config.headers.common["platform"] = PLATFORM;
|
|
|
+ config.headers.common["deviceId"] = DEVICE_ID;
|
|
|
+ config.headers.common["time"] = time;
|
|
|
return config;
|
|
|
},
|
|
|
function (error) {
|
|
@@ -69,6 +99,7 @@ _axiosApp.interceptors.response.use(
|
|
|
// 登录失效 跳转登录页面
|
|
|
if (status == 403 || status == 401) {
|
|
|
notifyInvalidTokenThrottled();
|
|
|
+ removeToken();
|
|
|
return Promise.reject(error);
|
|
|
} else if (status == 405) {
|
|
|
if (showErrorMessage) {
|
|
@@ -101,7 +132,6 @@ _axiosApp.interceptors.response.use(
|
|
|
}
|
|
|
);
|
|
|
|
|
|
-// _axiosApp.get = cachingGet(_axiosApp, cacheGetUrls);
|
|
|
loadProgressBar(null, _axiosApp);
|
|
|
|
|
|
export const httpApp = _axiosApp;
|