Просмотр исходного кода

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

RuoYi лет назад: 4
Родитель
Сommit
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
 import { saveAs } from 'file-saver'
7
 import { saveAs } from 'file-saver'
8
 
8
 
9
 let downloadLoadingInstance;
9
 let downloadLoadingInstance;
10
+// 是否显示重新登录
11
+let isReloginShow;
10
 
12
 
11
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
13
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
12
 // 创建axios实例
14
 // 创建axios实例
@@ -48,16 +50,25 @@ service.interceptors.response.use(res => {
48
       return res.data
50
       return res.data
49
     }
51
     }
50
     if (code === 401) {
52
     if (code === 401) {
51
-      MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
53
+      if (!isReloginShow) {
54
+        isReloginShow = true;
55
+        MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
52
           confirmButtonText: '重新登录',
56
           confirmButtonText: '重新登录',
53
           cancelButtonText: '取消',
57
           cancelButtonText: '取消',
54
           type: 'warning'
58
           type: 'warning'
55
         }
59
         }
56
       ).then(() => {
60
       ).then(() => {
61
+        isReloginShow = false;
57
         store.dispatch('LogOut').then(() => {
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
       return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
72
       return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
62
     } else if (code === 500) {
73
     } else if (code === 500) {
63
       Message({
74
       Message({