From aaaf1808ce52f2b93fd53254e9935750d325f0a6 Mon Sep 17 00:00:00 2001 From: chuguofei <1633295391@qq.com> Date: Wed, 28 Jun 2023 14:48:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WEB-INF/oss/iot/common/variable_js.jsp | 4 +- src/main/webapp/WEB-INF/oss/iot/monitor.jsp | 49 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/main/webapp/WEB-INF/oss/iot/common/variable_js.jsp b/src/main/webapp/WEB-INF/oss/iot/common/variable_js.jsp index 169cac5..bc19438 100644 --- a/src/main/webapp/WEB-INF/oss/iot/common/variable_js.jsp +++ b/src/main/webapp/WEB-INF/oss/iot/common/variable_js.jsp @@ -40,9 +40,11 @@ function debounce(fn, delay) { let time = null; return function () { + let _this = this; + let args = arguments; if (time !== null) clearTimeout(time); time = setTimeout(function () { - fn.call(this); + fn.apply(_this, args); }, delay) } } diff --git a/src/main/webapp/WEB-INF/oss/iot/monitor.jsp b/src/main/webapp/WEB-INF/oss/iot/monitor.jsp index e88c6c1..813841c 100644 --- a/src/main/webapp/WEB-INF/oss/iot/monitor.jsp +++ b/src/main/webapp/WEB-INF/oss/iot/monitor.jsp @@ -455,12 +455,12 @@ function searchDeviceInfo(dataParam, callBack) { postAjax(localUrl + "/page/node/sensor/list.json", dataParam, function (data) { - $(".sceneList-info").empty(); if (isOK(data)) { var dataObj = data.data; if (callBack) { callBack(dataObj) } else { + $(".sceneList-info").empty(); for (var i = 0; i < dataObj.length; i++) { const contentHTML = $("#template0").html().format( dataObj[i].name, @@ -522,7 +522,6 @@ getDisInfo(dataT[i])); } else if (dataT[i].iot_sensor_type == 90) { // gps定位数据 - str += $("#template6").html().format(disvalue(dataT[i].name, 9), dataT[i].iot_sensor_status, timeStamp2String(dataT[i].mtime, 'yyyy/MM/dd hh:mm:ss'), @@ -652,6 +651,23 @@ //客户端 var client; + var sensorChangeFn = debounce(function (params) { + searchDeviceInfo(params, function (result) { + let deviceHTML = ''; + for (let i = 0; i < result.length; i++) { + deviceHTML = getSensorListHtml(result[i].iotSensorList, params.scene_id, result[i].iot_node_status); + } + if (deviceHTML.length > 0) { + const sensorDOM = $(".sceneList-info .sensor_info_container div[id=sensor" + params.sensor_id + "]").parent(); + sensorDOM.hide(); + sensorDOM.after(deviceHTML); + // sensorDOM.next().css('border','2px red solid') + sensorDOM.remove(); + } + }) + }, 1000) + + function mqttInit() { // 连接选项 const options = { @@ -684,31 +700,18 @@ reportFlag = '0' } if (reportFlag == '0') { - if (lastTime + 3 * 1000 < new Date().getTime()) { + if (lastTime + 60 * 5 * 1000 < new Date().getTime()) { reflash(sceneId); lastTime = new Date().getTime(); } } else if (reportFlag == '1' && sensorID != null && sensorID != '') { - debounce(function () { - searchDeviceInfo({ - scene_id: sceneId, - node_data_type: 0, - device_code: device_code, - sensor_id: sensorID, - limit: 1 - }, function (result) { - let deviceHTML = ''; - for (let i = 0; i < result.length; i++) { - deviceHTML = getSensorListHtml(result[i].iotSensorList, sceneId, result[i].iot_node_status); - } - if (deviceHTML.length > 0) { - const sensorDOM = $(".sceneList-info .sensor_info_container div[id=sensor" + sensorID + "]").parent(); - sensorDOM.hide(); - sensorDOM.after(deviceHTML); - sensorDOM.remove(); - } - }) - }, 2000) + sensorChangeFn({ + scene_id: sceneId, + node_data_type: 0, + device_code: device_code, + sensor_id: sensorID, + limit: 1 + }) } } )