This commit is contained in:
Iruka 2024-09-30 15:34:20 +08:00
parent ec0e061cc9
commit 834268e54b
4 changed files with 59 additions and 41 deletions

43
App.vue
View File

@ -14,18 +14,6 @@
globalData: {}, globalData: {},
onLaunch: function() { onLaunch: function() {
console.log('App Launch') console.log('App Launch')
// #ifdef H5
this.mqtt = new mqttUtil();
// #endif
// mqtt
uni.$on("mqtt-link", (userId) => {
this.mqttLink(userId);
});
// mqtt
uni.$on("mqtt-subscribes", topics => {
this.mqttSubscribes();
});
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')
@ -45,9 +33,25 @@
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);
const obj = this.dc.topic;
if (obj.newV && obj.newV.length) {
this.mqttSubscribes(obj.newV); //
}
if (obj.oldV && obj.oldV.length) {
this.mqttUnsubscribes(obj.oldV); //
}
this.indexData.setStorage(3, {
userId: this.indexData.userId,
landId: this.indexData.selectItem.id,
stations: this.dc.stations,
flapValves: this.dc.flapValves,
waterOutlets: this.dc.valves,
});
} }
uni.hideLoading(); uni.hideLoading();
// console.error("indexDataHandler_2:", { // console.error("indexDataHandler:", {
// e: e, // e: e,
// data: data, // data: data,
// indexData: this.indexData, // indexData: this.indexData,
@ -58,14 +62,18 @@
mqttLink(userId) { mqttLink(userId) {
this.mqtt.link(userId); this.mqtt.link(userId);
}, },
//Mqtt //Mqtt
mqttSubscribes(topics) { mqttSubscribes(topics) {
this.mqtt.subscribes(topics); this.mqtt.subscribes(topics);
}, },
//Mqtt //Mqtt
mqttUnsubscribes(topics) { mqttUnsubscribes(topics) {
this.mqtt.unsubscribes(topics); this.mqtt.unsubscribes(topics);
}, },
//Mqtt
mqttEnd() {
this.mqtt.over();
},
//Mqtt //Mqtt
mqttMsgHandler(topic, data) { mqttMsgHandler(topic, data) {
console.error("mqttMsgHandler:", { console.error("mqttMsgHandler:", {
@ -73,11 +81,6 @@
data: data, data: data,
}); });
}, },
//Mqtt
mqttEnd() {
this.mqtt.over();
},
} }
} }
</script> </script>

View File

