86 lines
2.1 KiB
Vue
86 lines
2.1 KiB
Vue
<script>
|
||
import indexUtil from "@/utils/indexUtil.js"
|
||
import dc from "@/utils/deviceUtil/dc.js"
|
||
import mqttUtil from "@/utils/mqttUtil.js"
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
indexData: new indexUtil(this.indexDataHandler), //全局地块列表管理
|
||
dc: new dc(), // 设备控制类
|
||
mqtt: new mqttUtil(this.mqttMsgHandler), //Mqtt
|
||
}
|
||
},
|
||
globalData: {},
|
||
onLaunch: function() {
|
||
console.log('App Launch')
|
||
// #ifdef H5
|
||
this.mqtt = new mqttUtil();
|
||
// #endif
|
||
|
||
// 监听mqtt连接命令
|
||
uni.$on("mqtt-link", (userId) => {
|
||
this.mqttLink(userId);
|
||
});
|
||
// 监听mqtt连接订阅命令
|
||
uni.$on("mqtt-subscribes", topics => {
|
||
this.mqttSubscribes();
|
||
});
|
||
},
|
||
onShow: function() {
|
||
console.log('App Show')
|
||
},
|
||
onHide: function() {
|
||
console.log('App Hide')
|
||
},
|
||
methods: {
|
||
//监听indexData的回调
|
||
indexDataHandler(e, data) {
|
||
// console.error("indexDataHandler_1:", {
|
||
// e: e,
|
||
// data: data
|
||
// });
|
||
if (e == this.indexData.eventType.land) {
|
||
// console.error("地块更新通知:", this.indexData.selectItem)
|
||
|
||
this.dc.setLandItem(this.indexData.selectItem, null);
|
||
}
|
||
if (e == this.indexData.eventType.device) {
|
||
// console.error("设备更新通知:", this.indexData.device)
|
||
|
||
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);
|
||
}
|
||
uni.hideLoading();
|
||
console.error("indexDataHandler_2:", {
|
||
indexData: this.indexData,
|
||
dc: this.dc,
|
||
})
|
||
},
|
||
//Mqtt连接
|
||
mqttLink(userId) {
|
||
console.error("mqttLink");
|
||
this.mqtt.link(userId);
|
||
},
|
||
//Mqtt断开连接
|
||
mqttEnd() {
|
||
this.mqtt.over();
|
||
},
|
||
//Mqtt消息回调
|
||
mqttMsgHandler(topic, data) {
|
||
console.error("mqttMsgHandler:", {
|
||
topic: topic,
|
||
data: data,
|
||
});
|
||
},
|
||
}
|
||
}
|
||
</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> |