Selaa lähdekoodia

登录失效调试

zhouna 3 vuotta sitten
vanhempi
commit
49d007ea0a
3 muutettua tiedostoa jossa 39 lisäystä ja 109 poistoa
  1. 0 2
      src/js/index.js
  2. 0 3
      src/js/login.js
  3. 39 104
      src/js/utils.js

+ 0 - 2
src/js/index.js

@@ -602,8 +602,6 @@ window.addEventListener('message', e => {
       sureBtn: false,
       message: data.data || '登录过期',
       callback: function () {
-        //alert('跳回登录3')
-        //localStorage.removeItem('accessToken')
         window.location.href = 'login.html'
       }
     });

+ 0 - 3
src/js/login.js

@@ -6,7 +6,6 @@ require("./modal.js")
 const { api } = require('./api.js')
 
 const { post, setCookie, delCookie, getUrlArgObject, toast } = require('../js/utils.js');
-const md5 = require('js-md5');
 const hideLogo = getUrlArgObject("hideLg");
 const otherLogo = getUrlArgObject("adLg");
 let type;
@@ -16,7 +15,6 @@ $(function () {
   if (hideLogo || otherLogo) {
     $(".copy-right").text("");
   }
-  //localStorage.removeItem('accessToken')
   $(document).keyup(function (event) {
     if (event.keyCode == 13) {
       sureLogin()
@@ -28,7 +26,6 @@ $(function () {
 
 //获取验证码
 function getSecurityCode() {
-  var windowUrl = window.URL || window.webkitURL;//处理浏览器兼容性
   var xhr = new XMLHttpRequest();
   var url = api.getCaptcha;//验证码请求地址
   xhr.open("GET", url, true);

+ 39 - 104
src/js/utils.js

@@ -148,8 +148,6 @@ const post = function (url, data, opts) {
   if (!token && window.location.href.indexOf('login') == -1) {
     setCookie('behosDateStart', '');
     setCookie('behosDateEnd', '');
-    //alert('无token判断,跳回登录')
-    // window.location.href = '../login.html';
   }
   for (let i = 0; i < $('.typeFilter').children().length; i++) {
     if (
@@ -186,123 +184,32 @@ const post = function (url, data, opts) {
         }
       },
       success: function (res) {
-
-        const json = res
-        let jsonres = null
-        if (typeof (json) === 'string') {
-          jsonres = JSON.parse(json)
-        } else {
-          jsonres = {
-            ...json
-          }
+        if(res.code==="0"){
+		  resolve({
+			data: res
+		  });
+		  return;
         }
-
-        let dialogcode = jsonres.code === '10020011' || jsonres.code === '10020012' || jsonres.code === '10020013'
-        if (jsonres.code && dialogcode) {
-          localStorage.removeItem('accessToken')
-          console.log('token已清除1')
-          $.alerModal({
-            gobackBtn: true,
-            title: "提示",
-            type: "modal",
-            width: '470',
-            time: 1000,
-            cancalText: '我知道了',
-			isFather: true,
-            fatherWrapper: $("#mainBox", parent.document),
-            sureBtn: false,
-            message: jsonres.msg || '登录过期',
-            callback: function () {
-
-              //alert('跳回登录2')
-              // localStorage.removeItem('accessToken')
-              // if (window.parent) {
-              //   window.parent.window.location.href = 'login.html'
-              // } else {
-              //   window.location.href = 'login.html'
-              // }
-              window.parent.window.location.href = 'login.html'
-            }
-          });
-        } else if (jsonres.code && dialogcode && (self != top)) {
-          localStorage.removeItem('accessToken')
-          console.log('token已清除2')
-          const dialogmessage = {
-            iframemessage: 1,
-            data: jsonres.msg
-          }
-          window.parent.postMessage(JSON.stringify(dialogmessage), '*')
-        }
-        resolve({
-          data: res
-        });
+        //登录信息失效处理
+		unloginPop(res.code);
       },
       error: function (error) {
-        const errorCode = {
-          ...error.responseJSON
-        }
-        //const wd = window.parent.window || window;
-        // if (jsonres.code && (jsonres.code === '10020011' || jsonres.code === '00020007') && (self != top)) {
-        //   let dialog = 'true'
-        //   window.parent.postMessage(dialog, '*')
-
-        // }
-        let dialogcode2 = errorCode.code === '10020011' || errorCode.code === '10020012' || errorCode.code === '10020013'
-
-        if (errorCode.code && dialogcode2 && (self == top)) {
-          localStorage.removeItem('accessToken')
-          console.log('token已清除3')
-          $.alerModal({
-            gobackBtn: true,
-            title: "提示",
-            type: "modal",
-            width: '470',
-            time: 1000,
-            cancalText: '我知道了',
-			isFather: true,
-			fatherWrapper: $("#mainBox", parent.document),
-            sureBtn: false,
-            message: errorCode.msg || '登录过期',
-            callback: function () {
-              //alert('跳回登录1')
-
-              // if (window.parent) {
-              //   window.parent.window.location.href = 'login.html'
-              // } else {
-
-              // }
-			  //localStorage.removeItem('accessToken')
-              window.location.href = 'login.html'
-            }
-          });
-        } else {
-          if (errorCode.code && dialogcode2 && (self != top)) {
-            localStorage.removeItem('accessToken')
-            const dialogmessage = {
-              iframemessage: 1,
-              data: errorCode.msg
-            }
-            window.parent.postMessage(JSON.stringify(dialogmessage), '*')
-          }
           if (error.status === 403 || error.status === 401) {
             setCookie('behosDateStart', '');
             setCookie('behosDateEnd', '');
             if (!token && window.location.href.indexOf('login') == -1) {
-              //alert('无token判断,跳回登录')
-              // window.location.href = '../login.html';
             } else {
               if($(".alertModal:visible").length){
                 return;
               }
               $.alerModal({
-                "message": "没有该权限",
+                "message": "没有该权限"+error.status,
                 type: "tip",
                 time: '1000',
                 isFather: true,
                 fatherWrapper: $("#mainBox", parent.document)
               });
             }
-            // wd.location.href = "../login.html";
           } else if (error.status === 500 || error.status === 501 || error.status === 404) {
             $.alerModal({
               "message": '接口错误',
@@ -311,16 +218,44 @@ const post = function (url, data, opts) {
               isFather: true,
               fatherWrapper: $("#mainBox", parent.document)
             });
-
-            // wd.location.href = '../error.html?code=' + error.status;
           }
-        }
         reject(error);
       },
     });
   });
 };
 
+//登录失效弹窗处理
+function unloginPop(code){
+  const isOut = code === '10020011' || code === '10020012' || code === '10020013';
+  if(isOut){
+    if(self != top){
+	  const dialogmessage = {
+		iframemessage: 1,
+		data: errorCode.msg
+	  }
+	  window.parent.postMessage(JSON.stringify(dialogmessage), '*')
+    }else{
+	  $.alerModal({
+		gobackBtn: true,
+		title: "提示",
+		type: "modal",
+		width: '470',
+		time: 1000,
+		cancalText: '我知道了',
+		isFather: true,
+		fatherWrapper: $("#mainBox", parent.document),
+		sureBtn: false,
+		message: errorCode.msg || '登录过期',
+		callback: function () {
+		  window.location.href = 'login.html'
+		}
+	  });
+    }
+  }
+
+}
+
 // 导出
 const expJson = (url, data) => {
   const token = localStorage.getItem('accessToken');