diff --git a/pages/control/index.vue b/pages/control/index.vue index 0bb2fdc..d09fd13 100644 --- a/pages/control/index.vue +++ b/pages/control/index.vue @@ -360,26 +360,37 @@ export default { }, makeSpecialData(msgData, tag) { - const div10 = (v) => (v == null ? null : Math.round((Number(v)/10)*10)/10) - // 传感器键名映射表 - const IMEI_SENSOR_MAP = { - A: SENSOR_MAP, - B: tag?{temp1:'205',humi1:'105',temp2:'206',humi2:'106',temp3:'207',humi3:'107',temp4:'208',humi4:'108'} - :{temp1:'temp5',humi1:'humi5',temp2:'temp6',humi2:'humi6',temp3:'temp7',humi3:'humi7',temp4:'temp8',humi4:'humi8'}, - C: tag?{temp1:'209',humi1:'109',temp2:'210',humi2:'110',temp3:'211',humi3:'111',temp4:'212',humi4:'112'} - :{temp1:'temp9',humi1:'humi9',temp2:'temp10',humi2:'humi10',temp3:'temp11',humi3:'humi11',temp4:'temp12',humi4:'humi12'}, + const div10 = (v) => (v == null ? null : Math.round((Number(v)/10)*10)/10); + + // 1. 提取B/C的tag对应键名(精简重复三元) + const B_KEYS = { + true: {temp1:'205',humi1:'105',temp2:'206',humi2:'106',temp3:'207',humi3:'107',temp4:'208',humi4:'108'}, + false: {temp1:'temp5',humi1:'humi5',temp2:'temp6',humi2:'humi6',temp3:'temp7',humi3:'humi7',temp4:'temp8',humi4:'humi8'} + }; + const C_KEYS = { + true: {temp1:'209',humi1:'109',temp2:'210',humi2:'110',temp3:'211',humi3:'111',temp4:'212',humi4:'112'}, + false: {temp1:'temp9',humi1:'humi9',temp2:'temp10',humi2:'humi10',temp3:'temp11',humi3:'humi11',temp4:'temp12',humi4:'humi12'} }; - // 确定传感器键名 + // 2. 简化传感器键名映射表 + const IMEI_SENSOR_MAP = { + A: SENSOR_MAP, + B: B_KEYS[tag], // 直接取tag对应的键名,替代三元 + C: C_KEYS[tag] + }; + + // 3. 确定传感器键名(精简变量名) const isAdmin = store.getters?.name === 'admin'; - const sensorKeys = (isAdmin && ['A','B','C'].includes(this.imei)) - ? IMEI_SENSOR_MAP[this.imei] - : IMEI_SENSOR_MAP.A; - // 批量生成liveData + const sk = (isAdmin && ['A','B','C'].includes(this.imei)) ? IMEI_SENSOR_MAP[this.imei] : IMEI_SENSOR_MAP.A; + + // 4. 简化liveData的嵌套三元(核心优化) this.liveData = Object.fromEntries( - Object.entries(sensorKeys).map(([key, sensorKey]) => [ - key, - (tag?div10(msgData[sensorKey]):(this.imei==='A'?msgData[key]: msgData[sensorKey]))|| "已离线..." + Object.entries(sk).map(([k, skVal]) => [ + k, + (tag + ? div10(msgData[skVal]) + : (this.imei === 'A' ? msgData[k] : msgData[skVal])) + || "已离线..." ]) ); },