jsy-app/App.vue

93 lines
2.4 KiB
Vue
Raw Permalink Normal View History

2024-09-18 10:30:10 +08:00
<script>
2024-09-26 12:42:59 +08:00
import indexUtil from "@/utils/indexUtil.js"
2024-09-26 18:52:14 +08:00
import dc from "@/utils/deviceUtil/dc.js"
2024-09-18 10:30:10 +08:00
import mqttUtil from "@/utils/mqttUtil.js"
export default {
data() {
return {
2024-09-27 12:01:15 +08:00
indexData: new indexUtil(this.indexDataHandler), //全局地块列表管理
2024-09-27 18:48:24 +08:00
dc: new dc(), // 设备控制类
mqtt: new mqttUtil(this.mqttMsgHandler), //Mqtt
2024-09-18 10:30:10 +08:00
}
},
globalData: {},
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
methods: {
2024-09-27 12:01:15 +08:00
//监听indexData的回调
indexDataHandler(e, data) {
2024-09-26 18:52:14 +08:00
if (e == this.indexData.eventType.land) {
2024-09-27 12:01:15 +08:00
// console.error("地块更新通知:", this.indexData.selectItem)
this.dc.setLandItem(this.indexData.selectItem, null);
2024-09-26 18:52:14 +08:00
}
if (e == this.indexData.eventType.device) {
2024-09-27 12:01:15 +08:00
// console.error("设备更新通知:", this.indexData.device)
2024-09-26 18:52:14 +08:00
this.dc.setStations(this.indexData.device.stations);
this.dc.setFlapValves(this.indexData.device.flapValves);
this.dc.setValves(this.indexData.selectItem.id, this.indexData.device.waterOutlets);
2024-09-30 15:34:20 +08:00
const obj = this.dc.topic;
if (obj.newV && obj.newV.length) {
this.mqttSubscribes(obj.newV); //订阅主题
}
if (obj.oldV && obj.oldV.length) {
this.mqttUnsubscribes(obj.oldV); //取消订阅主题
}
this.indexData.setStorage(3, {
userId: this.indexData.userId,
landId: this.indexData.selectItem.id,
stations: this.dc.stations,
flapValves: this.dc.flapValves,
waterOutlets: this.dc.valves,
});
2024-09-26 18:52:14 +08:00
}
2024-09-27 12:01:15 +08:00
uni.hideLoading();
2024-09-30 15:34:20 +08:00
// console.error("indexDataHandler:", {
2024-09-30 10:23:30 +08:00
// e: e,
// data: data,
// indexData: this.indexData,
// dc: this.dc,
// })
2024-09-18 10:30:10 +08:00
},
2024-09-27 18:48:24 +08:00
//Mqtt连接
mqttLink(userId) {
this.mqtt.link(userId);
2024-09-18 10:30:10 +08:00
},
2024-09-30 15:34:20 +08:00
//Mqtt订阅
2024-09-30 10:23:30 +08:00
mqttSubscribes(topics) {
this.mqtt.subscribes(topics);
},
2024-09-30 15:34:20 +08:00
//Mqtt取消订阅
2024-09-30 10:23:30 +08:00
mqttUnsubscribes(topics) {
this.mqtt.unsubscribes(topics);
2024-09-18 10:30:10 +08:00
},
2024-09-30 15:34:20 +08:00
//Mqtt断开连接
mqttEnd() {
this.mqtt.over();
},
2024-09-27 18:48:24 +08:00
//Mqtt消息回调
mqttMsgHandler(topic, data) {
console.error("mqttMsgHandler:", {
topic: topic,
data: data,
});
2024-09-18 10:30:10 +08:00
},
}
}
</script>
<style lang="scss">
@import '@/uni_modules/uview-plus/index.scss';
@import '@/static/scss/index.scss';
@import '@/static/alifont/iconfont.css';
@import '@/static/scss/app.css';
</style>