From cfa35ff1f39c2a7b69d624d45f8e05591f3375d4 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期一, 30 三月 2026 11:49:29 +0800
Subject: [PATCH] 调整 报工平台,添加定时刷新功能。模块添加定时器管理模块
---
WebTM/views/仓存管理/生产入库单/Kf_ProductInBillList.html | 4
WebTM/layuiadmin/modules/timerManager.js | 113 ++++++++++++++++
WebTM/views/IpadIndex.html | 201 ++++++++++++++++++----------
WebTM/layuiadmin/Scripts/webConfig.js | 53 +++++-
4 files changed, 283 insertions(+), 88 deletions(-)
diff --git a/WebTM/layuiadmin/Scripts/webConfig.js b/WebTM/layuiadmin/Scripts/webConfig.js
index 6db8126..f9d0b7c 100644
--- a/WebTM/layuiadmin/Scripts/webConfig.js
+++ b/WebTM/layuiadmin/Scripts/webConfig.js
@@ -42,15 +42,15 @@
return GetWEBURL()
}
-
layui.use(['jquery', 'layer'], function () {
var $ = layui.jquery,
layer = layui.layer;
-
// 鍏ㄥ眬閰嶇疆
layer.config({
scrollbar: false
});
+
+ var pendingRequests = [];
// 鍏ㄥ眬閰嶇疆 榛樿涓嶆樉绀虹埗绾ф粴鍔ㄦ
var _open = layer.open;
@@ -70,6 +70,7 @@
if (oldSuccess) oldSuccess.call(this, layero, index);
};
+
// 鍏抽棴寮圭獥鏃�
options.end = function () {
if (needHideScroll) {
@@ -84,12 +85,16 @@
return _open.call(this, options);
};
+
// 鍏ㄥ眬鎷︽埅鎵�鏈� layui ajax 璇锋眰
$(document).ajaxSend(function (event, jqxhr, settings) {
var token = localStorage.getItem('token');
- if (token) {
+ pendingRequests.push(jqxhr);
+
+ if (typeof token != 'undefined') {
// 鑷姩甯︿笂 token
jqxhr.setRequestHeader('Authorization', 'Bearer ' + token);
+
}
});
@@ -99,25 +104,31 @@
$(document).ajaxComplete(function (event, jqxhr, settings) {
// HTTP 鐘舵�佺爜
var status = jqxhr.status;
-
+ console.log(jqxhr)
if (status === 401) {
+ abortAllPendingRequests(pendingRequests);
// 鏈櫥褰� / token 杩囨湡
- layer.confirm('鐧诲綍宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�', { icon: 7, title: '鎻愮ず' }, function () {
+ layer.confirm(jqxhr.responseJSON.Message, { icon: 7, title: '鎻愮ず' }, function () {
localStorage.removeItem('token');
- window.top.location.href = '../../views/user/login.html'; // 璺冲埌鐧诲綍椤�
+ window.top.location.href = '/views/user/login.html'; // 璺冲埌鐧诲綍椤�
});
} else if (status === 403) {
+ abortAllPendingRequests(pendingRequests);
// 鏃犳潈闄�
- layer.msg('鎮ㄦ病鏈夎妯″潡鐨勬搷浣滄潈闄�', { icon: 2, time: 2000 });
+ layer.confirm(jqxhr.responseJSON.Message, {
+ icon: 4, skin: 'layui-layer-lan', title: "娓╅Θ鎻愮ず", closeBtn: 0, btn: ['纭畾']
+ });
}
});
});
-
+var pendingRequests2 = []
if (typeof $ != 'undefined') {
$(document).ajaxSend(function (event, jqxhr, settings) {
var token = localStorage.getItem('token');
- if (token) {
+ pendingRequests2.push(jqxhr)
+
+ if (typeof token != 'undefined') {
// 鑷姩甯︿笂 token
jqxhr.setRequestHeader('Authorization', 'Bearer ' + token);
}
@@ -132,14 +143,32 @@
if (status === 401) {
// 鏈櫥褰� / token 杩囨湡
- layer.confirm('鐧诲綍宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�', { icon: 7, title: '鎻愮ず' }, function () {
+ abortAllPendingRequests(pendingRequests2)
+ layer.confirm(jqxhr.responseJSON.Message, { icon: 7, title: '鎻愮ず' }, function () {
localStorage.removeItem('token');
- window.top.location.href = '../../views/user/login.html'; // 璺冲埌鐧诲綍椤�
+ window.top.location.href = '/views/user/login.html'; // 璺冲埌鐧诲綍椤�
});
} else if (status === 403) {
// 鏃犳潈闄�
- layui.layer.msg('鎮ㄦ病鏈夎妯″潡鐨勬搷浣滄潈闄�', { icon: 2, time: 2000 });
+ abortAllPendingRequests(pendingRequests2)
+ layer.confirm(jqxhr.responseJSON.Message, {
+ icon: 4, skin: 'layui-layer-lan', title: "娓╅Θ鎻愮ず", closeBtn: 0, btn: ['纭畾']
+ });
}
});
}
+
+function abortAllPendingRequests(pendingRequests) {
+ if (pendingRequests.length === 0) return;
+
+ // 閬嶅巻鍙栨秷鎵�鏈夎姹�
+ $.each(pendingRequests, function (i, req) {
+ try {
+ req.abort(); // 涓柇璇锋眰
+ } catch (e) { }
+ });
+
+ // 娓呯┖璇锋眰姹�
+ pendingRequests = [];
+}
diff --git a/WebTM/layuiadmin/modules/timerManager.js b/WebTM/layuiadmin/modules/timerManager.js
new file mode 100644
index 0000000..7295b6a
--- /dev/null
+++ b/WebTM/layuiadmin/modules/timerManager.js
@@ -0,0 +1,113 @@
+/**
+ * Layui 鎵╁睍妯″潡锛氬畾鏃跺櫒绠$悊鍣�
+ * 鍔熻兘锛氱粺涓�绠$悊瀹氭椂鍣紝鏀寔鏆傚仠/鎭㈠/娓呴櫎锛岄槻姝㈠唴瀛樻硠婕�
+ */
+layui.define([], function(exports) {
+ "use strict";
+
+ // 鍘熷畾鏃跺櫒鏍稿績绫�
+ class TimerManager {
+ constructor() {
+ this.timers = new Map();
+ }
+
+ /**
+ * 鍒涘缓瀹氭椂鍣�
+ * @param {String} key 瀹氭椂鍣ㄥ敮涓�鏍囪瘑锛堝锛�'countdown'锛�
+ * @param {Function} callback 鎵ц鐨勪笟鍔″嚱鏁�
+ * @param {Number} interval 鎵ц闂撮殧锛坢s锛�
+ * @param {String} type 绫诲瀷锛歩nterval锛堥噸澶嶏級/ timeout锛堝崟娆★級
+ * @returns {void}
+ */
+ createTimer(key, callback, interval = 1000, type = 'interval') {
+ // 鍏堟竻闄ゅ悓鍚嶅畾鏃跺櫒锛岄伩鍏嶉噸澶嶅垱寤�
+ this.clearTimer(key);
+
+ let timerId = null;
+ const timerConfig = {
+ id: null,
+ type,
+ callback,
+ interval,
+ isPaused: false
+ };
+
+ if (type === 'interval') {
+ timerId = setInterval(() => {
+ // 鏆傚仠鐘舵�佷笉鎵ц
+ if (!timerConfig.isPaused) {
+ callback();
+ }
+ }, interval);
+ } else if (type === 'timeout') {
+ timerId = setTimeout(() => {
+ if (!timerConfig.isPaused) {
+ callback();
+ this.clearTimer(key); // 鍗曟鎵ц鍚庤嚜鍔ㄦ竻闄�
+ }
+ }, interval);
+ }
+
+ timerConfig.id = timerId;
+ this.timers.set(key, timerConfig);
+ }
+
+ /**
+ * 鏆傚仠瀹氭椂鍣�
+ * @param {String} key 瀹氭椂鍣ㄦ爣璇�
+ */
+ pauseTimer(key) {
+ const timer = this.timers.get(key);
+ if (timer) {
+ timer.isPaused = true;
+ }
+ }
+
+ /**
+ * 鎭㈠瀹氭椂鍣�
+ * @param {String} key 瀹氭椂鍣ㄦ爣璇�
+ */
+ resumeTimer(key) {
+ const timer = this.timers.get(key);
+ if (timer) {
+ timer.isPaused = false;
+ }
+ }
+
+ /**
+ * 娓呴櫎鍗曚釜瀹氭椂鍣�
+ * @param {String} key 瀹氭椂鍣ㄦ爣璇�
+ */
+ clearTimer(key) {
+ const timer = this.timers.get(key);
+ if (timer) {
+ if (timer.type === 'interval') {
+ clearInterval(timer.id);
+ } else if (timer.type === 'timeout') {
+ clearTimeout(timer.id);
+ }
+ this.timers.delete(key);
+ }
+ }
+
+ /**
+ * 娓呴櫎鎵�鏈夊畾鏃跺櫒锛堥〉闈㈤攢姣佹椂璋冪敤锛�
+ */
+ clearAllTimers() {
+ this.timers.forEach((timer) => {
+ if (timer.type === 'interval') {
+ clearInterval(timer.id);
+ } else if (timer.type === 'timeout') {
+ clearTimeout(timer.id);
+ }
+ });
+ this.timers.clear();
+ }
+ }
+
+ // 鍒涘缓鍗曚緥
+ const timerManager = new TimerManager();
+
+ // 瀵煎嚭妯″潡
+ exports('timerManager', timerManager);
+});
\ No newline at end of file
diff --git a/WebTM/views/IpadIndex.html b/WebTM/views/IpadIndex.html
index d75a497..243c8aa 100644
--- a/WebTM/views/IpadIndex.html
+++ b/WebTM/views/IpadIndex.html
@@ -56,7 +56,7 @@
base: '../layuiadmin/' //闈欐�佽祫婧愭墍鍦ㄨ矾寰�
}).extend({
index: 'lib/index' //涓诲叆鍙fā鍧�
- }).use(['index', 'form', 'laydate', 'table', 'element'], function () {
+ }).use(['index', 'form', 'laydate', 'table', 'element', "timerManager"], function () {
var $ = layui.$
, admin = layui.admin
, layer = layui.layer
@@ -64,6 +64,7 @@
, form = layui.form
, laydate = layui.laydate
, element = layui.element
+ , timerManager = layui.timerManager
;
//window 鍏ㄥ眬鍙橀噺
window.mychart1 = echarts.init(document.getElementById('mychart1'));
@@ -75,9 +76,67 @@
mychart2.resize();
})
+ // 閰嶇疆 寮瑰嚭灞� 鎵撳紑/鍏抽棴澶勭悊鍑芥暟
+ InitLayerConfig()
+
TSLoad();
fetchButtonsData();
+
+ timerManager.createTimer(
+ 'Timer', // 鍞竴鏍囪瘑
+ function () {
+ TSLoad();
+ },
+ 10000, // 闂撮殧3鍒嗛挓
+ 'interval' // 寰幆绫诲瀷
+ );
+
+ $(window).on('beforeunload', function () {
+ timerManager.clearAllTimers();
+ });
});
+ function InitLayerConfig() {
+ var _open = layer.open
+ , _timerManager = layui.timerManager
+
+ layer.open = function (opts) {
+ // 鍚堝苟榛樿閰嶇疆
+ var options = $.extend({}, layer.config, opts);
+
+ var oldSuccess = options.success;
+ var oldEnd = options.end;
+ var needHideScroll = options.scrollbar === false;
+
+ // 鎵撳紑寮圭獥鏃�
+ options.success = function (layero, index) {
+ if (needHideScroll) {
+ $('body').css('overflow', 'hidden');
+ }
+ console.log("鏆傚仠瀹氭椂鍣�")
+ _timerManager.pauseTimer('Timer')
+ if (oldSuccess) oldSuccess.call(this, layero, index);
+ };
+
+
+ // 鍏抽棴寮圭獥鏃�
+ options.end = function () {
+ if (needHideScroll) {
+ // 鍙湁鏈�鍚庝竴涓脊绐楀叧闂墠鎭㈠
+ if ($('.layui-layer:visible').length <= 1) {
+ $('body').css('overflow', '');
+ }
+ }
+ if ($('.layui-layer:visible').length <= 1) {
+ console.log("鎭㈠瀹氭椂鍣�")
+ _timerManager.resumeTimer('Timer')
+ }
+ if (oldEnd) oldEnd.call(this);
+ };
+
+ return _open.call(this, options);
+ };
+ }
+
function TSLoad() {
$("#topleft").html("");
var HUserName = sessionStorage["HUserName"]; //sessionStorage["HUserName"]; //榛樿褰撳墠鐧诲綍浜哄憳
@@ -118,14 +177,14 @@
case "鐢熶骇":
html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border2"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
break;
- case "缁翠慨杩涜涓�":
- html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border5"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
- break;
- case "缁翠慨缁撴潫":
+ case "寰呮満":
html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border1"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
break;
- case "缁翠慨缁堟":
- html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border1"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
+ case "鏁呴殰":
+ html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border5 "></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
+ break;
+ case "缁翠慨瀹屾垚":
+ html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border2"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
break;
default:
}
@@ -195,14 +254,14 @@
case "鐢熶骇":
html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border2"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
break;
- case "缁翠慨杩涜涓�":
- html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border5"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
- break;
- case "缁翠慨缁撴潫":
+ case "寰呮満":
html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border1"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
break;
- case "缁翠慨缁堟":
- html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border1"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
+ case "鏁呴殰":
+ html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border5 "></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
+ break;
+ case "缁翠慨瀹屾垚":
+ html1 += '<h1><span>褰撳墠鐘舵�侊細</span><span class="gj_icon color_border2"></span><span>' + LoadData[i - 1].HStatus + '</span></h1>';
break;
default:
}
@@ -239,6 +298,7 @@
if (sessionStorage["Organization"] == "瀹佹尝甯傚崕鑸熷寘瑁呮湁闄愬叕鍙�") {
// 鍗庤垷 浣跨敤鍒嗙粍鏍囩
+ console.log("鍒嗙粍鏍囩", LoadingTabsContact)
var divParent = document.createElement("div")
divParent.classList.add("layui-tab")
divParent.classList.add("layui-tab-card")
@@ -1531,75 +1591,68 @@
layer.alert("璇烽�夋嫨宸ュ崟鍒楄〃", { icon: 5 });
return false;
}
- //褰撳墠宸ュ崟(姹囨姤)鎸夐挳鐐瑰嚮浜嬩欢
- function CodingReport(event, obj) {
- if (wktag == 0) {
- layer.alert("璇烽�夋嫨宸ュ崟鍒楄〃", { icon: 5 });
- return false;
- }
-
- // 鍒ゆ柇鏄惁涓哄崕鑸熺粍缁�
- if (sessionStorage["Organization"] == "瀹佹尝甯傚崕鑸熷寘瑁呮湁闄愬叕鍙�") {
- // 鍗庤垷缁勭粐锛氳嫢姹囨姤鎬绘暟涓嶄负0鍒欒烦杩囩姸鎬佹鏌ワ紝鍚﹀垯鎵ц妫�鏌�
- if (parseFloat(HReportTotal) !== 0) {
- // 姹囨姤鎬绘暟涓嶄负0锛岀洿鎺ユ墦寮�锛堜笉鎵ц WorkStaus 妫�鏌ワ級
- } else {
- // 姹囨姤鎬绘暟绛変簬0锛屾墽琛屽師鏈夌殑鐘舵�佹鏌�
- if (WorkStaus(HSourceID1, workcode, HSourceInterID, "鏂帿灏旀眹鎶�")) {
- layer.alert("鍗曟嵁鐘舵�佷笉婊¤冻姹囨姤鏉′欢!", { icon: 5 });
- return false;
- }
- }
+ // 鍒ゆ柇鏄惁涓哄崕鑸熺粍缁�
+ if (sessionStorage["Organization"] == "瀹佹尝甯傚崕鑸熷寘瑁呮湁闄愬叕鍙�") {
+ // 鍗庤垷缁勭粐锛氳嫢姹囨姤鎬绘暟涓嶄负0鍒欒烦杩囩姸鎬佹鏌ワ紝鍚﹀垯鎵ц妫�鏌�
+ if (parseFloat(HReportTotal) !== 0) {
+ // 姹囨姤鎬绘暟涓嶄负0锛岀洿鎺ユ墦寮�锛堜笉鎵ц WorkStaus 妫�鏌ワ級
} else {
- // 闈炲崕鑸熺粍缁囷細淇濇寔鍘熸湁閫昏緫锛岀洿鎺ユ墽琛� WorkStaus 妫�鏌�
+ // 姹囨姤鎬绘暟绛変簬0锛屾墽琛屽師鏈夌殑鐘舵�佹鏌�
if (WorkStaus(HSourceID1, workcode, HSourceInterID, "鏂帿灏旀眹鎶�")) {
layer.alert("鍗曟嵁鐘舵�佷笉婊¤冻姹囨姤鏉′欢!", { icon: 5 });
return false;
}
}
+ } else {
+ // 闈炲崕鑸熺粍缁囷細淇濇寔鍘熸湁閫昏緫锛岀洿鎺ユ墽琛� WorkStaus 妫�鏌�
+ if (WorkStaus(HSourceID1, workcode, HSourceInterID, "鏂帿灏旀眹鎶�")) {
+ layer.alert("鍗曟嵁鐘舵�佷笉婊¤冻姹囨姤鏉′欢!", { icon: 5 });
+ return false;
+ }
+ }
+ layer.open({
+ type: 2,
+ skin: 'layui-layer-rim', //鍔犱笂杈规
+ title: '褰撳墠宸ュ崟',
+ closeBtn: 1,
+ shift: 2,
+ area: ['100%', '100%'],
+ maxmin: true,
+ scrollbar: false,
+ content: '杞﹂棿绠$悊/宸ュ簭鍑虹珯姹囨姤鍗�/Cj_StationOutBill_CurrentWork.html?OperationType=2&linterid=&HSouceBillType=',
+ end: function () {
- // 鎵撳紑 iframe 寮圭獥锛堝師鏈変唬鐮佷笉鍙橈級
- layer.open({
- type: 2,
- skin: 'layui-layer-rim', //鍔犱笂杈规
- title: '褰撳墠宸ュ崟',
- closeBtn: 1,
- shift: 2,
- area: ['100%', '100%'],
- maxmin: true,
- scrollbar: false,
- content: '杞﹂棿绠$悊/宸ュ簭鍑虹珯姹囨姤鍗�/Cj_StationOutBill_CurrentWork.html?OperationType=2&linterid=&HSouceBillType=',
- end: function () {
- // 鍙�夌殑鍏抽棴鍥炶皟
- },
- success: function (dom, index) {
- var data = [{
- "HEquipName": $("#HEquipName1").text(),
- "HEquipCode": $("#HEquipCode1").text(),
- "HICMOBillNo": workcode,
- "HICMOInterID": HICMOInterID,
- "HICMOEntryID": HICMOEntryID,
- "HSourceID": HSourceID1,
- "HSourceName": HSourceName1,
- "HEmpName": HEmpName,
- "HManagerID": HManagerID,
- "HManagerName": HManagerName,
- "HGroupName": HGroupName,
- "HGroupID": HGroupID,
- "HBillType": HBillType,
- "HSourceInterID": HSourceInterID,
- "HSourceEntryID": HSourceEntryID,
- "HSourceBillNo": HSourceBillNo,
- "HSourceBillType": HSourceBillType
- }];
+ },
+ success: function (dom, index) {
+ var data = [];
+ data.push({
+ "HEquipName": $("#HEquipName1").text(),
+ "HEquipCode": $("#HEquipCode1").text(),
+ "HICMOBillNo": workcode,
+ "HICMOInterID": HICMOInterID,
+ "HICMOEntryID": HICMOEntryID,
+ "HSourceID": HSourceID1,
+ "HSourceName": HSourceName1,
+ "HEmpName": HEmpName,
+ "HManagerID": HManagerID,
+ "HManagerName": HManagerName,
+ "HGroupName": HGroupName,
+ "HGroupID": HGroupID,
+ "HBillType": HBillType,
+ "HSourceInterID": HSourceInterID,
+ "HSourceEntryID": HSourceEntryID,
+ "HSourceBillNo": HSourceBillNo,
+ "HSourceBillType": HSourceBillType
+ });
- //閫氳繃绱㈠紩鑾峰彇鍒板綋鍓峣frame寮瑰嚭灞�
- var iframe = window['layui-layer-iframe' + index];
- //璋冪敤iframe寮瑰嚭灞傚唴鐨勬柟娉�
- iframe.edit(data);
- }
- });
- }
+ //閫氳繃绱㈠紩鑾峰彇鍒板綋鍓峣frame寮瑰嚭灞�
+ var iframe = window['layui-layer-iframe' + index];
+ //璋冪敤iframe寮瑰嚭灞傚唴鐨勬柟娉�
+ iframe.edit(data);
+ },
+
+
+ });
}
//璁惧鍚姩鐐规鎸夐挳鐐瑰嚮浜嬩欢
diff --git "a/WebTM/views/\344\273\223\345\255\230\347\256\241\347\220\206/\347\224\237\344\272\247\345\205\245\345\272\223\345\215\225/Kf_ProductInBillList.html" "b/WebTM/views/\344\273\223\345\255\230\347\256\241\347\220\206/\347\224\237\344\272\247\345\205\245\345\272\223\345\215\225/Kf_ProductInBillList.html"
index 270dc47..2ae2a07 100644
--- "a/WebTM/views/\344\273\223\345\255\230\347\256\241\347\220\206/\347\224\237\344\272\247\345\205\245\345\272\223\345\215\225/Kf_ProductInBillList.html"
+++ "b/WebTM/views/\344\273\223\345\255\230\347\256\241\347\220\206/\347\224\237\344\272\247\345\205\245\345\272\223\345\215\225/Kf_ProductInBillList.html"
@@ -323,7 +323,7 @@
if (sessionStorage.login != "login") {
layer.confirm("鐧诲綍澶辨晥锛岃閲嶆柊鐧诲綍锛�", {
icon: 4, skin: 'layui-layer-lan', title: "娓╅Θ鎻愮ず", closeBtn: 0, btn: ['閲嶆柊鐧诲綍']
- }, function () { window.location.href = "../../user/login.html"; });
+ }, function () { window.location.href = "/views/user/login.html"; });
}
//#region 鑾峰彇缁勭粐
@@ -1522,7 +1522,7 @@
}
//#endregion
-
+
//#endregion
//浠ヤ笂鏄痩ayui妯″潡
});
--
Gitblit v1.9.1