From a7df117a651101d179f93c8900c7c2f47ba0fe0e Mon Sep 17 00:00:00 2001 From: lld <15027638633@163.com> Date: Sun, 8 Mar 2026 19:26:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index.vue | 75 +++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 95019bb..61a4910 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -52,7 +52,7 @@ :class="['list-item', { 'list-item-disabled': item.online === '离线' }]" :right-options="options"> + @click="onItemTap(item)"> {{ item.agriName }} {{ item.workModeDesc }} @@ -355,35 +355,25 @@ export default { makeSpecialData: function (msgData){ const online = TimeUtil.isLessThanSpecifiedSeconds(msgData.ts,90)?'在线':'离线'; - this.listData.push( - { - agriName: "八方南棚", - imei: "A", - temp1: msgData.temp1, - temp2: msgData.temp2, - temp3: msgData.temp3, - temp4: msgData.temp4, - online:online - }, - { - agriName: "九方春棚", - imei: "B", - temp1: msgData.temp5, - temp2: msgData.temp6, - temp3: msgData.temp7, - temp4: msgData.temp8, - online:online - }, - { - agriName: "十二方棚", - imei: "C", - temp1: msgData.temp9, - temp2: msgData.temp10, - temp3: msgData.temp11, - temp4: msgData.temp12, - online:online - }, - ) + const deviceConfigs = [ + { agriName: "八方南棚", imei: "A", temps: [1,2,3,4] }, + { agriName: "九方春棚", imei: "B", temps: [5,6,7,8] }, + { agriName: "十二方棚", imei: "C", temps: [9,10,11,12] } + ]; + + const devices = deviceConfigs.map(({agriName, imei, temps}) => ({ + agriName, + imei, + temp1: msgData[`temp${temps[0]}`], + temp2: msgData[`temp${temps[1]}`], + temp3: msgData[`temp${temps[2]}`], + temp4: msgData[`temp${temps[3]}`], + online + })); + + this.listData.push(...devices); + // 状态和温度不需要监听不需要搞 + // devices.forEach(d => this.imeiToDeviceMap.set(d.imei, d)); }, ackMessage(topic, payload) { const regex = /^device\/\d+\/status$/; @@ -410,18 +400,19 @@ export default { } this.getDataDetails(); }, + // 离线状态查询 是先获取大棚表,无线表不存在大棚表里 updateDeviceStatusFast(targetImei, isOnline) { + console.info("监听到状态",targetImei, isOnline) // 直接从Map里取设备项,无需遍历数组 const targetDevice = this.imeiToDeviceMap.get(targetImei); if (!targetDevice) return; - - const statusText = isOnline ? '在线' : '离线'; // 直接修改对象属性,响应式正常生效 - targetDevice.deviceStatus = statusText; - targetDevice.online = statusText; + targetDevice.deviceStatus = isOnline; + targetDevice.online = isOnline; }, updateTempFast: function (msgData,topic) { + console.info("监听到温度",topic,msgData) const regexWithGroup = /^frontend\/(.+)\/dtu\/(\d+)\/listener$/; const matchResult = topic.match(regexWithGroup); const imei = matchResult[2]; // 提取结果:'1234567890' @@ -435,6 +426,22 @@ export default { targetDevice.temp2 = div10(msgData['202']); targetDevice.temp3 = div10(msgData['203']); targetDevice.temp4 = div10(msgData['204']); + + // if (imei === '862538065276061') { + // const deviceConfigs = [ + // { agriName: "八方南棚", imei: "A", temps: [1,2,3,4] }, + // { agriName: "九方春棚", imei: "B", temps: [5,6,7,8] }, + // { agriName: "十二方棚", imei: "C", temps: [9,10,11,12] } + // ]; + // + // deviceConfigs.forEach(({agriName, imei, temps}) => { + // var target = this.imeiToDeviceMap.get(imei); + // target.temp1 = div10(msgData[`20${temps[0]}`]); + // target.temp2 = div10(msgData[`20${temps[1]}`]); + // target.temp3 = div10(msgData[`20${temps[2]}`]); + // target.temp4 = div10(msgData[`20${temps[3]}`]); + // }) + // } }, getDataDetails() { this.dataDetails = {