Browse Source

修改登出

zhaoke 1 year ago
parent
commit
9c7e6a6687
1 changed files with 18 additions and 24 deletions
  1. 18 24
      src/utils/request.js

+ 18 - 24
src/utils/request.js

@@ -50,31 +50,26 @@ service.interceptors.response.use(
    */
   (response) => {
     const res = response.data;
-
     // if the custom code is not 20000, it is judged as an error.
     if (res.code != "0") {
-      Message({
-        message: res.message || "Error",
-        type: "error",
-        duration: 5 * 1000,
-      });
-
-      // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
-      if (res.code === 500 || res.code === 50012 || res.code === 50014) {
-        // to re-login
-        MessageBox.confirm(
-          "You have been logged out, you can cancel to stay on this page, or log in again",
-          "Confirm logout",
-          {
-            confirmButtonText: "Re-Login",
-            cancelButtonText: "Cancel",
-            type: "warning",
-          }
-        ).then(async () => {
-          sessionStorage.removeItem("userName");
-          store.dispatch("app/toggleOutflag", false);
-          await store.dispatch("user/logout");
-          router.push(`/login`);
+      const loseToken = res.message ? res.message.includes('用户令牌验证失败') || res.message.includes('令牌验证不通过') : false
+      if (loseToken) {
+        Message({
+          message: "身份令牌过期或失效,即将重新登录",
+          type: "error",
+          duration: 3 * 1000,
+          onClose: async () => {
+            sessionStorage.clear();
+            removeToken(); // must remove  token  first
+            removeToken("codeToken");
+            removeToken("systemSet");
+            removeToken("userid");
+            store.dispatch("app/toggleOutflag", false);
+            await store.dispatch("user/resetToken");
+            resetRouter();
+            router.push(`/login`);
+            location.reload();
+          },
         });
       }
       return Promise.reject(new Error(res.message || "Error"));
@@ -84,7 +79,6 @@ service.interceptors.response.use(
   },
   (error) => {
     const des500 = `${error}`.split(" ").includes("500");
-    return
     if (des500) {
       Message({
         message: "身份令牌过期或失效,即将重新登录",