jsy-app/App.vue

122 lines
3.0 KiB
Vue
Raw Normal View History

2024-09-18 10:30:10 +08:00
<script>
2024-11-27 18:46:21 +08:00
import indexUtil from "@/utils/indexUtil/index.js"
import {
deviceControl,
dcMsgType,
dcEventType
} from "@/utils/indexUtil/dc.js"
2024-09-18 10:30:10 +08:00
import mqttUtil from "@/utils/mqttUtil.js"
export default {
data() {
return {
2024-11-27 18:46:21 +08:00
ijs: new indexUtil(), //全局地块列表管理
2024-12-03 17:58:07 +08:00
dc: new deviceControl(2, this.dcEventHandler), // 设备控制类
2024-09-27 18:48:24 +08:00
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')
2024-11-29 15:09:33 +08:00
const that = this;
2024-11-27 18:46:21 +08:00
uni.$off("notify-update-land");
uni.$on("notify-update-land", (data) => {
2024-11-29 15:09:33 +08:00
// console.error("index监听地块更新", data)
2024-11-27 18:46:21 +08:00
// uni.$emit("index-showLoading", true);
uni.showLoading();
2024-11-29 15:09:33 +08:00
that.getWoList(data, null);
2024-11-27 18:46:21 +08:00
});
2024-09-18 10:30:10 +08:00
},
onHide: function() {
console.log('App Hide')
},
methods: {
2024-11-29 15:09:33 +08:00
getWoList(land, wo) {
const that = this;
if (land && wo) {
that.dc.setData(land, wo);
}
that.ijs.getWoList(land).then(res => {
that.dc.setData(land, res.data);
2024-12-17 18:55:04 +08:00
uni.$emit("update-land-index", res.data)
uni.$emit("update-land-indexMap", res.data)
2024-11-29 15:09:33 +08:00
uni.hideLoading();
}).catch(() => {
uni.hideLoading();
});
},
2024-11-27 18:46:21 +08:00
dcEventHandler(type, params, item) {
switch (type) {
case dcEventType.interface: // 界面操作
uni.$emit("open-angle-slider", params)
break;
case dcEventType.refresh: // 命令刷新设备
2024-12-03 12:38:13 +08:00
this.ijs.sendDeviceRefresh(item, params).then(res => {}).catch(error => {
this.dc.clearRefreshCountdown(params.deviceCode);
});
2024-11-27 18:46:21 +08:00
break;
case dcEventType.refreshApi: // 接口刷新阀门
break;
case dcEventType.send: // 命令控制设备
this.ijs.sendDeviceControl(params);
break;
default:
// 消息通知
if (params.success == dcMsgType.ok) {
this.$modal.msgSuccess(params.message);
} else if (params.success == dcMsgType.err) {
this.$modal.msgError(params.message);
} else {
this.$modal.msgWarning(params.message);
}
break;
2024-09-26 18:52:14 +08:00
}
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-11-27 18:46:21 +08:00
mqttSubscribes(topic) {
if (topic) {
this.mqtt.subscribes(topic);
} else {
const topic = this.dc.topic;
if (topic.newV.length) {
2024-11-29 15:09:33 +08:00
this.mqtt.subscribes(topic.newV);
2024-11-27 18:46:21 +08:00
}
if (topic.oldV.length) {
2024-11-29 15:09:33 +08:00
this.mqtt.subscribes(topic.oldV);
2024-11-27 18:46:21 +08:00
}
}
2024-09-30 10:23:30 +08:00
},
2024-09-30 15:34:20 +08:00
//Mqtt取消订阅
2024-11-27 18:46:21 +08:00
mqttUnsubscribes(topic) {
this.mqtt.unsubscribes(topic);
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,
2024-11-27 18:46:21 +08:00
data: JSON.parse(data),
2024-09-27 18:48:24 +08:00
});
2024-11-27 18:46:21 +08:00
this.dc.handleMessage(topic, JSON.parse(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>