From 90ca6b5d5483cbc1c7140ba5d88b956bb0689de9 Mon Sep 17 00:00:00 2001
From: hwh <332078369@qq.com>
Date: 星期四, 08 八月 2024 14:19:02 +0800
Subject: [PATCH] pda盘点优化
---
HTML/js/public.js | 125 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 117 insertions(+), 8 deletions(-)
diff --git a/HTML/js/public.js b/HTML/js/public.js
index a15a788..59bbbe0 100644
--- a/HTML/js/public.js
+++ b/HTML/js/public.js
@@ -38,6 +38,22 @@
if (url!=IP+"/WeatherForecast/Login") {
if (!$.cookie('token')) {
callbackFun("鐧诲綍浜轰俊鎭凡澶辨晥");
+ try{
+ parent.window.location.href = '/views/Login.html';
+ }
+ catch(error){
+ window.location.href = '/views/Login.html';
+ }
+ return;
+ }
+ if(isTokenExpired($.cookie('token'))){
+ try{
+ parent.window.location.href = '/views/Login.html';
+ }
+ catch(error){
+ window.location.href = '/views/Login.html';
+ }
+ return;
}
}
$.ajax({
@@ -55,19 +71,33 @@
success: function (res, status, xhr) {
// console.log(res);
// console.log(status);
-
callbackFun(res);
},
- error: function (res, status, error) {
- // console.log(res);
- // console.log(status);
- callbackFun(res, status, error);
+ error: function (res, status, error) {
+ callbackFun(res.responseJSON, status, error);
// layer.msg(res.statusText, {
// icon: 2,
// time: 2000 //2绉掑叧闂紙濡傛灉涓嶉厤缃紝榛樿鏄�3绉掞級
// }, function() {});
},
});
+}
+function isTokenExpired(token) {
+ const tokenParts = token.split('.');
+ if (tokenParts.length !== 3) {
+ return true; // JWT 鏍煎紡涓嶆纭�
+ }
+ const payloadBase64 = tokenParts[1];
+ const payload = JSON.parse(atob(payloadBase64));
+
+ if (!payload || !payload.exp) {
+ return true; // 娌℃湁鏈夋晥杞借嵎鎴栬�呮病鏈夎繃鏈熸椂闂�
+ }
+
+ const now = Date.now() / 1000; // 褰撳墠鏃堕棿鎴筹紙绉掞級
+ const expiration = payload.exp;
+
+ return now >= expiration;
}
function synData(url, data, type, callbackFun) {
var deferred = $.Deferred();
@@ -180,9 +210,9 @@
var bodyHeight = $("#body").outerHeight();
var topHeight = $("#top").outerHeight();
var centerHeight = $("#center").outerHeight();
-// console.log(bodyHeight);
-// console.log(topHeight);
-// console.log(centerHeight);
+ console.log(bodyHeight);
+ console.log(topHeight);
+ console.log(centerHeight);
var hh = bodyHeight - topHeight-centerHeight - 26 ;//6鏄痓ody涓婂唴杈硅窛
return hh;
@@ -282,4 +312,83 @@
});
});
}
+}
+//娣辨嫹璐�
+function deepClone(source) {
+ if (typeof source !== 'object' || source == null) {
+ return source;
+ }
+ const target = Array.isArray(source) ? [] : {};
+ for (const key in source) {
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
+ if (typeof source[key] === 'object' && source[key] !== null) {
+ target[key] = deepClone(source[key]);
+ } else {
+ target[key] = source[key];
+ }
+ }
+ }
+ return target;
+}
+/**
+ * 灏嗚〃鍗曡祴鍊间负鎸囧畾鐨勫璞�
+ * @param {Object} data - 鍖呭惈琛ㄥ崟鏁版嵁鐨勫璞�
+ * @param {String} formSelector - 琛ㄥ崟鐨勯�夋嫨鍣紝渚嬪 '#myForm' 鎴� '.myForm'
+ */
+function setFormData(data, formSelector) {
+ var $form = $(formSelector);
+
+ $.each(data, function(key, value) {
+ var $field = $form.find('[name=' + key + ']');
+
+ if ($field.length > 0) {
+ var fieldType = $field.attr('type');
+
+ switch (fieldType) {
+ case 'checkbox':
+ if (Array.isArray(value)) {
+ $field.each(function() {
+ $(this).prop('checked', value.includes($(this).val()));
+ });
+ } else {
+ $field.prop('checked', value);
+ }
+ break;
+ case 'radio':
+ $field.filter('[value=' + value + ']').prop('checked', true);
+ break;
+ default:
+ $field.val(value);
+ break;
+ }
+ }
+ });
+}
+
+//鍒嗛〉鏍煎紡鍖�
+var FnParseData = function (res) {
+ return {
+ "code": res.code == 0 ? 0 : res.code, // 瑙f瀽鎺ュ彛鐘舵��
+ "msg": res.msg, // 瑙f瀽鎻愮ず鏂囨湰
+ "count": res.data.Total, // 瑙f瀽鏁版嵁闀垮害
+ "data": res.data.Items // 瑙f瀽鏁版嵁鍒楄〃
+ };
+}
+
+//璋冪敤鎵撳嵃
+function openPrintDialog(printData, printType){
+ layer.open({
+ type: 2,
+ title: '鎵撳嵃',
+ // content: '../../js/hiprint/custom.html',
+ content: '/views/SystemSettings/PrintModule.html',
+ maxmin: true,
+ area: ['100%', '100%'],
+ data: printData,
+ success: function (layero, index) {
+ var body = layer.getChildFrame('body',index);
+ body.find('#printData').val(JSON.stringify(printData));
+ body.find('#printType').val(printType);
+ }
+ });
}
\ No newline at end of file
--
Gitblit v1.8.0