接入真实温度数据,后期进入页面可改成从数据库查询真实数据
parent
172e5cb894
commit
4cd115ca62
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue