From e58cc90113d35aa8e43a6410448a9d45c23188b0 Mon Sep 17 00:00:00 2001
From: Iruka <1017819588@qq.com>
Date: Fri, 27 Sep 2024 12:01:15 +0800
Subject: [PATCH] .
---
App.vue | 29 +++++++-----
.../custom-select-land/custom-select-land.vue | 10 ++++-
pages/index.vue | 44 ++++++++++++++-----
utils/indexUtil.js | 13 +++---
4 files changed, 66 insertions(+), 30 deletions(-)
diff --git a/App.vue b/App.vue
index 26180e8..8190690 100644
--- a/App.vue
+++ b/App.vue
@@ -6,9 +6,9 @@
export default {
data() {
return {
- indexData: new indexUtil(this.deviceChange), //全局地块列表管理
+ indexData: new indexUtil(this.indexDataHandler), //全局地块列表管理
dc: new dc(),
- mqtt: null,
+ mqtt: new mqttUtil(),
mqttObj: {
topics: []
},
@@ -29,7 +29,6 @@
uni.$on("mqtt-subscribes", topics => {
this.mqttSubscribes();
});
-
},
onShow: function() {
console.log('App Show')
@@ -38,21 +37,29 @@
console.log('App Hide')
},
methods: {
- deviceChange(e) {
- console.error("deviceChange:", e);
+ //监听indexData的回调
+ indexDataHandler(e, data) {
+ // console.error("indexDataHandler_1:", {
+ // e: e,
+ // data: data
+ // });
if (e == this.indexData.eventType.land) {
- console.error("地块更新通知")
- // this.indexData.getNewDeviceList();
+ // console.error("地块更新通知:", this.indexData.selectItem)
+
+ this.dc.setLandItem(this.indexData.selectItem, null);
}
if (e == this.indexData.eventType.device) {
- console.error("设备更新通知")
- console.error("dexice:", this.indexData.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);
-
- console.error("this.dc:",this.dc)
}
+ uni.hideLoading();
+ // console.error("indexDataHandler_2:", {
+ // indexData: this.indexData,
+ // dc: this.dc,
+ // })
},
setTime: function() {
console.error(this.globalData.num);
diff --git a/components/custom-select-land/custom-select-land.vue b/components/custom-select-land/custom-select-land.vue
index 6dcdfea..644c280 100644
--- a/components/custom-select-land/custom-select-land.vue
+++ b/components/custom-select-land/custom-select-land.vue
@@ -87,9 +87,15 @@
this.indexData.selectItem = item;
this.indexData.showIndex = index;
if (item.id != oldItem.id) {
+ /*
+ 1.设置缓存
+ 2.回调的方式通知改变
+ 3.全局订阅的方式通知改变
+ 4.组件回调的方式通知改变
+ */
this.indexData.setStorage(2, item);
- this.indexData.onEventHandler(this.indexData.eventType.land);
- uni.$emit("notify-update-land");
+ this.indexData.onEventHandler(this.indexData.eventType.land, item);
+ uni.$emit("notify-update-land", item);
this.$emit("select", item);
}
this.close();
diff --git a/pages/index.vue b/pages/index.vue
index 8895bfd..db0dc5f 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -157,8 +157,8 @@
{{ item.rowKey }}
出水口数量
-
+
@@ -178,7 +178,7 @@
-
@@ -408,7 +408,7 @@
-
+
@@ -425,6 +425,7 @@
indexData: getApp().indexData,
dc: getApp().dc,
// show: false,
+ isLandChange: false,
}
},
onLoad() {
@@ -432,10 +433,9 @@
// uni.$emit("mqtt-link");
uni.$off("notify-update-land");
- uni.$on("notify-update-land", () => {
- console.error("index监听地块更新")
- // this.landDataChange = true;
- getApp().indexData.getNewDeviceList();
+ uni.$on("notify-update-land", (data) => {
+ console.error("index监听地块更新:", data)
+ this.isLandChange = true;
});
},
onShow() {
@@ -443,9 +443,9 @@
plus.screen.lockOrientation("portrait-primary");
plus.navigator.setFullscreen(false);
// #endif
+ this.getDevice();
},
- onPageScroll(e) {
- // 页面滚动触发事件的处理函数
+ onPageScroll(e) { // 页面滚动触发事件的处理函数
// console.log(e.scrollTop); // 输出滚动位置的垂直距离
if (e.scrollTop >= 100) {
this.isSticky = true;
@@ -454,24 +454,44 @@
}
},
methods: {
+ //打开地块
openLand() {
this.$refs.refLand.open();
},
- change(e) {
- console.log('change', e);
+ //地块选择回调
+ landChange(e) {
+ this.isLandChange = true;
+ this.getDevice();
},
+ //更新设备列表
+ getDevice() {
+ if (this.isLandChange) {
+ console.error('getDevice_index_开始更新地块');
+ uni.showLoading();
+ getApp().indexData.getNewDeviceList();
+ this.isLandChange = false;
+ }
+ },
+ //蝶阀按钮切换
+ flapValveChange(e) {
+ console.error('flapValveChange', e);
+ },
+ //去列表
toList() {
uni.navigateTo({
url: `/pages/index-list`
})
},
+ //去扫码
toQRCode() {},
+ //显示角度弹框
angleSliderShow() {
this.$refs.refAngleSlider.show("1-1", "①开", 10, {
// item: e.row,
// index: e.index,
});
},
+ //显示角度弹框确认
angleSliderConfirm(e) {
console.error("angleSliderConfirm:", e);
},
diff --git a/utils/indexUtil.js b/utils/indexUtil.js
index d47d95a..13c9620 100644
--- a/utils/indexUtil.js
+++ b/utils/indexUtil.js
@@ -58,7 +58,7 @@ class indexUtil {
if (this.isFirst) {
this.isFirst = false;
this.getNewLandList(userId);
- this.getNewDeviceList(userId);
+
}
}
@@ -99,6 +99,7 @@ class indexUtil {
this.setStorage(1, null);
}
this.setStorage(2, this.selectItem);
+ this.getNewDeviceList();
}
// 组织地块数据
@@ -197,9 +198,9 @@ class indexUtil {
} else {
device = null;
}
- console.error("device:", device)
+ // console.error("device:", device)
this.device = device;
- this.onEventHandler(this.eventType.device);
+ this.onEventHandler(this.eventType.device, device);
}).catch(error => {
commonUtils.toast(error);
})
@@ -211,6 +212,8 @@ class indexUtil {
uni.setStorageSync(constant.lands, data);
} else if (type == 2) {
uni.setStorageSync(constant.landItem, data);
+ } else if (type == 3) {
+ uni.setStorageSync(constant.device, data);
} else {
commonUtils.toast("数据持久化异常");
}
@@ -221,8 +224,8 @@ class indexUtil {
land: "land",
device: "device",
}
- onEventHandler(type) {
- this.eventHandler(type);
+ onEventHandler(type, data) {
+ this.eventHandler(type, data);
}
}
export default indexUtil
\ No newline at end of file