admin
2 天以前 49bb2841cc45fea723667672e56c8c7510165ba8
Pda/js/public.js
@@ -5,7 +5,7 @@
//var IP = "http://192.168.1.2:8017/";
//var IP = "http://192.168.10.112/WmsService/";
//var IP = "http://192.168.1.226:8086";
//var IP = "http://192.168.62.200:8888/api";
//var IP = "http://192.168.62.200:8888/api";
//运行
var IP = "https://localhost:44363/api";
//本地发布
@@ -22,22 +22,20 @@
      data = JSON.stringify(data);
   }
   if (url != IP + "/WeatherForecast/Login") {
      if (!$.cookie('token')) {
      if (!$.cookie("token")) {
         callbackFun("登录人信息已失效");
         try {
            parent.window.location.href = '/View/login.html';
         }
         catch (error) {
            window.location.href = '/View/login.html';
            parent.window.location.href = "/View/login.html";
         } catch (error) {
            window.location.href = "/View/login.html";
         }
         return;
      }
      if (isTokenExpired($.cookie('token'))) {
      if (isTokenExpired($.cookie("token"))) {
         try {
            parent.window.location.href = '/View/login.html';
         }
         catch (error) {
            window.location.href = '/View/login.html';
            parent.window.location.href = "/View/login.html";
         } catch (error) {
            window.location.href = "/View/login.html";
         }
         return;
      }
@@ -47,8 +45,8 @@
      data: data,
      type: type,
      headers: {
         'Content-Type': 'application/json',
         "ToKen": $.cookie('token')
         "Content-Type": "application/json",
         ToKen: $.cookie("token"),
      },
      timeout: 45000,
      async: true,
@@ -63,7 +61,7 @@
         //   icon: 2,
         //   time: 2000 //2秒关闭(如果不配置,默认是3秒)
         // }, function() {});
      }
      },
   });
}
function synData(url, data, type, callbackFun) {
@@ -72,22 +70,20 @@
      data = JSON.stringify(data);
   }
   if (url != IP + "/WeatherForecast/Login") {
      if (!$.cookie('token')) {
      if (!$.cookie("token")) {
         callbackFun("登录人信息已失效");
         try {
            parent.window.location.href = '/View/login.html';
         }
         catch (error) {
            window.location.href = '/View/login.html';
            parent.window.location.href = "/View/login.html";
         } catch (error) {
            window.location.href = "/View/login.html";
         }
         return;
      }
      if (isTokenExpired($.cookie('token'))) {
      if (isTokenExpired($.cookie("token"))) {
         try {
            parent.window.location.href = '/View/login.html';
         }
         catch (error) {
            window.location.href = '/View/login.html';
            parent.window.location.href = "/View/login.html";
         } catch (error) {
            window.location.href = "/View/login.html";
         }
         return;
      }
@@ -98,7 +94,7 @@
      type: type,
      headers: {
         "Content-Type": "application/json",
         "ToKen": $.cookie('token'),
         ToKen: $.cookie("token"),
      },
      timeout: 45000,
      async: false,
@@ -116,7 +112,7 @@
}
$("#navIcon").click(function () {
   if ($(".nav_list").css('display') == 'none') {
   if ($(".nav_list").css("display") == "none") {
      $(".nav_list").show();
   } else {
      $(".nav_list").hide();
@@ -125,36 +121,37 @@
//深拷贝
function deepCopy(obj) {
   let newobj = null     // 接受拷贝的新对象
   if (typeof (obj) == 'object' && typeof (obj) !== null) {   // 判断是否是引用类型
      newobj = obj instanceof Array ? [] : {}               // 判断是数组还是对象
   let newobj = null; // 接受拷贝的新对象
   if (typeof obj == "object" && typeof obj !== null) {
      // 判断是否是引用类型
      newobj = obj instanceof Array ? [] : {}; // 判断是数组还是对象
      for (var i in obj) {
         newobj[i] = deepCopy(obj[i])                        // 判断下一级是否还是引用类型
         newobj[i] = deepCopy(obj[i]); // 判断下一级是否还是引用类型
      }
   } else {
      newobj = obj
      newobj = obj;
   }
   return newobj
   return newobj;
}
function isTokenExpired(token) {
   if(token==undefined||token==''){
   if (token == undefined || token == "") {
      return true;
   }
   const tokenParts = token.split('.');
   const tokenParts = token.split(".");
   if (tokenParts.length !== 3) {
     return true; // JWT 格式不正确
      return true; // JWT 格式不正确
   }
   const payloadBase64 = tokenParts[1];
   const payload = JSON.parse(atob(payloadBase64));
   if (!payload || !payload.exp) {
     return true; // 没有有效载荷或者没有过期时间
      return true; // 没有有效载荷或者没有过期时间
   }
   const now = Date.now() / 1000; // 当前时间戳(秒)
   const expiration = payload.exp;
   return now >= expiration;
  }
}