fix: 监控增加节流控制

dev
chuguofei 2023-06-29 18:59:24 +08:00
parent 4ca9f12947
commit 34f95abfee
2 changed files with 23 additions and 6 deletions

View File

@ -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;
}
}
}
</script>
<title><%=ProConfig.PROJECT_NAME%>
</title>

View File

@ -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,