From a92078500468d99b297d5b511f6a97ae22977a0e Mon Sep 17 00:00:00 2001 From: chuguofei <1633295391@qq.com> Date: Fri, 30 Jun 2023 11:26:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dshow.html=E4=B8=AD?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=E5=87=BD=E6=95=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/webapp/page/visual/show.html | 40 +++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/webapp/page/visual/show.html b/src/main/webapp/page/visual/show.html index 14965ee..225f07c 100644 --- a/src/main/webapp/page/visual/show.html +++ b/src/main/webapp/page/visual/show.html @@ -55,6 +55,33 @@ if (ucode1 != null && ucode1 != '') { ucode = ucode1 } + + function debounce(fn, delay) { + let time = null; + return function () { + let _this = this; + let args = arguments; + if (time !== null) clearTimeout(time); + time = setTimeout(function () { + fn.apply(_this, args); + }, 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; + } + } + } + // console.log("show html with [%s]", userKey) window.var app = new Vue({ @@ -198,17 +225,19 @@ $("body").css("background-position", "center top"); } }, - refreshDataFn: window.parent.debounce(function () { + refreshDataFn: debounce(function () { udpChartValue(); initSensorData(); initControlNode(); initStateNode(); initDeviceStatus(); }, 3000), - issueRefreshDataFn: window.parent.throttle(function (sensorID) { + issueRefreshDataFn: throttle(function (sensorID) { initSensorData(sensorID); initControlNode(sensorID); }, 2000), + + mqttInit() { var that = this; // 连接选项 @@ -230,11 +259,10 @@ console.log('连接失败:', error) }) client.on('message', function (topic, message, s) { - let reportFlag = message.toString(); - let sensorID = null; + message = JSON.parse(message) + let reportFlag,sensorID = null; - if (window.parent.throttle && Object.prototype.toString.call(window.parent.throttle) == '[object Function]') { - message = window.parent.uint8ArrayToJSON(message); + if (Object.prototype.toString.call(message) == '[object Object]') { reportFlag = message['report_flag']; sensorID = message['sensor_id']; }