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 {
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);

View File

@ -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();

View File

@ -157,8 +157,8 @@
<view class="iconfont icon-diefa icon"></view>
<view class="text">{{ item.rowKey }}</view>
<view style="margin:0 10px;">出水口数量</view>
<u-badge numberType="overflow" type="info" max="999"
:value="item.children.length || 0" />
<u-badge numberType="overflow" type="info" showZero max="999"
:value="item.children.length" />
</view>
</template>
<view class="u-collapse-content">
@ -178,7 +178,7 @@
</view>
</u-col>
<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>
</u-col>
</u-row>
@ -408,7 +408,7 @@
<!-- 弹窗 -->
<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" />
</view>
@ -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);
},

View File

@ -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