接入真实温度数据,后期进入页面可改成从数据库查询真实数据

master
lld 2025-12-26 01:27:15 +08:00
parent 172e5cb894
commit 4cd115ca62
2 changed files with 55 additions and 24 deletions

View File

@ -281,7 +281,9 @@ $uni-success: #18bc37 !default;
</uni-section> </uni-section>
<uni-section :title="title" titleFontSize="16px" type="line" v-if="value!== 1"> <uni-section :title="title" titleFontSize="16px" type="line" v-if="value!== 1">
<template v-slot:right>
{{ temp }}
</template>
<!-- 卷膜/卷被卡片容器2列栅格布局 --> <!-- 卷膜/卷被卡片容器2列栅格布局 -->
<view class="card-grid"> <view class="card-grid">
<!-- 卷被开卡片 --> <!-- 卷被开卡片 -->
@ -381,6 +383,7 @@ import mqtt from 'mqtt'
export default { export default {
data() { data() {
return { return {
temp: "",
mqttConfig: { mqttConfig: {
host: '1.94.254.176', host: '1.94.254.176',
port: 9001, port: 9001,
@ -456,8 +459,9 @@ export default {
this.status.jm3k = 0; this.status.jm3k = 0;
} }
},
console.info(this.status) onShow() {
this.connectMqtt();
}, },
onUnload() { onUnload() {
this.disconnectMqtt() this.disconnectMqtt()
@ -503,6 +507,7 @@ export default {
jm3g: 0 jm3g: 0
}; };
this.message={}; this.message={};
this.temp='';
}, },
// //
handleCardClick(status, type) { handleCardClick(status, type) {
@ -552,13 +557,13 @@ export default {
this.message = JSON.stringify({[type]: status}) this.message = JSON.stringify({[type]: status})
console.info("指令:"+this.message+";大棚:"+this.publishTopic) console.info("指令:"+this.message+";大棚:"+this.publishTopic)
// //
this.publishMessage(); // this.publishMessage();
// // //
this.deviceType=type; // this.deviceType=type;
//todo //todo
// this.status[type] = this.status[type] === 0 ? 1 : 0; this.status[type] = this.status[type] === 0 ? 1 : 0;
// this.show[type] = this.status[type] === 0 ? "" : ""; this.show[type] = this.status[type] === 0 ? "运行" : "暂停";
} }
} }
@ -653,18 +658,9 @@ export default {
console.info("处理回执消息") console.info("处理回执消息")
// 👉 // 👉
this.handleCommandAck(msgData,this.deviceType); this.handleCommandAck(msgData,this.deviceType);
} else {
this.handleOtherContent(msgData)
} }
if (this.value!==1) {
var arr=['jbk',"jbg","jm1k","jm1g","jm2k","jm2g","jm3k","jm3g"]
const allKeysNumeric = Object.keys(msgData).some(key => arr.includes(key));
if (allKeysNumeric) {
console.info(msgData)
this.status={...msgData}
console.info("imei: "+this.publishTopic+"copy: ",this.status)
}
}
}, },
addMessage(content) { addMessage(content) {
@ -692,13 +688,46 @@ export default {
}, },
// //
handleOtherContent(otherData) { handleOtherContent(msgData) {
// //
console.log("收到其他内容:", otherData); console.log("收到其他内容:", msgData);
// 湿线 // 湿线
//
if (this.value!==1) {
var arr=['jbk',"jbg","jm1k","jm1g","jm2k","jm2g","jm3k","jm3g"]
const allKeysNumeric = Object.keys(msgData).some(key => arr.includes(key));
if (allKeysNumeric) {
console.info(msgData)
this.status={...msgData}
console.info("imei: "+this.publishTopic+"copy: ",this.status)
}
//
const allKeysNumeric2 = Object.keys(msgData).every(key => /^\d+$/.test(key));
if (Object.keys(msgData).length > 0 && allKeysNumeric2) {
var avgResult = this.calculateAvg(msgData).averageFixed;
this.temp = "当前棚内平均温度:"+avgResult+"℃"
}
}
},
calculateAvg(dataObj) {
const targetKeys = ['201', '202', '203', '204'];
const values = targetKeys.map(key => dataObj[key]).filter(val => typeof val === 'number' && !isNaN(val));
if (values.length === 0) return { average: 0, averageFixed: '0.00' };
const sum = values.reduce((total, num) => total + num, 0);
const avg = sum/10 / values.length;
return {
average: avg,
averageFixed: avg.toFixed(2)
};
} }
}, },
onHide() {
this.disconnectMqtt();
},
beforeDestroy() { beforeDestroy() {
if (this.client) { if (this.client) {
this.client.end() this.client.end()

View File

@ -135,7 +135,6 @@ export default {
onUnload() { onUnload() {
try { client && client.end(true) } catch(e) {} try { client && client.end(true) } catch(e) {}
// //
// //
// connected // connected
@ -143,7 +142,10 @@ export default {
// temp1/humi1 temp4/humi4 // temp1/humi1 temp4/humi4
// //
// lastTopic lastRaw // lastTopic lastRaw
} },
onHide() {
client && client.end(true)
},
} }
</script> </script>