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')
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
this.mqtt = new mqttUtil();
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// 监听mqtt连接命令
|
2024-09-27 18:48:24 +08:00
|
|
|
|
uni.$on("mqtt-link", (userId) => {
|
|
|
|
|
this.mqttLink(userId);
|
2024-09-18 10:30:10 +08:00
|
|
|
|
});
|
|
|
|
|
// 监听mqtt连接订阅命令
|
|
|
|
|
uni.$on("mqtt-subscribes", topics => {
|
|
|
|
|
this.mqttSubscribes();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
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) {
|
|
|
|
|
// console.error("indexDataHandler_1:", {
|
|
|
|
|
// e: e,
|
|
|
|
|
// data: 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-27 12:01:15 +08:00
|
|
|
|
uni.hideLoading();
|
2024-09-27 18:48:24 +08:00
|
|
|
|
console.error("indexDataHandler_2:", {
|
|
|
|
|
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) {
|
2024-09-18 10:30:10 +08:00
|
|
|
|
console.error("mqttLink");
|
2024-09-27 18:48:24 +08:00
|
|
|
|
this.mqtt.link(userId);
|
2024-09-18 10:30:10 +08:00
|
|
|
|
},
|
2024-09-27 18:48:24 +08:00
|
|
|
|
//Mqtt断开连接
|
|
|
|
|
mqttEnd() {
|
|
|
|
|
this.mqtt.over();
|
2024-09-18 10:30:10 +08:00
|
|
|
|
},
|
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>
|