diff --git a/App.vue b/App.vue index 319a02a..f6f507f 100644 --- a/App.vue +++ b/App.vue @@ -42,7 +42,7 @@ }, methods: { // 添加一个消息回调 - addMsgEvent(type, key, callBack) { + on(type, key, callBack) { switch (type) { case "land": //地块消息回调 this.landFun[key] = callBack; @@ -52,6 +52,17 @@ break; } }, + // 删除一个消息回调 + off(type, key) { + switch (type) { + case "land": //地块消息回调 + delete this.landFun[key] + break; + case "mqtt": //mqtt消息回调 + delete this.mqttFun[key] + break; + } + }, // 给某个回调函数发送数据 sendMsgEvent(type, data) { let func = {}; diff --git a/pages/dev-ops/station.vue b/pages/dev-ops/station.vue index a2260d5..c241340 100644 --- a/pages/dev-ops/station.vue +++ b/pages/dev-ops/station.vue @@ -121,7 +121,7 @@ } this.rolaFrequency.range = list; const that = this; - getApp().addMsgEvent("mqtt", "mqtt_devOps_station", function(e) { + getApp().on("mqtt", "mqtt_devOps_station", function(e) { if (e.type == "state") { // that.mqttConnected = e.connected; } else if (e.type == "msg") { @@ -142,7 +142,6 @@ }) } that.dataObj[deviceCode] = obj; - console.error("this.dataObj:", that.dataObj); } } }); @@ -151,11 +150,11 @@ mounted() {}, onUnload() { getApp().mqttUnsubscribes(this.topics); + getApp().off("mqtt", "mqtt_devOps_station") }, methods: { queryList(pageNo, pageSize) { DevOpsApi.getStationList(this.landId).then(res => { - console.error("res:", res); this.$refs.paging.completeByTotal(res.rows); this.mqttSubscribes(res.rows); }); diff --git a/pages/dev-ops/valve.vue b/pages/dev-ops/valve.vue index bf5277b..e5d4bec 100644 --- a/pages/dev-ops/valve.vue +++ b/pages/dev-ops/valve.vue @@ -138,7 +138,7 @@ } this.rolaFrequency.range = list; const that = this; - getApp().addMsgEvent("mqtt", "mqtt_devOps_valve", function(e) { + getApp().on("mqtt", "mqtt_devOps_valve", function(e) { if (e.type == "state") { // that.mqttConnected = e.connected; } else if (e.type == "msg") { @@ -154,20 +154,13 @@ lf: e.data.data.lf, }) } - that.dataObj[deviceCode] = obj; - console.error("this.dataObj:", that.dataObj); - } - if (e.topic.includes("jsy/iot/valveUpdateLoraRes/")) { - const arr = e.topic.split("/"); - const deviceCode = arr[3]; - let obj = that.dataObj[deviceCode] || {}; if (e.data.type == "vlf" && e.data.res == 1) { obj = Object.assign(obj, { lf: e.data.data, }) } + that.dataObj[deviceCode] = obj; - console.error("this.dataObj:", that.dataObj); } } }); @@ -176,6 +169,7 @@ mounted() {}, onUnload() { getApp().mqttUnsubscribes(this.topics); + getApp().off("mqtt", "mqtt_devOps_valve") }, methods: { queryList(pageNo, pageSize) { @@ -189,7 +183,6 @@ let topic = []; rows.forEach(item => { topic.push(`jsy/iot/deviceConfig/${item.device.deviceTypeId}/${item.device.deviceCode}`);//获取配置 - topic.push(`jsy/iot/valveUpdateLoraRes/${item.device.deviceCode}`);//修改频段 }); this.topics = topic; getApp().mqttSubscribes(this.topics); diff --git a/pages/fourmonitor/pest.vue b/pages/fourmonitor/pest.vue index c7f72e0..b58bec9 100644 --- a/pages/fourmonitor/pest.vue +++ b/pages/fourmonitor/pest.vue @@ -253,7 +253,7 @@ let topic = "jsy/iot/push/outProduct/" + this.item.deviceCode; this.topics.push(topic); this.mqttSubscribes(this.topics); - getApp().addMsgEvent("mqtt", "mqtt_head", function(e) { + getApp().on("mqtt", "mqtt_head", function(e) { if (e.type == "state") { this.mqttConnected = e.connected; } else if (e.type == "msg") { @@ -265,6 +265,7 @@ }, onUnload() { this.mqttUnSubscribes(this.topics); + getApp().off("mqtt", "mqtt_head") }, methods: { mqttSubscribes(topics) { diff --git a/pages/fourmonitor/spore.vue b/pages/fourmonitor/spore.vue index 3f1b318..d929a64 100644 --- a/pages/fourmonitor/spore.vue +++ b/pages/fourmonitor/spore.vue @@ -224,7 +224,7 @@ let topic = "jsy/iot/push/outProduct/" + this.item.deviceCode; this.topics.push(topic); this.mqttSubscribes(this.topics); - getApp().addMsgEvent("mqtt", "mqtt_head", function(e) { + getApp().on("mqtt", "mqtt_head", function(e) { if (e.type == "state") { this.mqttConnected = e.connected; } else if (e.type == "msg") { @@ -234,6 +234,9 @@ } } }, + onUnload() { + getApp().off("mqtt", "mqtt_head") + }, methods: { mqttSubscribes(topics) { getApp().mqttSubscribes(topics); diff --git a/pages/fourmonitor/weatherstation.vue b/pages/fourmonitor/weatherstation.vue index 6671240..fa4a79a 100644 --- a/pages/fourmonitor/weatherstation.vue +++ b/pages/fourmonitor/weatherstation.vue @@ -213,7 +213,7 @@ let topic = "jsy/iot/push/outProduct/" + this.item.deviceCode; this.topics.push(topic); this.mqttSubscribes(this.topics); - getApp().addMsgEvent("mqtt", "mqtt_head", function(e) { + getApp().on("mqtt", "mqtt_head", function(e) { if (e.type == "state") { this.mqttConnected = e.connected; } else if (e.type == "msg") { @@ -223,6 +223,9 @@ } } }, + onUnload() { + getApp().off("mqtt", "mqtt_head"); + }, methods: { mqttSubscribes(topics) { getApp().mqttSubscribes(topics); diff --git a/pages/head/fertilizerapplicator/detail.vue b/pages/head/fertilizerapplicator/detail.vue index 0cb7c02..0529db7 100644 --- a/pages/head/fertilizerapplicator/detail.vue +++ b/pages/head/fertilizerapplicator/detail.vue @@ -461,7 +461,7 @@ let topic = "jsy/iot/push/outProduct/" + this.item.deviceCode; this.topics.push(topic) this.mqttSubscribes(this.topics); - getApp().addMsgEvent("mqtt", "mqtt_fertilizer", function(e) { + getApp().on("mqtt", "mqtt_fertilizer", function(e) { if (e.type == "state") { this.mqttConnected = e.connected; } else if (e.type == "msg") { @@ -472,6 +472,7 @@ }, onUnload() { this.mqttUnSubscribes(this.topics); + getApp().off("mqtt", "mqtt_fertilizer") // #ifdef APP-PLUS plus.screen.lockOrientation('portrait-primary') plus.navigator.setFullscreen(false); diff --git a/pages/head/fertilizerapplicator/detailkl.vue b/pages/head/fertilizerapplicator/detailkl.vue index 1e72f7c..5c98b34 100644 --- a/pages/head/fertilizerapplicator/detailkl.vue +++ b/pages/head/fertilizerapplicator/detailkl.vue @@ -405,7 +405,7 @@ let topic = "jsy/iot/push/outProduct/" + this.item.deviceCode; this.topics.push(topic) this.mqttSubscribes(this.topics); - getApp().addMsgEvent("mqtt", "mqtt_fertilizerKL", function(e) { + getApp().on("mqtt", "mqtt_fertilizerKL", function(e) { if (e.type == "state") { this.mqttConnected = e.connected; } else if (e.type == "msg") { @@ -416,6 +416,7 @@ }, onUnload() { this.mqttUnSubscribes(this.topics); + getApp().off("mqtt", "mqtt_fertilizerKL") // #ifdef APP-PLUS plus.screen.lockOrientation('portrait-primary') plus.navigator.setFullscreen(false); diff --git a/pages/head/headdevice/detail.vue b/pages/head/headdevice/detail.vue index 6bbc5b4..238ff7d 100644 --- a/pages/head/headdevice/detail.vue +++ b/pages/head/headdevice/detail.vue @@ -351,7 +351,7 @@ let topic = "jsy/iot/push/outProduct/" + this.item.deviceCode; this.topics.push(topic); this.mqttSubscribes(this.topics); - getApp().addMsgEvent("mqtt", "mqtt_head", function(e) { + getApp().on("mqtt", "mqtt_head", function(e) { if (e.type == "state") { this.mqttConnected = e.connected; } else if (e.type == "msg") { @@ -363,6 +363,7 @@ }, onUnload() { this.mqttUnSubscribes(this.topics); + getApp().off("mqtt", "mqtt_head") // #ifdef APP-PLUS plus.screen.lockOrientation('portrait-primary') plus.navigator.setFullscreen(false); diff --git a/pages/index-map.vue b/pages/index-map.vue index 5470ba4..de39ca5 100644 --- a/pages/index-map.vue +++ b/pages/index-map.vue @@ -450,14 +450,14 @@ }, onLoad() { const that = this; - getApp().addMsgEvent("mqtt", "mqtt_map", function(e) { + getApp().on("mqtt", "mqtt_map", function(e) { if (e.type == "state") { that.mqttConnected = e.connected; } else if (e.type == "msg") { that.mapUpdateMarker(e.data); } }); - getApp().addMsgEvent("land", "land_map", function(e) { + getApp().on("land", "land_map", function(e) { this.mapOnload(); }); }, diff --git a/pages/index.vue b/pages/index.vue index 3c365fe..eef2d0a 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -581,12 +581,12 @@ }, onLoad() { const that = this; - getApp().addMsgEvent("mqtt", "mqtt_index", function(e) { + getApp().on("mqtt", "mqtt_index", function(e) { if (e.type == "state") { that.mqttConnected = e.connected; } else if (e.type == "msg") {} }); - getApp().addMsgEvent("land", "land_index", function(e) {}); + getApp().on("land", "land_index", function(e) {}); }, onShow() { this.title = this.ijs?.land?.landName || "田间";