@ -12,6 +12,7 @@
</view> </view>
</block> </block>
</uni-nav-bar> </uni-nav-bar>
<!-- 内容 --> <!-- 内容 -->
<view class="content"> <view class="content">
<!-- 顶部搜索框 --> <!-- 顶部搜索框 -->
@ -98,7 +99,7 @@
</view> </view>
<view class="fixed" style="width:calc(100% - 30%); justify-content: flex-end;"> <view class="fixed" style="width:calc(100% - 30%); justify-content: flex-end;">
<view class="iconfont icon-xh icon" <view class="iconfont icon-xh icon"
:class="[ mqtt.connected ? 'xh_green':'xh_red' ]"> :class="[ mqtt.connected ? 'font-green':'font-red' ]">
</view> </view>
<view @click.stop=""> <view @click.stop="">
<u-button type="success" size="small" text="一键刷新" /> <u-button type="success" size="small" text="一键刷新" />
@ -150,6 +151,11 @@
</u-collapse-item> </u-collapse-item>
</u-collapse> </u-collapse>
</view> </view>
<!-- <button @click="mqttLink">mqttLink</button>
<button @click="mqttEnd">mqttEnd</button>
<button @click="mqttSubscribes">订阅</button> -->
<!-- 阀门列表 --> <!-- 阀门列表 -->
<view class="card"> <view class="card">
<u-collapse accordion> <u-collapse accordion>
@ -246,15 +252,14 @@
<u-col span="6"> <u-col span="6">
<view class="valve"> <view class="valve">
<view> <view>
<u-button>全开</u-button> <view class="btn v-btn2 fixed">
<!-- <view class="btn v-btn2 fixed">
<text>全开</text> <text>全开</text>
<text class="load-text">(超时)</text> <text class="load-text">(超时)</text>
<view <view
v-if="!item2.device.custom.btnControllable.openAll" v-if="!item2.device.custom.btnControllable.openAll"
class="iconfont icon-suoding icon"> class="iconfont icon-suoding icon">
</view> </view>
</view> --> </view>
</view> </view>
<view class="btn-img"> <view class="btn-img">
<view class="text"> <view class="text">
@ -381,14 +386,7 @@
<!-- 角度 --> <!-- 角度 -->
<custom-angle-slider ref="refAngleSlider" mode="bottom" @close="" @confirm="angleSliderConfirm" /> <custom-angle-slider ref="refAngleSlider" mode="bottom" @close="" @confirm="angleSliderConfirm" />
</view> </view>
<button @click="mqttLink">mqttLink</button>
<button @click="mqttEnd">mqttEnd</button>
<button @click="mqttGet">获取信息</button>
<view>
<p>connected:{{mqtt.connected}}</p>
<!-- <p>reconnecting:{{mqtt.client.reconnecting}}</p>
<p>结果{{mqtt.client && (mqtt.client.connected && !mqtt.client.reconnecting)}}</p> -->
</view>
</template> </template>
<script> <script>
@ -411,13 +409,11 @@
// uni.$emit("mqtt-link", this.user.userId); // uni.$emit("mqtt-link", this.user.userId);
// getApp().mqttLink(this.user.userId); // getApp().mqttLink(this.user.userId);
uni.$off("notify-update-land"); uni.$off("notify-update-land");
uni.$on("notify-update-land", (data) => { uni.$on("notify-update-land", (data) => {
console.error("index监听地块更新", data) console.error("index监听地块更新", data)
this.isLandChange = true; this.isLandChange = true;
}); });
}, },
onShow() { onShow() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
@ -428,7 +424,7 @@
}, },
onPageScroll(e) { // onPageScroll(e) { //
// console.log(e.scrollTop); // // console.log(e.scrollTop); //
if (e.scrollTop >= 100) { if (e.scrollTop >= 75) {
this.isSticky = true; this.isSticky = true;
} else { } else {
this.isSticky = false; this.isSticky = false;
@ -441,9 +437,12 @@
mqttEnd() { mqttEnd() {
getApp().mqttEnd(); getApp().mqttEnd();
}, },
mqttGet() { mqttSubscribes() {
console.error("mqtt", this.mqtt) console.error("mqtt", this.mqtt)
let topics = ["jsy/iot/push/1H8ngznmV50GzutYS8rIk01pd8"]
getApp().mqttSubscribes(topics);
}, },
// //
openLand() { openLand() {
this.$refs.refLand.open(); this.$refs.refLand.open();
@ -845,10 +844,10 @@
} }
.font-green { .font-green {
color: #39ac4f color: #39ac4f !important;
} }
.font-red { .font-red {
color: #e60012 color: #e60012 !important;
} }
</style> </style>

View File

@ -334,7 +334,14 @@
} }
// //
store.dispatch("GetInfo").then(result => { store.dispatch("GetInfo").then(result => {
toIndex(); if (result.code == 200) {
toIndex(result.user.userId);
} else {
uni.showToast({
title: result.msg,
icon: "none"
})
}
}) })
// //
store store
@ -352,9 +359,14 @@
} }
// //
function toIndex() { function toIndex(userId) {
uni.switchTab({ uni.switchTab({
url: '/pages/index' url: '/pages/index',
success: () => {
// getApp().mqttLink(userId);
},
fail: () => {},
complete: () => {}
}); });
} }

View File

@ -77,6 +77,10 @@
background-color: #39ac4f; background-color: #39ac4f;
color: #fff; color: #fff;
} }
.btn.activeing {
background-color: #39ac4f;
color: #fff;
}
/* 字体颜色 */ /* 字体颜色 */
.font-red { .font-red {