Преглед изворни кода

修复登录失效后多次请求提示多次弹窗问题

RuoYi пре 4 година
родитељ
комит
a3f8d03611
1 измењених фајлова са 14 додато и 3 уклоњено
  1. 14 3
      ruoyi-ui/src/utils/request.js

+ 14 - 3
ruoyi-ui/src/utils/request.js

@@ -7,6 +7,8 @@ import { tansParams, blobValidate } from "@/utils/ruoyi";
7 7
 import { saveAs } from 'file-saver'
8 8
 
9 9
 let downloadLoadingInstance;
10
+// 是否显示重新登录
11
+let isReloginShow;
10 12
 
11 13
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
12 14
 // 创建axios实例
@@ -48,16 +50,25 @@ service.interceptors.response.use(res => {
48 50
       return res.data
49 51
     }
50 52
     if (code === 401) {
51
-      MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
53
+      if (!isReloginShow) {
54
+        isReloginShow = true;
55
+        MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
52 56
           confirmButtonText: '重新登录',
53 57
           cancelButtonText: '取消',
54 58
           type: 'warning'
55 59
         }
56 60
       ).then(() => {
61
+        isReloginShow = false;
57 62
         store.dispatch('LogOut').then(() => {
58
-          location.href = '/index';
63
+          // 如果是登录页面不需要重新加载
64
+          if (window.location.hash.indexOf("#/login") != 0) {
65
+            location.href = '/index';
66
+          }
59 67
         })
60
-      }).catch(() => {});
68
+      }).catch(() => {
69
+        isReloginShow = false;
70
+      });
71
+    }
61 72
       return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
62 73
     } else if (code === 500) {
63 74
       Message({