This commit is contained in:
Iruka 2024-09-27 12:01:15 +08:00
parent 2cb9fbbe34
commit e58cc90113
4 changed files with 66 additions and 30 deletions

29
App.vue
View File

@ -6,9 +6,9 @@
export default { export default {
data() { data() {
return { return {
indexData: new indexUtil(this.deviceChange), // indexData: new indexUtil(this.indexDataHandler), //
dc: new dc(), dc: new dc(),
mqtt: null, mqtt: new mqttUtil(),
mqttObj: { mqttObj: {
topics: [] topics: []
}, },
@ -29,7 +29,6 @@
uni.$on("mqtt-subscribes", topics => { uni.$on("mqtt-subscribes", topics => {
this.mqttSubscribes(); this.mqttSubscribes();
}); });
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')
@ -38,21 +37,29 @@
console.log('App Hide') console.log('App Hide')
}, },
methods: { methods: {
deviceChange(e) { //indexData
console.error("deviceChange", e); indexDataHandler(e, data) {
// console.error("indexDataHandler_1", {
// e: e,
// data: data
// });
if (e == this.indexData.eventType.land) { if (e == this.indexData.eventType.land) {
console.error("地块更新通知") // console.error(":", this.indexData.selectItem)
// this.indexData.getNewDeviceList();
this.dc.setLandItem(this.indexData.selectItem, null);
} }
if (e == this.indexData.eventType.device) { if (e == this.indexData.eventType.device) {
console.error("设备更新通知") // console.error(":", this.indexData.device)
console.error("dexice:", this.indexData.device)
this.dc.setStations(this.indexData.device.stations); this.dc.setStations(this.indexData.device.stations);
this.dc.setFlapValves(this.indexData.device.flapValves); this.dc.setFlapValves(this.indexData.device.flapValves);
this.dc.setValves(this.indexData.selectItem.id, this.indexData.device.waterOutlets); 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() { setTime: function() {
console.error(this.globalData.num); console.error(this.globalData.num);

View File

@ -87,9 +87,15 @@
this.indexData.selectItem = item; this.indexData.selectItem = item;
this.indexData.showIndex = index; this.indexData.showIndex = index;
if (item.id != oldItem.id) { if (item.id != oldItem.id) {
/*
1.设置缓存
2.回调的方式通知改变
3.全局订阅的方式通知改变
4.组件回调的方式通知改变
*/
this.indexData.setStorage(2, item); this.indexData.setStorage(2, item);
this.indexData.onEventHandler(this.indexData.eventType.land); this.indexData.onEventHandler(this.indexData.eventType.land, item);
uni.$emit("notify-update-land"); uni.$emit("notify-update-land", item);
this.$emit("select", item); this.$emit("select", item);
} }
this.close(); this.close();

View File

@ -157,8 +157,8 @@
<view class="iconfont icon-diefa icon"></view> <view class="iconfont icon-diefa icon"></view>
<view class="text">{{ item.rowKey }}</view> <view class="text">{{ item.rowKey }}</view>
<view style="margin:0 10px;">出水口数量</view> <view style="margin:0 10px;">出水口数量</view>
<u-badge numberType="overflow" type="info" max="999" <u-badge numberType="overflow" type="info" showZero max="999"
:value="item.children.length || 0" /> :value="item.children.length" />
</view> </view>
</template> </template>
<view class="u-collapse-content"> <view class="u-collapse-content">
@ -178,7 +178,7 @@
</view> </view>
</u-col> </u-col>
<u-col span="3" style="align-items: flex-end;"> <u-col span="3" style="align-items: flex-end;">
<u-switch v-model="value" @change="change" size="20" <u-switch v-model="value" @change="flapValveChange" size="20"
activeColor="#39ac4f"></u-switch> activeColor="#39ac4f"></u-switch>
</u-col> </u-col>
</u-row> </u-row>
@ -408,7 +408,7 @@
<!-- 弹窗 --> <!-- 弹窗 -->
<view> <view>
<!-- 地块选择 --> <!-- 地块选择 -->
<custom-select-land ref="refLand"></custom-select-land> <custom-select-land ref="refLand" @select="landChange"></custom-select-land>
<!-- 角度 --> <!-- 角度 -->
<custom-angle-slider ref="refAngleSlider" mode="bottom" @close="" @confirm="angleSliderConfirm" /> <custom-angle-slider ref="refAngleSlider" mode="bottom" @close="" @confirm="angleSliderConfirm" />
</view> </view>
@ -425,6 +425,7 @@
indexData: getApp().indexData, indexData: getApp().indexData,
dc: getApp().dc, dc: getApp().dc,
// show: false, // show: false,
isLandChange: false,
} }
}, },
onLoad() { onLoad() {
@ -432,10 +433,9 @@
// uni.$emit("mqtt-link"); // uni.$emit("mqtt-link");
uni.$off("notify-update-land"); uni.$off("notify-update-land");
uni.$on("notify-update-land", () => { uni.$on("notify-update-land", (data) => {
console.error("index监听地块更新") console.error("index监听地块更新", data)
// this.landDataChange = true; this.isLandChange = true;
getApp().indexData.getNewDeviceList();
}); });
}, },
onShow() { onShow() {
@ -443,9 +443,9 @@
plus.screen.lockOrientation("portrait-primary"); plus.screen.lockOrientation("portrait-primary");
plus.navigator.setFullscreen(false); plus.navigator.setFullscreen(false);
// #endif // #endif
this.getDevice();
}, },
onPageScroll(e) { onPageScroll(e) { //
//
// console.log(e.scrollTop); // // console.log(e.scrollTop); //
if (e.scrollTop >= 100) { if (e.scrollTop >= 100) {
this.isSticky = true; this.isSticky = true;
@ -454,24 +454,44 @@
} }
}, },
methods: { methods: {
//
openLand() { openLand() {
this.$refs.refLand.open(); 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() { toList() {
uni.navigateTo({ uni.navigateTo({
url: `/pages/index-list` url: `/pages/index-list`
}) })
}, },
//
toQRCode() {}, toQRCode() {},
//
angleSliderShow() { angleSliderShow() {
this.$refs.refAngleSlider.show("1-1", "①开", 10, { this.$refs.refAngleSlider.show("1-1", "①开", 10, {
// item: e.row, // item: e.row,
// index: e.index, // index: e.index,
}); });
}, },
//
angleSliderConfirm(e) { angleSliderConfirm(e) {
console.error("angleSliderConfirm:", e); console.error("angleSliderConfirm:", e);
}, },

View File

@ -58,7 +58,7 @@ class indexUtil {
if (this.isFirst) { if (this.isFirst) {
this.isFirst = false; this.isFirst = false;
this.getNewLandList(userId); this.getNewLandList(userId);
this.getNewDeviceList(userId);
} }
} }
@ -99,6 +99,7 @@ class indexUtil {
this.setStorage(1, null); this.setStorage(1, null);
} }
this.setStorage(2, this.selectItem); this.setStorage(2, this.selectItem);
this.getNewDeviceList();
} }
// 组织地块数据 // 组织地块数据
@ -197,9 +198,9 @@ class indexUtil {
} else { } else {
device = null; device = null;
} }
console.error("device:", device) // console.error("device:", device)
this.device = device; this.device = device;
this.onEventHandler(this.eventType.device); this.onEventHandler(this.eventType.device, device);
}).catch(error => { }).catch(error => {
commonUtils.toast(error); commonUtils.toast(error);
}) })
@ -211,6 +212,8 @@ class indexUtil {
uni.setStorageSync(constant.lands, data); uni.setStorageSync(constant.lands, data);
} else if (type == 2) { } else if (type == 2) {
uni.setStorageSync(constant.landItem, data); uni.setStorageSync(constant.landItem, data);
} else if (type == 3) {
uni.setStorageSync(constant.device, data);
} else { } else {
commonUtils.toast("数据持久化异常"); commonUtils.toast("数据持久化异常");
} }
@ -221,8 +224,8 @@ class indexUtil {
land: "land", land: "land",
device: "device", device: "device",
} }
onEventHandler(type) { onEventHandler(type, data) {
this.eventHandler(type); this.eventHandler(type, data);
} }
} }
export default indexUtil export default indexUtil