Explorar el Código

fix: 修复登录状态下重复请求用户信息的问题

lsc hace 1 semana
padre
commit
e2659a828f
Se han modificado 1 ficheros con 23 adiciones y 2 borrados
  1. 23 2
      js/liyuan/Onload.js

+ 23 - 2
js/liyuan/Onload.js

@@ -318,6 +318,8 @@ U.MD.D.error = function (errorMessage, scripturi, linenumber, columnnumber, erro
  */
 let LoginState = false
 let CookieS = ''
+let isPanL = false
+let _loginInFlight = false
 U.MD.D.getuser = function () {
     // $("#U_MD_D_BG")[0].style.backgroundImage = 'url("/img/icon/gif/longhuaBg.gif")'
     var userInfo = US.userInfo;
@@ -327,8 +329,10 @@ U.MD.D.getuser = function () {
         LoginState = true
         var _cookie = U.UF.Cookie.get("cocorobo");
         try {
-            if (!panId && _cookie && loginType != 1) {
+            if (!panId && _cookie && loginType != 1 && !_loginInFlight) {
+                _loginInFlight = true
                 U.A.Request(US.Config.server + "getcookieuserid", [], function (res) {
+                    _loginInFlight = false
                     if (res.value && res.value[0] && res.value[0][0]) {
                         var _user = res.value[0][0];
                         U.A.Request(US.Config.edu + "admin/userinfo/userinfoById/" + _user.userid, [], function (res) {
@@ -682,9 +686,11 @@ U.MD.D.getuser = function () {
     }else if(LoginState && !CookieS){
         CookieS = _cookie
         U.UF.Cookie.set("cocoroboLoginType=2");
-    }else if(LoginState && _cookie != CookieS){
+    }else if(LoginState && _cookie != CookieS && !_loginInFlight){
         US.userInfo = {}
+        _loginInFlight = true
         U.A.Request(US.Config.server + "getcookieuserid", [], function (res) {
+            _loginInFlight = false
             if (res.value && res.value[0] && res.value[0][0]) {
                 var _user = res.value[0][0];
                 U.A.Request(US.Config.edu + "admin/userinfo/userinfoById/" + _user.userid, [], function (res) {
@@ -706,6 +712,21 @@ U.MD.D.getuser = function () {
                 window.location.reload();
             }
         }, [], { "type": "GET", "withCredentials": true });
+    }else if(LoginState && _cookie && !isPanL && !_loginInFlight){
+        CookieCheckTimes++
+        if (CookieCheckTimes % 5 !== 0) return;
+        isPanL = true
+        _loginInFlight = true;
+        U.A.Request(US.Config.server + "getcookieuserid", [], function (res) {
+            _loginInFlight = false;
+            if (res.value && res.value[0] && res.value[0][0]) {
+                isPanL = false
+            }else if(res.status && res.status.status != 0){
+                U.UF.Cookie.del('cocorobo')
+                window.onbeforeunload = null
+                window.location.reload();
+            }
+        }, [], { "type": "GET", "withCredentials": true });
     }
 }