From 8edfc33511b93df539e1c5515b696f62f2c0e8f8 Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期一, 21 十一月 2022 15:52:11 +0800
Subject: [PATCH] 修复前端分页bug

---
 widgetsTS/widget_search/view.js |  376 +++++++++++++++++++++++++++--------------------------
 1 files changed, 193 insertions(+), 183 deletions(-)

diff --git a/widgetsTS/widget_search/view.js b/widgetsTS/widget_search/view.js
index 63ced06..ef4924c 100644
--- a/widgetsTS/widget_search/view.js
+++ b/widgetsTS/widget_search/view.js
@@ -4,6 +4,7 @@
 var current_selected_monitor_qindex = "pm25";
 
 var tableData;
+var monitor_type_changed = false;
 
 //瀵瑰簲widget.js涓璏yWidget瀹炰緥鍖栧悗鐨勫璞�
 var thisWidget
@@ -15,12 +16,15 @@
     loadCountByUserid();
 
     $(".cnt_div a").on("click", function () {
-        $(".cnt_div a").removeClass("select_btn"); 
+        $(".cnt_div a").removeClass("select_btn");
         $(this).addClass("select_btn");
+        if (current_selected_monitor_type && current_selected_monitor_type != $(this).attr("_code")) {
+            monitor_type_changed = true;
+        }
         current_selected_monitor_type = $(this).attr("_code");
-        current_selected_monitor_name = $(this).attr("_name");  
+        current_selected_monitor_name = $(this).attr("_name");
         changeQindexSelection();
-    });  
+    });
     //寮�濮嬫煡璇㈡暟鎹�
     $("#btn").click(function () {
         current_selected_monitor_keyword = $('#search').val();
@@ -33,36 +37,36 @@
             current_selected_monitor_keyword = $('#search').val();
             throttling();
         }
-      })
+    })
 
 
-    $("#selectedALL").click(function() { 
-        if (this.checked){ 
-            $("input[name='selectedItem']:checkbox").each(function(){ 
-                  $(this).prop("checked", true);  
+    $("#selectedALL").click(function () {
+        if (this.checked) {
+            $("input[name='selectedItem']:checkbox").each(function () {
+                $(this).prop("checked", true);
             });
-        } else {   
-            $("input[name='selectedItem']:checkbox").each(function() {   
-                  $(this).prop("checked", false);  
+        } else {
+            $("input[name='selectedItem']:checkbox").each(function () {
+                $(this).prop("checked", false);
             });
-        }  
+        }
     });
 }
 
 // 鑺傛祦锛岄槻姝㈢敤鎴风偣鍑诲娆¤姹傚娆�
 let timeout;
 //闇�瑕佸畾涔夊湪鏂规硶澶�
-function throttling(){
-	//鍏堟竻鐞�
-	clearTimeout(timeout)	
-	timeout = setTimeout(() => {
-		reloadData(1)
-	}, 500)
+function throttling() {
+    //鍏堟竻鐞�
+    clearTimeout(timeout)
+    timeout = setTimeout(() => {
+        reloadData(1)
+    }, 500)
 }
 
 //鍔犺浇count
 function loadCountByUserid() {
-    var backend_url = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_all_count_by_id&userid=" + thisWidget.userid ;
+    var backend_url = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_all_count_by_id&userid=" + thisWidget.userid;
     $.ajax({
         type: 'get',
         dataType: 'json',
@@ -86,17 +90,17 @@
         error: function (request, textStatus) {
         }
     });
-    var backend_url_taxi = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_count_all&userid=" + thisWidget.userid ;
+    var backend_url_taxi = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_count_all&userid=" + thisWidget.userid;
     $.ajax({
         type: 'get',
         dataType: 'json',
         data: {},
         async: true,//鍚屾
-        url : backend_url_taxi,
+        url: backend_url_taxi,
         success: function (data) {
             var cntGroup = data.data.result;
             if (cntGroup != null) {
-                for(var i=0;i < cntGroup.length;i++){
+                for (var i = 0; i < cntGroup.length; i++) {
                     var cntobj = cntGroup[i]
                     $("#count_all").text(cntobj.count_all);
                     $("#count_bus").text(cntobj.count_bus);
@@ -150,180 +154,186 @@
 
 }
 
-function reloadData(page){
+function reloadData(page) {
     $("#searchInfo").empty();
     var avgnam = 30; //姣忛〉鏄剧ず涓暟
-    var backend_url = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_" + current_selected_monitor_type + "_list_keyword&datatype=" + thisWidget.datatype 
-            + "&datatime=" + thisWidget.datatime +"&userid=" + thisWidget.userid+ "&qindex=" + current_selected_monitor_qindex 
-            + "&keyword=" + current_selected_monitor_keyword + "&pageno="+page+"&pagesize="+avgnam;
+    if (!monitor_type_changed && tableData) {
+        pageData(tableData, avgnam, page)
+        monitor_type_changed = false;
+    } else {
+        var backend_url = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_" + current_selected_monitor_type + "_list_keyword&datatype=" + thisWidget.datatype
+            + "&datatime=" + thisWidget.datatime + "&userid=" + thisWidget.userid + "&qindex=" + current_selected_monitor_qindex
+            + "&keyword=" + current_selected_monitor_keyword + "&pageno=" + page + "&pagesize=" + avgnam;
         $.ajax({
-          type:"GET",
-          url:backend_url,
-          dataType:"json",
-          success:function(data){
-            tableData = data.data.result;
-            if(current_selected_monitor_keyword == null){
-                haoutil.msg("璇疯緭鍏ュ叧閿瓧锛侊紒锛�")
-                return;
-            }
-            if(tableData == null){
-                haoutil.msg("璇烽�夋嫨鏌ヨ绫诲埆锛侊紒锛�")
-                return;
-            }
-            if(tableData.length == 0){
-                haoutil.msg("鏃犳煡璇㈢粨鏋滐紝璇锋洿鎹㈡煡璇㈡潯浠讹紒")
-                return;
-            }          
-            var newsTotalNum = data.data.result.length; //璁板綍鐨勬�绘潯鏁�
-            console.log(data.data,"鎵�鏈夋暟鎹�")
-            var pageNum = Math.ceil(newsTotalNum/avgnam); //鍒嗛〉鐨勬�婚〉鏁�
-            
-            for(var i=0;i<tableData.length;i++){
-                var j = (page-1)*avgnam + i + 1;
-                var topObj = tableData[i];
-                topObj = changeNullAndundefinedToEmpty(topObj);
-                var content = "<tr _siteid='" + topObj.code + "' _lon='" + topObj.lon + "' _lat='" + topObj.lat + "' onmouseover='over(this)' onmouseout='out(this)' ><td><input id='items' type='checkbox' name='selectedItem' value='" + j + "' /></td><td>" + j + "</td><td onclick='locateAndShowDetail(this)'>" + topObj.code + "</td><td onclick='locateAndShowDetail(this)'>" + topObj.name + "</td><td><font color='" + getLayerPointColorByQindexandValue(current_selected_monitor_type, current_selected_monitor_qindex, topObj[current_selected_monitor_qindex]) + "'>" + topObj[current_selected_monitor_qindex] + "</font></td></tr>"
-                $("#searchInfo").append(content);
-            }
-            var content1 = '<div class="am-cf">' +
-                '鍏� '+newsTotalNum+' 鏉¤褰� / '+pageNum+'椤�' +
-                '</div>';
-            var content2 = '<div class="pageDiv">' + 
-            '<ul class="am-pagination">';
-            // 鍒ゆ柇鍓嶉潰鏄惁杩樻湁椤甸潰
-            if(page == 1){
-                content2 += '<li class="am-disabled"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >芦</a></li>';
-            }else{
-                content2 += '<li><a href="javascript:reloadData('+(page-1)+')" rel="external nofollow" >芦</a></li>';
-            }
-            if (pageNum <= 3 ) {//鎬婚〉鏁板皬浜庝簲椤碉紝鍒欏姞杞芥墍鏈夐〉                
-                for (var i=1; i <= pageNum; i++) {
-                    if (i == page) {
-                        content2 += '<li class="am-active"><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-                    }else{
-                        content2 += '<li><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-                    }
-                };
-                $('#page').append(content2);
-                // return;
-            }else if (pageNum > 3) {//鎬婚〉鏁板ぇ浜庝簲椤碉紝鍒欏姞杞戒簲椤�
-                if (page < 3) {//褰撳墠椤靛皬浜�3锛屽姞杞�1-3椤�
-                    for (var i=1; i <= 3; i++) {
-                        if (i == page) {
-                            content2 += '<li class="am-active"><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-
-                        }else{
-                            content2 += '<li><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-                        }
-                    };
-                    if (page <= pageNum-2) {//鏈�鍚庝竴椤佃拷鍔犫��...鈥濅唬琛ㄧ渷鐣ョ殑椤�
-                        content2 += "<li><a>...</a></li>";
-                    }
-                    $('#page').append(content2);
-                    // return;
-                }else if (page >= 3) {//褰撳墠椤靛ぇ浜�3椤�
-                    for (var i=1; i <= 2; i++) {//1,2椤电爜濮嬬粓鏄剧ず
-                        content2 += '<li><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-                    }
-                    content2 += "<li><a>...</a></li>";//2椤电爜鍚庨潰鐢�...浠f浛閮ㄥ垎鏈樉绀虹殑椤电爜
-                    if (page+1 == pageNum) {//褰撳墠椤�+1绛変簬鎬婚〉鐮�
-                        for(i = page-1; i <= pageNum; i++){//鈥�...鈥濆悗闈㈣窡涓変釜椤电爜褰撳墠椤靛眳涓樉绀�
-                            if (i == page) {
-                                content2 += '<li class="am-active"><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-
-                            }else{
-                                content2 += '<li><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-                            }
-                        }
-                    }else if (page == pageNum) {//褰撳墠椤垫暟绛変簬鎬婚〉鏁板垯鏄渶鍚庝竴椤甸〉鐮佹樉绀哄湪鏈�鍚�
-                        for(var i = page-2; i <= pageNum; i++){//...鍚庨潰璺熶笁涓〉鐮佸綋鍓嶉〉灞呬腑鏄剧ず
-                            if (i == page) {
-                                content2 += '<li class="am-active"><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-
-                            }else{
-                                content2 += '<li><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-                            }
-                        }
-                    }else{//褰撳墠椤靛皬浜庢�婚〉鏁帮紝鍒欐渶鍚庝竴椤靛悗闈㈣窡...
-                        for(var i = page-1; i <= page+1; i++){//dqPage+1椤靛悗闈�...
-                            if (i == page) {
-                                content2 += '<li class="am-active"><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-
-                            }else{
-                                content2 += '<li><a href="javascript:reloadData('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>';
-                            }
-                        }
-                        content2 += "<li><a>...</a></li>";
-                    }
-                    $('#page').append(content2);
-                    // return;
+            type: "GET",
+            url: backend_url,
+            dataType: "json",
+            success: function (data) {
+                tableData = data.data.result;
+                if (current_selected_monitor_keyword == null) {
+                    haoutil.msg("璇疯緭鍏ュ叧閿瓧锛侊紒锛�")
+                    return;
                 }
+                if (tableData == null) {
+                    haoutil.msg("璇烽�夋嫨鏌ヨ绫诲埆锛侊紒锛�")
+                    return;
+                }
+                if (tableData.length == 0) {
+                    haoutil.msg("鏃犳煡璇㈢粨鏋滐紝璇锋洿鎹㈡煡璇㈡潯浠讹紒")
+                    return;
+                }
+                pageData(tableData, avgnam, page);
             }
-            // 鍒ゆ柇鍚庨潰鏄惁杩樻湁椤甸潰
-            if(page == pageNum){
-                content2 += '<li class="am-disabled"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >禄</a></li>';
-            }else{
-                content2 += '<li><a href="javascript:reloadData('+(page+1)+')" rel="external nofollow" >禄</a></li>';
-            }
-            content2 += '</ul>' +
-                  '</div>';
-            $("#pageID").empty();
-            $("#pageID").append(content1);
-            $("#page").empty();
-            $("#page").append(content2);
-          }
         });
     }
+}
 
-      function over(obj) {
-        $('#searchInfo tr').removeClass("over_tr");
-        $(obj).addClass("over_tr");
+function over(obj) {
+    $('#searchInfo tr').removeClass("over_tr");
+    $(obj).addClass("over_tr");
+}
+
+function out(obj) {
+
+    $(obj).removeClass("over_tr");
+}
+
+function locateAndShowDetail(obj) {
+    $('#searchInfo tr').removeClass("select_tr");
+    let parentObj = $(obj).parent();
+
+    $(parentObj).addClass("select_tr");
+    var siteId = $(parentObj).attr("_siteid");
+    var lon = $(parentObj).attr("_lon");
+    var lat = $(parentObj).attr("_lat");
+
+    if (lon && lon != '/') {
+        thisWidget.locateAndHighlight(lon, lat);
     }
-    
-    function out(obj) {
-    
-        $(obj).removeClass("over_tr");
+    if (current_selected_monitor_type != 100500) {
+        thisWidget.showDetailedWindow({ "nodejs_url_predix": thisWidget.nodejs_url_predix, "datatype": thisWidget.datatype, "selected_qindex": current_selected_monitor_qindex, "datatime": thisWidget.datatime, "layerid": current_selected_monitor_type, "siteid": siteId });
     }
-    
-    function locateAndShowDetail(obj) {
-        $('#searchInfo tr').removeClass("select_tr");
-        let parentObj = $(obj).parent();
-    
-        $(parentObj).addClass("select_tr");
-        var siteId = $(parentObj).attr("_siteid");
-        var lon = $(parentObj).attr("_lon");
-        var lat = $(parentObj).attr("_lat");
-    
-        if (lon && lon != '/') {
-            thisWidget.locateAndHighlight(lon, lat);
-        }
-        if (current_selected_monitor_type != 100500) {
-            thisWidget.showDetailedWindow({ "nodejs_url_predix": thisWidget.nodejs_url_predix, "datatype": thisWidget.datatype, "selected_qindex": current_selected_monitor_qindex, "datatime": thisWidget.datatime, "layerid": current_selected_monitor_type, "siteid": siteId });
+}
+
+
+function setTopNname(count) {
+    $("#topN_name").html("Top" + count);
+
+}
+
+function highlightSelected() {
+
+    var obj = document.getElementsByName('selectedItem'); //閫夋嫨鎵�鏈塶ame="'selectedItem'"鐨勫璞★紝杩斿洖鏁扮粍 
+    // var first_value = document.getElementById('items').value; //閫夋嫨鎵�鏈塿alue="'鍊�'
+    var selectedItem = [];
+    for (var i = 0; i < obj.length; ++i) {
+        if (obj[i].checked) {
+            // selectedItem[selectedItem.length] = tableData[i+(first_value-1)];
+            selectedItem[selectedItem.length] = tableData[i];
         }
     }
 
-
-    function setTopNname(count) {
-        $("#topN_name").html("Top" + count);
-    
+    if (selectedItem.length <= 0) {
+        haoutil.msg("璇峰嬀閫�");
+    } else {
+        //console.log(selectedItem);
+        thisWidget.HighlightMulti(current_selected_monitor_type, current_selected_monitor_qindex, selectedItem);
     }
-    
-    function highlightSelected() {
-    
-        var obj = document.getElementsByName('selectedItem'); //閫夋嫨鎵�鏈塶ame="'selectedItem'"鐨勫璞★紝杩斿洖鏁扮粍 
-        // var first_value = document.getElementById('items').value; //閫夋嫨鎵�鏈塿alue="'鍊�'
-        var selectedItem = [];
-        for (var i = 0; i < obj.length; ++i) {
-            if (obj[i].checked) {
-                // selectedItem[selectedItem.length] = tableData[i+(first_value-1)];
-                selectedItem[selectedItem.length] = tableData[i];
+}
+
+function pageData(tableData, avgnam, page) {
+    var newsTotalNum = tableData.length; //璁板綍鐨勬�绘潯鏁�
+    var pageNum = Math.ceil(newsTotalNum / avgnam); //鍒嗛〉鐨勬�婚〉鏁�
+
+    for (var i = (page - 1) * avgnam; i < Math.min(page * avgnam, newsTotalNum); i++) {
+        var j = i + 1;
+        var topObj = tableData[i];
+        topObj = changeNullAndundefinedToEmpty(topObj);
+        var content = "<tr _siteid='" + topObj.code + "' _lon='" + topObj.lon + "' _lat='" + topObj.lat + "' onmouseover='over(this)' onmouseout='out(this)' ><td><input id='items' type='checkbox' name='selectedItem' value='" + j + "' /></td><td>" + j + "</td><td onclick='locateAndShowDetail(this)'>" + topObj.code + "</td><td onclick='locateAndShowDetail(this)'>" + topObj.name + "</td><td><font color='" + getLayerPointColorByQindexandValue(current_selected_monitor_type, current_selected_monitor_qindex, topObj[current_selected_monitor_qindex]) + "'>" + topObj[current_selected_monitor_qindex] + "</font></td></tr>"
+        $("#searchInfo").append(content);
+    }
+    var content1 = '<div class="am-cf">' +
+        '鍏� ' + newsTotalNum + ' 鏉¤褰� / ' + pageNum + '椤�' +
+        '</div>';
+    var content2 = '<div class="pageDiv">' +
+        '<ul class="am-pagination">';
+    // 鍒ゆ柇鍓嶉潰鏄惁杩樻湁椤甸潰
+    if (page == 1) {
+        content2 += '<li class="am-disabled"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >芦</a></li>';
+    } else {
+        content2 += '<li><a href="javascript:reloadData(' + (page - 1) + ')" rel="external nofollow" >芦</a></li>';
+    }
+    if (pageNum <= 3) {//鎬婚〉鏁板皬浜庝簲椤碉紝鍒欏姞杞芥墍鏈夐〉                
+        for (var i = 1; i <= pageNum; i++) {
+            if (i == page) {
+                content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+            } else {
+                content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
             }
+        };
+        $('#page').append(content2);
+        // return;
+    } else if (pageNum > 3) {//鎬婚〉鏁板ぇ浜庝簲椤碉紝鍒欏姞杞戒簲椤�
+        if (page < 3) {//褰撳墠椤靛皬浜�3锛屽姞杞�1-3椤�
+            for (var i = 1; i <= 3; i++) {
+                if (i == page) {
+                    content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+
+                } else {
+                    content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+                }
+            };
+            if (page <= pageNum - 2) {//鏈�鍚庝竴椤佃拷鍔犫��...鈥濅唬琛ㄧ渷鐣ョ殑椤�
+                content2 += "<li><a>...</a></li>";
+            }
+            $('#page').append(content2);
+            // return;
+        } else if (page >= 3) {//褰撳墠椤靛ぇ浜�3椤�
+            for (var i = 1; i <= 2; i++) {//1,2椤电爜濮嬬粓鏄剧ず
+                content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+            }
+            content2 += "<li><a>...</a></li>";//2椤电爜鍚庨潰鐢�...浠f浛閮ㄥ垎鏈樉绀虹殑椤电爜
+            if (page + 1 == pageNum) {//褰撳墠椤�+1绛変簬鎬婚〉鐮�
+                for (i = page - 1; i <= pageNum; i++) {//鈥�...鈥濆悗闈㈣窡涓変釜椤电爜褰撳墠椤靛眳涓樉绀�
+                    if (i == page) {
+                        content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+                    } else {
+                        content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+                    }
+                }
+            } else if (page == pageNum) {//褰撳墠椤垫暟绛変簬鎬婚〉鏁板垯鏄渶鍚庝竴椤甸〉鐮佹樉绀哄湪鏈�鍚�
+                for (var i = page - 2; i <= pageNum; i++) {//...鍚庨潰璺熶笁涓〉鐮佸綋鍓嶉〉灞呬腑鏄剧ず
+                    if (i == page) {
+                        content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+                    } else {
+                        content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+                    }
+                }
+            } else {//褰撳墠椤靛皬浜庢�婚〉鏁帮紝鍒欐渶鍚庝竴椤靛悗闈㈣窡...
+                for (var i = page - 1; i <= page + 1; i++) {//dqPage+1椤靛悗闈�...
+                    if (i == page) {
+                        content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+
+                    } else {
+                        content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
+                    }
+                }
+                content2 += "<li><a>...</a></li>";
+            }
+            $('#page').append(content2);
+            // return;
         }
-    
-        if (selectedItem.length <= 0) {
-            haoutil.msg("璇峰嬀閫�");
-        } else {
-            //console.log(selectedItem);
-            thisWidget.HighlightMulti(current_selected_monitor_type, current_selected_monitor_qindex, selectedItem);
-        }
-    }
\ No newline at end of file
+    }
+    // 鍒ゆ柇鍚庨潰鏄惁杩樻湁椤甸潰
+    if (page == pageNum) {
+        content2 += '<li class="am-disabled"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >禄</a></li>';
+    } else {
+        content2 += '<li><a href="javascript:reloadData(' + (page + 1) + ')" rel="external nofollow" >禄</a></li>';
+    }
+    content2 += '</ul>' +
+        '</div>';
+    $("#pageID").empty();
+    $("#pageID").append(content1);
+    $("#page").empty();
+    $("#page").append(content2);
+}
\ No newline at end of file

--
Gitblit v1.9.1