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']; }