From ecd9d731c0970ea9abc764afad5432477ecc23ef Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期四, 26 三月 2026 10:57:31 +0800
Subject: [PATCH] 修改 webconfig 实现 全局 ajax请求自动载入 Token , 全局配置打开弹出层后,自动隐藏父级滚动条的功能

---
 WebTM/layuiadmin/Scripts/webConfig.js |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 109 insertions(+), 3 deletions(-)

diff --git a/WebTM/layuiadmin/Scripts/webConfig.js b/WebTM/layuiadmin/Scripts/webConfig.js
index abae271..6db8126 100644
--- a/WebTM/layuiadmin/Scripts/webConfig.js
+++ b/WebTM/layuiadmin/Scripts/webConfig.js
@@ -5,13 +5,17 @@
     //var WEBURL = "http://localhost/API/";             //棰滄檽鍐涙湰鍦伴厤缃�
     //var WEBURL = "http://localhost:8082/API/";        //鏉滆春鏈湴閰嶇疆
     //var WEBURL = "http://localhost:81/API/"           //缈佹稕娑涙湰鍦伴厤缃�
-    //var WEBURL = "http://localhost:8082/API/";        //寮犵憺骞挎湰鍦伴厤缃�
-    //var WEBURL = "http://localhost:81/API/";          //闄堥晲鍝叉湰鍦伴厤缃�
-    var WEBURL = "http://localhost:8082/LuBaoAPI/";   //鏉庢灄淇婃湰鍦伴厤缃�
+    // var WEBURL = "http://localhost:8082/API/";        //寮犵憺骞挎湰鍦伴厤缃�
+    var WEBURL = "http://localhost:81/API/";          //闄堥晲鍝叉湰鍦伴厤缃�
+    //var WEBURL = "http://localhost:8082/LuBaoAPI/";   //鏉庢灄淇婃湰鍦伴厤缃�
     //var WEBURL = "http://localhost:8080/API/";        //鐜嬩华鏈湴閰嶇疆
     //var WEBURL = "http://localhost:8082/LuBaoAPI/";   //浣欐�濇澃鏈湴閰嶇疆
     //var WEBURL = "http://localhost:8088/ARAPI/";      //浣欐�濇澃鏈湴閰嶇疆(瀹夌憺)
     //var WEBURL = "http://47.96.97.237/API/";          //鏅轰簯鏈嶅姟鍣�
+    /* var WEBURL = "http://localhost:8082/LuBaoAPI/";  //浣欐�濇澃鏈湴閰嶇疆*/
+    // var WEBURL = "http://localhost:81/API/";            // 闄堥晲鍝叉湰鍦伴厤缃�*/
+    //var WEBURL = "http://localhost:8082/LuBaoAPI/";  //鏉庢灄淇婃湰鍦伴厤缃�
+    //var WEBURL = "http://localhost:8088/ARAPI/";      //浣欐�濇澃鏈湴閰嶇疆(瀹夌憺)
     //var WEBURL = "http://61.164.86.218:8099/ABAPI/";  //濂ラ偊
     //var WEBURL = "http://10.1.4.155/API/";            //姹熶赴瀹㈡埛NEW
     //var WEBURL = "http://183.129.128.86:9090/API/";   //鍑礉濂堢壒瀹㈡埛鏈嶅姟鍣ㄥ缃�
@@ -30,6 +34,7 @@
     //var WEBURL = "http://121.36.199.126:8181/API/";   //涓夊崌
     //var WEBURL = "http://36.134.2.30:200/WEBS-API/";  //閲戝竻
     //var WEBURL = "http://172.16.1.85/API/";           //杩﹀崡
+    // var WEBURL = "http://61.164.64.222:8082/API_WW/"
     return WEBURL
 }
 
@@ -37,3 +42,104 @@
     return GetWEBURL()
 }
 
+
+layui.use(['jquery', 'layer'], function () {
+    var $ = layui.jquery,
+        layer = layui.layer;
+
+    // 鍏ㄥ眬閰嶇疆
+    layer.config({
+        scrollbar: false
+    });
+
+    // 鍏ㄥ眬閰嶇疆 榛樿涓嶆樉绀虹埗绾ф粴鍔ㄦ
+    var _open = layer.open;
+    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');
+            }
+            if (oldSuccess) oldSuccess.call(this, layero, index);
+        };
+
+        // 鍏抽棴寮圭獥鏃�
+        options.end = function () {
+            if (needHideScroll) {
+                // 鍙湁鏈�鍚庝竴涓脊绐楀叧闂墠鎭㈠
+                if ($('.layui-layer:visible').length <= 1) {
+                    $('body').css('overflow', '');
+                }
+            }
+            if (oldEnd) oldEnd.call(this);
+        };
+
+        return _open.call(this, options);
+    };
+
+    // 鍏ㄥ眬鎷︽埅鎵�鏈� layui ajax 璇锋眰
+    $(document).ajaxSend(function (event, jqxhr, settings) {
+        var token = localStorage.getItem('token');
+        if (token) {
+            // 鑷姩甯︿笂 token
+            jqxhr.setRequestHeader('Authorization', 'Bearer ' + token);
+        }
+
+    });
+
+
+    // 缁熶竴澶勭悊 鏈璇�/鏈巿鏉冭姹�
+    $(document).ajaxComplete(function (event, jqxhr, settings) {
+        // HTTP 鐘舵�佺爜
+        var status = jqxhr.status;
+
+        if (status === 401) {
+            // 鏈櫥褰� / token 杩囨湡
+            layer.confirm('鐧诲綍宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�', { icon: 7, title: '鎻愮ず' }, function () {
+                localStorage.removeItem('token');
+                window.top.location.href = '../../views/user/login.html'; // 璺冲埌鐧诲綍椤�
+
+            });
+        } else if (status === 403) {
+            // 鏃犳潈闄�
+            layer.msg('鎮ㄦ病鏈夎妯″潡鐨勬搷浣滄潈闄�', { icon: 2, time: 2000 });
+        }
+    });
+});
+
+if (typeof $ != 'undefined') {
+    $(document).ajaxSend(function (event, jqxhr, settings) {
+        var token = localStorage.getItem('token');
+        if (token) {
+            // 鑷姩甯︿笂 token
+            jqxhr.setRequestHeader('Authorization', 'Bearer ' + token);
+        }
+
+    });
+
+
+    // 缁熶竴澶勭悊 鏈璇�/鏈巿鏉冭姹�
+    $(document).ajaxComplete(function (event, jqxhr, settings) {
+        // HTTP 鐘舵�佺爜
+        var status = jqxhr.status;
+
+        if (status === 401) {
+            // 鏈櫥褰� / token 杩囨湡
+            layer.confirm('鐧诲綍宸茶繃鏈燂紝璇烽噸鏂扮櫥褰�', { icon: 7, title: '鎻愮ず' }, function () {
+                localStorage.removeItem('token');
+                window.top.location.href = '../../views/user/login.html'; // 璺冲埌鐧诲綍椤�
+
+            });
+        } else if (status === 403) {
+            // 鏃犳潈闄�
+            layui.layer.msg('鎮ㄦ病鏈夎妯″潡鐨勬搷浣滄潈闄�', { icon: 2, time: 2000 });
+        }
+    });
+}

--
Gitblit v1.9.1