From 1929d432a9cf73c55a2eced06f7d76ecfe07df4c Mon Sep 17 00:00:00 2001
From: wtt <1985833171@qq.com>
Date: 星期四, 10 四月 2025 10:00:49 +0800
Subject: [PATCH] tableSelect加载优化减少接口访问次数

---
 WebTM/layuiadmin/modules/tableSelect.js |   78 +++++++--------------------------------
 1 files changed, 14 insertions(+), 64 deletions(-)

diff --git a/WebTM/layuiadmin/modules/tableSelect.js b/WebTM/layuiadmin/modules/tableSelect.js
index 04b4964..6d7fa06 100644
--- a/WebTM/layuiadmin/modules/tableSelect.js
+++ b/WebTM/layuiadmin/modules/tableSelect.js
@@ -25,6 +25,7 @@
         opt.table.height = opt.table.height || 290;
         elem.off('keyup').on('keyup', function(e) {
             e.stopPropagation();
+            //杈撳叆瀛楃灏忎簬浜屾垨鑰呯壒娈婃寜閽笉鏄剧ず
             if ($('div.tableSelect').length >= 1 || elem.val().length <= 2 || event.key == "F7" || event.key == "F8" || event.key == "F6") {
                 return false;
             }
@@ -44,10 +45,15 @@
             opt.table.elem = "#"+tableName;
             opt.table.id = tableName;
             //鑻ユ病鏈塽rl琛ㄧず涓哄墠绔垎椤�
-            if (opt.table.url != undefined) {
-                opt.table.where['sWhere'] = opt.sWhere
-            } else {
-                opt.table.data = opt.ajaxSelect(opt.sWhere);
+            //if (opt.table.url != undefined) {
+            //    opt.table.where['sWhere'] = opt.sWhere
+            //} else {
+            //    opt.table.data = opt.ajaxSelect(opt.sWhere);
+            //}
+            //璁╀竴娆″姞杞芥樉绀烘暟鎹�
+            //褰撳瓧绗﹂暱搴︾瓑浜�3鏃剁涓�娆″姞杞�
+            if (elem.val().length == 3) {
+                searchFirst()
             }
             opt.table.request={//璁剧疆椤靛弬鏁�
                 pageName: 'page', // 椤电爜鐨勫弬鏁板悕绉帮紝榛樿锛歱age
@@ -61,56 +67,8 @@
                     "data": res.data // 瑙f瀽鏁版嵁鍒楄〃
                 };
             }
-            //鐢╦ump鏇夸唬鍘熸潵琛ㄦ牸pagejump鐢ㄤ簬鏇存柊鎸夐挳閫変腑鏁伴噺姝ゅ姛鑳藉彂鐜版棤鐢ㄥ垹闄�
-            //opt.table.done = function (res, curr, count, origin) {
-            //    this.page.jump = jump;
-            //}
 
             var tableSelect_table = table.render(opt.table);
-            //璁╀竴娆″姞杞芥樉绀烘暟鎹�
-            let executed = false;
-            if (elem.val().length == 3 && !executed) {
-                executed = true;
-                search();
-            }
-            //jump鍒嗛〉瑙﹀彂鍑芥暟
-            //function jump(obj, first) {
-            //    table.reload(tableName);
-            //    //鏇存柊鎸夐挳
-            //    updataButton(table.checkStatus(tableName).data.length)
-            //}
-
-			//鏇存柊閫変腑鏁伴噺
-			function updataButton (n) {
-				tableBox.find('.tableSelect_btn_select span').html(n==0?'':'('+n+')')
-            }
-            
-            //鏁扮粍鍘婚噸
-			function uniqueObjArray(arr, type){
-                var newArr = [];
-                var tArr = [];
-                if(arr.length == 0){
-                    return arr;
-                }else{
-                    if(type){
-                        for(var i=0;i<arr.length;i++){
-                            if(!tArr[arr[i][type]]){
-                                newArr.push(arr[i]);
-                                tArr[arr[i][type]] = true;
-                            }
-                        }
-                        return newArr;
-                    }else{
-                        for(var i=0;i<arr.length;i++){
-                            if(!tArr[arr[i]]){
-                                newArr.push(arr[i]);
-                                tArr[arr[i]] = true;
-                            }
-                        }
-                        return newArr;
-                    }
-                }
-            }
 
 			//FIX浣嶇疆濡備綍涓嬮潰鏀句笉涓嬫斁涓婇潰
 			var overHeight = (elem.offset().top + elem.outerHeight() + tableBox.outerHeight() - $(window).scrollTop()) > $(window).height();
@@ -181,8 +139,8 @@
                     timeout = setTimeout(() => func.apply(context, args), wait);
                 };
             }
-            //鎼滅储鍑芥暟
-            function search() {
+            //鎼滅储鍑芥暟绗竴娆″姞杞�
+            function searchFirst() {
                 var searchKeyList = opt.searchKey.split(',');//鑾峰彇鏌ユ壘鐨勫叧閿瓧鎼滅储妗�
                 //鎷兼帴sql瀛楃涓�
                 var sWhereStr = " and ("
@@ -197,17 +155,9 @@
                 //鍚庣鍒嗛〉鎼滅储
                 if (opt.table.where != undefined) {
                     opt.table.where['sWhere'] = opt.sWhere + sWhereStr;
-                    tableSelect_table.reload({
-                        where: opt.table.where,
-                        page: {
-                            curr: 1
-                        }
-                    });
                 } else {
                     var sWhere = opt.sWhere + sWhereStr;
-                    tableSelect_table.reload({
-                        data: opt.ajaxSelect(sWhere)
-                    });
+                    opt.table.data = opt.ajaxSelect(sWhere);
                 }
             }
 
@@ -243,7 +193,7 @@
                     });
                 }
                 
-            },200))
+            },500))
 
             //鍙屽嚮琛岄�変腑
             table.on('rowDouble('+tableName+')', function(obj){

--
Gitblit v1.9.1