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 bc19438..7da1fca 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 @@ -48,6 +48,22 @@ }, delay) } } + + function throttle(fn, delay) { + let _this, args; + let previous = 0; + return function () { + let now = +new Date(); + _this = this; + args = arguments; + if (now - previous > delay) { + fn.apply(_this, args); + previous = now; + } + } + } + + <%=ProConfig.PROJECT_NAME%> \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/oss/iot/monitor.jsp b/src/main/webapp/WEB-INF/oss/iot/monitor.jsp index cced03f..4b14763 100644 --- a/src/main/webapp/WEB-INF/oss/iot/monitor.jsp +++ b/src/main/webapp/WEB-INF/oss/iot/monitor.jsp @@ -651,7 +651,7 @@ //客户端 var client; - var sensorChangeFn = debounce(function (params) { + var sensorChangeDebounceFn = debounce(function (params) { searchDeviceInfo(params, function (result) { let deviceHTML = ''; for (let i = 0; i < result.length; i++) { @@ -667,6 +667,10 @@ }) }, 1000) + var sensorChangeThrottleFn = throttle(function (sceneId) { + reflash(sceneId); + }, 1000) + function mqttInit() { // 连接选项 @@ -700,12 +704,9 @@ reportFlag = '0' } if (reportFlag == '0') { - if (lastTime + 3 * 1000 < new Date().getTime()) { - reflash(sceneId); - lastTime = new Date().getTime(); - } + sensorChangeThrottleFn(sceneId); } else if (reportFlag == '1' && sensorID != null && sensorID != '') { - sensorChangeFn({ + sensorChangeDebounceFn({ scene_id: sceneId, node_data_type: 0, device_code: device_code,