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-26 18:52:14 +08:00
|
|
|
|
indexData: new indexUtil(this.deviceChange), //全局地块列表管理
|
|
|
|
|
dc: new dc(),
|
2024-09-18 10:30:10 +08:00
|
|
|
|
mqtt: null,
|
|
|
|
|
mqttObj: {
|
|
|
|
|
topics: []
|
2024-09-25 18:47:15 +08:00
|
|
|
|
},
|
2024-09-18 10:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
globalData: {},
|
|
|
|
|
onLaunch: function() {
|
|
|
|
|
console.log('App Launch')
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
this.mqtt = new mqttUtil();
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
// 监听mqtt连接命令
|
|
|
|
|
uni.$on("mqtt-link", () => {
|
|
|
|
|
this.mqttLink();
|
|
|
|
|
});
|
|
|
|
|
// 监听mqtt连接订阅命令
|
|
|
|
|
uni.$on("mqtt-subscribes", topics => {
|
|
|
|
|
this.mqttSubscribes();
|
|
|
|
|
});
|
2024-09-25 18:47:15 +08:00
|
|
|
|
|
2024-09-18 10:30:10 +08:00
|
|
|
|
},
|
|
|
|
|
onShow: function() {
|
|
|
|
|
console.log('App Show')
|
|
|
|
|
},
|
|
|
|
|
onHide: function() {
|
|
|
|
|
console.log('App Hide')
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2024-09-26 18:52:14 +08:00
|
|
|
|
deviceChange(e) {
|
|
|
|
|
console.error("deviceChange:", e);
|
|
|
|
|
if (e == this.indexData.eventType.land) {
|
|
|
|
|
console.error("地块更新通知")
|
|
|
|
|
// this.indexData.getNewDeviceList();
|
|
|
|
|
}
|
|
|
|
|
if (e == this.indexData.eventType.device) {
|
|
|
|
|
console.error("设备更新通知")
|
|
|
|
|
console.error("dexice:", 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);
|
|
|
|
|
|
|
|
|
|
console.error("this.dc:",this.dc)
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-09-18 10:30:10 +08:00
|
|
|
|
setTime: function() {
|
|
|
|
|
console.error(this.globalData.num);
|
|
|
|
|
// setTimeout(() => {
|
|
|
|
|
// this.globalData.num++
|
|
|
|
|
// console.error(this.globalData.num);
|
|
|
|
|
// this.setTime();
|
|
|
|
|
// }, 1000)
|
|
|
|
|
},
|
|
|
|
|
mqttLink() {
|
|
|
|
|
// 处理 wx.connectSocket promisify 兼容问题,强制返回 SocketTask
|
|
|
|
|
uni.connectSocket = (function(connectSocket) {
|
|
|
|
|
return function(options) {
|
|
|
|
|
console.log(options)
|
|
|
|
|
options.success = options.success || function() {}
|
|
|
|
|
return connectSocket.call(this, options)
|
|
|
|
|
}
|
|
|
|
|
})(uni.connectSocket)
|
|
|
|
|
|
|
|
|
|
console.error("mqttLink");
|
|
|
|
|
// #ifdef H5
|
|
|
|
|
this.mqtt.link();
|
|
|
|
|
this.mqtt.client.on("connect", error => {
|
|
|
|
|
console.log("连接成功")
|
|
|
|
|
console.error("client:", this.mqtt.client);
|
|
|
|
|
})
|
|
|
|
|
this.mqtt.client.on("error", error => {
|
|
|
|
|
console.log("连接异常")
|
|
|
|
|
})
|
|
|
|
|
this.mqtt.client.on("reconnect", error => {
|
|
|
|
|
console.log("重新连接")
|
|
|
|
|
})
|
|
|
|
|
this.mqtt.client.on("message", (topic, message) => {
|
|
|
|
|
console.log("接受消息")
|
|
|
|
|
console.log("message:", message.toString())
|
|
|
|
|
this.mqttSendMsg(message);
|
|
|
|
|
})
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
mqttSubscribes(topics) {
|
|
|
|
|
this.mqttObj.topics = topics;
|
|
|
|
|
console.error("mqttSubscribes:", topics);
|
|
|
|
|
},
|
|
|
|
|
mqttSendMsg(msg) {
|
|
|
|
|
uni.$emit("mqtt-msg", msg);
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</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>
|