فهرست منبع

fix network utils

Michael Wang 3 سال پیش
والد
کامیت
f13b815415
3فایلهای تغییر یافته به همراه25 افزوده شده و 21 حذف شده
  1. 2 2
      src/plugins/axiosApp.ts
  2. 22 18
      src/plugins/axiosNotice.ts
  3. 1 1
      src/utils/utils.ts

+ 2 - 2
src/plugins/axiosApp.ts

@@ -33,7 +33,7 @@ function gToken(
   time: number
 ) {
   const Authorization = `Token ${getSessionId()}:${CryptoJS.enc.Base64.stringify(
-    CryptoJS.SHA1("post&" + url + "&" + time + "&" + token)
+    CryptoJS.SHA1(method + "&" + url + "&" + time + "&" + token)
   )}`;
 
   return Authorization;
@@ -50,7 +50,7 @@ _axiosApp.interceptors.request.use(
       const completeURL = new URL("http://nasty.com" + config.url);
       const path = completeURL.pathname;
       config.headers.common["Authorization"] = gToken(
-        "post",
+        config.method?.toLowerCase() === "get" ? "get" : "post",
         path,
         wk_token,
         time

+ 22 - 18
src/plugins/axiosNotice.ts

@@ -4,21 +4,25 @@ import { message } from "ant-design-vue";
 import { logout } from "@/api/loginPage";
 import router, { routeLogout } from "@/router";
 
-export const notifyInvalidTokenThrottled = throttle(() => {
-  if (router.currentRoute.value.name === "Login") {
-    return;
-  }
-  message.error({
-    content: "登录失效,请重新登录!",
-    duration: 10,
-  });
-  setTimeout(() => {
-    logout().finally(() =>
-      routeLogout({
-        cause: "登录失效",
-        redirectTo: router.currentRoute.value.fullPath,
-      })
-    );
-  }, 3000);
-  console.log("登录失效");
-}, 5000);
+export const notifyInvalidTokenThrottled = throttle(
+  () => {
+    if (router.currentRoute.value.name === "Login") {
+      return;
+    }
+    message.error({
+      content: "登录失效,请重新登录!",
+      duration: 10,
+    });
+    setTimeout(() => {
+      logout().finally(() =>
+        routeLogout({
+          cause: "登录失效",
+          redirectTo: router.currentRoute.value.fullPath,
+        })
+      );
+    }, 3000);
+    console.log("登录失效");
+  },
+  5000,
+  { trailing: false }
+);

+ 1 - 1
src/utils/utils.ts

@@ -8,7 +8,7 @@ export async function downloadFileURL(url: string, name?: string) {
     .then((res) => {
       const { data, headers } = res;
       const fileName = headers["content-disposition"].replace(
-        /\w+;filename=(.*)/,
+        /\w+;\s+filename=(.*)/,
         "$1"
       );
       //Here, when the JSON file is returned, the JSON.stringify Processing, other types of files do not need to be processed