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/layuiadmin/Scripts/webConfig.js |   53 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 12 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 = [];
+}

--
Gitblit v1.9.1