fix: 修复show.html中获取不到函数问题

dev
chuguofei 2023-06-30 11:26:30 +08:00
parent 2d20ae168b
commit a920785004
1 changed files with 34 additions and 6 deletions

View File

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