Selaa lähdekoodia

fix: 修复登录状态检查重复请求问题并切换测试环境地址

lsc 2 viikkoa sitten
vanhempi
commit
deec0ae149
2 muutettua tiedostoa jossa 79 lisäystä ja 19 poistoa
  1. 55 17
      js/liyuan/Onload2.js
  2. 24 2
      js/liyuan/Onload3.js

+ 55 - 17
js/liyuan/Onload2.js

@@ -33,18 +33,18 @@ U.MD.D.LocalStorage = null;
  */
 window.onload = function () {
     U.MD.D.Load();
-    U.MD.U.L.login();
+    // U.MD.U.L.login();
     //U.MD.D.isLogin();
     // U.MD.D.fullscreen();
     U.MD.D.stopSafari();
 
-    const params = ['type', 'courseid', 'orgnum', 'classcode'].reduce((acc, key) => {
+    const params = ['type', 'courseid', 'orgnum', 'classcode', 'state', 'form'].reduce((acc, key) => {
         const value = U.UF.C.queryString(key);
         if (value) acc[key] = value;
         return acc;
     }, {});
     U.MD.D.I.openApplication('liyuanLogin', params);
-
+    
     let _hashSearch = "?" + (window.location.hash.split("?")[1] || "");
     let shareCourseId = U.UF.C.queryString("shareCourseId", _hashSearch);
     let _shareType = U.UF.C.queryString("type", _hashSearch);
@@ -61,19 +61,19 @@ window.onload = function () {
 }
 
 US.Config = {
-    server: '//cloud.api.cocorobo.hk/api/',
-    api: '//cloud.api.cocorobo.hk/',
+    server: '//beta.api.cocorobo.cn/api/',
+    api: '//beta.api.cocorobo.cn/',
     chat: "//chat.api.cocorobo.cn/",
     edu: '//api.edu.cocorobo.cn/edu/',
     origin: '//cocorobo.cn',
     pbl: "//pbl.cocorobo.cn/api/pbl/",
-    // bpbl:"//pbl.cocorobo.cn",//正式鏈接
-    // bpbl:"//beta.pbl.cocorobo.cn",//測試鏈接
-    bpbl:"//pbl.cocorobo.hk",//hk鏈接
+    // bpbl:"//pbl.cocorobo.cn",//正式链接
+    bpbl:"//beta.pbl.cocorobo.cn",//测试链接
     // pbl: "http://localhost:7003/api/pbl/",
     basename: '',
     type:1,
-    background:'url("/img/icon/bgImg4.png")'
+    // background:'url("/img/icon/bgImg4.png")'
+    background:''
 }
 /**
  * 供外部调用的window.onload函数云端系统启动项
@@ -346,7 +346,7 @@ U.MD.D.getuser = function () {
             if (!panId && _cookie && loginType != 1 && !_loginInFlight) {
                 _loginInFlight = true;
                 U.A.Request(US.Config.server + "getcookieuserid", [], function (res) {
-                    _loginInFlight = false;     
+                    _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) {
@@ -704,7 +704,7 @@ U.MD.D.getuser = function () {
         US.userInfo = {}
         _loginInFlight = true;
         U.A.Request(US.Config.server + "getcookieuserid", [], function (res) {
-            _loginInFlight = false;     
+            _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) {
@@ -723,7 +723,9 @@ U.MD.D.getuser = function () {
                 }, [], { "type": "GET", "withCredentials": true });
             }else {
                 window.onbeforeunload = null
-                window.location.reload();
+                if(LoginState){
+                    window.location.reload();
+                }
             }
         }, [], { "type": "GET", "withCredentials": true });
     }else if(LoginState && _cookie && !isPanL && !_loginInFlight){
@@ -732,7 +734,7 @@ U.MD.D.getuser = function () {
         isPanL = true
         _loginInFlight = true;
         U.A.Request(US.Config.server + "getcookieuserid", [], function (res) {
-            _loginInFlight = false;     
+            _loginInFlight = false;
             if (res.value && res.value[0] && res.value[0][0]) {
                 isPanL = false
             }else if(res.status && res.status.status != 0){
@@ -1030,8 +1032,8 @@ function loginPan(userInfo, userId) {
   let vip_member = $(".vip_member")[0];
   vip_member && (vip_member.innerHTML = vMember);
 
-  addOp('','cocoflowLogin','')
-  addOp('','cocoflowOpen','')
+//   addOp('','cocoflowLogin','')
+//   addOp('','cocoflowOpen','')
 //   U.A.Request(
 //     US.Config.pbl + "addLoginOperation",
 //     [userId],
@@ -1239,6 +1241,7 @@ function loginSet(userInfo, res){
     //     U.MD.D.I.openApplication("appStore")
     // }
 
+    // let shareCourseId = window.location.href.indexOf("?shareCourseId=")!=-1?window.location.href.split("?shareCourseId=")[1].toString():''
     let _hashSearch = "?" + (window.location.hash.split("?")[1] || "");
     let shareCourseId = U.UF.C.queryString("shareCourseId", _hashSearch);
     let _shareType = U.UF.C.queryString("type", _hashSearch);
@@ -1278,11 +1281,16 @@ function selectUser(uid, callback) {
     const requestUser = () => {
         U.A.Request(`${US.Config.pbl}selectUser?userid=${uid}`, [], function (res) {
             if(res && res.value && res.value.length && res.value[0].length && res.value[0][0].userid){
+                if(U.UF.C.queryString('form') == 'desktop') {
+                    window.location.href=`cocorobo://auth/callback?apiKey=${res.value[0][0].apikey}&state=${U.UF.C.queryString('state')}&userid=${res.value[0][0].userid}&username=${res.value[0][0].username}&schoolname=${res.value[0][0].schoolName}`
+                }
                 if (callback) callback(res);
             }else {
                 U.alert("获取用户信息失败,正在重试!")
                 LoginState = false
-                requestUser();
+                setTimeout(() => {
+                    requestUser();
+                }, 10000);
             }
         }, [], { "type": "GET", "withCredentials": true });
     };
@@ -1292,7 +1300,9 @@ function selectUser(uid, callback) {
     } catch (error) {
         U.alert("登录失败,正在重试!")
         LoginState = false
-        requestUser();
+        setTimeout(() => {
+            requestUser();
+        }, 10000);
     }
 }
 
@@ -1303,6 +1313,34 @@ function addOp(text,type,time){
         }, [], { "type": "POST", "withCredentials": true });
     }
 }
+function detectBrowser() {
+    const ua = navigator.userAgent;
+
+    // 按优先级顺序检测
+    if (ua.includes("Edg/") || ua.includes("Edge/")) {
+        return "Microsoft Edge";
+    } else if (ua.includes("Firefox")) {
+        return "Mozilla Firefox";
+    } else if (ua.includes("Trident") || ua.includes("MSIE")) {
+        return "Internet Explorer";
+    } else if (ua.includes("360EE")) {
+        return "360 Browser (极速模式)";
+    } else if (ua.includes("360SE")) {
+        return "360 Browser (安全模式)";
+    } else if (ua.includes("SLBrowser")) {
+        return "QQ Browser";
+    } else if (ua.includes("UCBrowser")) {
+        return "UC Browser";
+    } else if (ua.includes("Opera") || ua.includes("OPR/")) {
+        return "Opera";
+    } else if (ua.includes("Chrome") && !ua.includes("Edg/")) {
+        return "Google Chrome";
+    } else if (ua.includes("Safari/") && !ua.includes("Chrome")) {
+        return "Safari";
+    } else {
+        return "Other Browser";
+    }
+}
 
 U.MD.D.addOp3 = async (userTime, loadTime, object, status) => {
     let browser = detectBrowser()

+ 24 - 2
js/liyuan/Onload3.js

@@ -318,6 +318,9 @@ U.MD.D.error = function (errorMessage, scripturi, linenumber, columnnumber, erro
  */
 let LoginState = false
 let CookieS = ''
+let CookieCheckTimes = 0
+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 +330,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 = true
                     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 +687,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 +713,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 });
     }
 }