特殊棚添加
parent
7f493da241
commit
9eaf3e7e71
|
|
@ -360,26 +360,37 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
makeSpecialData(msgData, tag) {
|
makeSpecialData(msgData, tag) {
|
||||||
const div10 = (v) => (v == null ? null : Math.round((Number(v)/10)*10)/10)
|
const div10 = (v) => (v == null ? null : Math.round((Number(v)/10)*10)/10);
|
||||||
// 传感器键名映射表
|
|
||||||
const IMEI_SENSOR_MAP = {
|
// 1. 提取B/C的tag对应键名(精简重复三元)
|
||||||
A: SENSOR_MAP,
|
const B_KEYS = {
|
||||||
B: tag?{temp1:'205',humi1:'105',temp2:'206',humi2:'106',temp3:'207',humi3:'107',temp4:'208',humi4:'108'}
|
true: {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'},
|
false: {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 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 isAdmin = store.getters?.name === 'admin';
|
||||||
const sensorKeys = (isAdmin && ['A','B','C'].includes(this.imei))
|
const sk = (isAdmin && ['A','B','C'].includes(this.imei)) ? IMEI_SENSOR_MAP[this.imei] : IMEI_SENSOR_MAP.A;
|
||||||
? IMEI_SENSOR_MAP[this.imei]
|
|
||||||
: IMEI_SENSOR_MAP.A;
|
// 4. 简化liveData的嵌套三元(核心优化)
|
||||||
// 批量生成liveData
|
|
||||||
this.liveData = Object.fromEntries(
|
this.liveData = Object.fromEntries(
|
||||||
Object.entries(sensorKeys).map(([key, sensorKey]) => [
|
Object.entries(sk).map(([k, skVal]) => [
|
||||||
key,
|
k,
|
||||||
(tag?div10(msgData[sensorKey]):(this.imei==='A'?msgData[key]: msgData[sensorKey]))|| "已离线..."
|
(tag
|
||||||
|
? div10(msgData[skVal])
|
||||||
|
: (this.imei === 'A' ? msgData[k] : msgData[skVal]))
|
||||||
|
|| "已离线..."
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue