写法优化
parent
15a5db4479
commit
d4c8f4538a
|
|
@ -160,6 +160,8 @@ import UniDatetimePicker
|
|||
from "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue";
|
||||
import { findDtuDataByInfo } from "@/api/system/data";
|
||||
|
||||
import { getMQTTClientInstance, publishMQTT } from '@/utils/mqtt';
|
||||
|
||||
export default {
|
||||
dicts: ['sys_data_map'],
|
||||
components: {
|
||||
|
|
@ -167,6 +169,7 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
mqttClient: null,
|
||||
temp: "",
|
||||
mqttConfig: {
|
||||
host: '1.94.254.176',
|
||||
|
|
@ -229,30 +232,19 @@ export default {
|
|||
},
|
||||
onLoad() {
|
||||
this.title="";
|
||||
if (this.status.jbk===1) {
|
||||
this.status.jbg = 0;
|
||||
}
|
||||
if (this.status.jbg===1) {
|
||||
this.status.jbk = 0;
|
||||
}
|
||||
if (this.status.jm1k===1) {
|
||||
this.status.jm1g = 0;
|
||||
}
|
||||
if (this.status.jm2k===1) {
|
||||
this.status.jm2g = 0;
|
||||
}
|
||||
if (this.status.jm3k===1) {
|
||||
this.status.jm3g = 0;
|
||||
}
|
||||
if (this.status.jm1g===1) {
|
||||
this.status.jm1k = 0;
|
||||
}
|
||||
if (this.status.jm2g===1) {
|
||||
this.status.jm2k = 0;
|
||||
}
|
||||
if (this.status.jm2g===1) {
|
||||
this.status.jm3k = 0;
|
||||
}
|
||||
// 定义所有互斥的键对:[k键, g键]
|
||||
const mutexPairs = [
|
||||
['jbk', 'jbg'],
|
||||
['jm1k', 'jm1g'],
|
||||
['jm2k', 'jm2g'],
|
||||
['jm3k', 'jm3g']
|
||||
];
|
||||
|
||||
// 遍历处理每一组互斥规则(k=1则g=0,g=1则k=0)
|
||||
mutexPairs.forEach(([kKey, gKey]) => {
|
||||
if (this.status[kKey] === 1) this.status[gKey] = 0;
|
||||
if (this.status[gKey] === 1) this.status[kKey] = 0;
|
||||
});
|
||||
|
||||
},
|
||||
onShow() {
|
||||
|
|
@ -274,16 +266,9 @@ export default {
|
|||
imei: this.imei
|
||||
}
|
||||
findDtuDataByInfo(queryParams).then(response => {
|
||||
this.liveData = {
|
||||
temp1: response.data.temp1 || '已离线..',
|
||||
temp2: response.data.temp2 || '已离线..',
|
||||
temp3: response.data.temp3 || '已离线..',
|
||||
temp4: response.data.temp4 || '已离线..',
|
||||
humi1: response.data.humi1 || '已离线..',
|
||||
humi2: response.data.humi2 || '已离线..',
|
||||
humi3: response.data.humi3 || '已离线..',
|
||||
humi4: response.data.humi4 || '已离线..'
|
||||
}
|
||||
Object.keys(response.data).forEach(key => {
|
||||
this.liveData[key] = response.data[key] || '已离线..';
|
||||
});
|
||||
this.temp = "最后更新时间:"+response.data.time;
|
||||
this.fontStyle = 'font-size:16px;'
|
||||
})
|
||||
|
|
@ -298,40 +283,27 @@ export default {
|
|||
},
|
||||
|
||||
reset() {
|
||||
this.show = {
|
||||
jbk: "暂停",
|
||||
jbg: "暂停",
|
||||
jm1k: "暂停",
|
||||
jm1g: "暂停",
|
||||
jm2k: "暂停",
|
||||
jm2g: "暂停",
|
||||
jm3k: "暂停",
|
||||
jm3g: "暂停"
|
||||
}
|
||||
|
||||
/*// 先定义固定的键列表(和字面量的键一致)
|
||||
const showKeys = ['jbk', 'jbg', 'jm1k', 'jm1g', 'jm2k', 'jm2g', 'jm3k', 'jm3g'];
|
||||
// 只遍历指定键,赋值为"暂停"
|
||||
showKeys.forEach(key => {
|
||||
this.show[key] = "暂停";
|
||||
});*/
|
||||
Object.keys(this.show).forEach(key => {
|
||||
this.show[key] = "暂停";
|
||||
});
|
||||
Object.keys(this.status).forEach(key => {
|
||||
this.status[key] = 0;
|
||||
});
|
||||
Object.keys(this.liveData).forEach(key => {
|
||||
this.liveData[key] = '数据加载中...';
|
||||
});
|
||||
this.deviceType = '';
|
||||
this.status = {
|
||||
jbk: 0,
|
||||
jbg: 0,
|
||||
jm1k: 0,
|
||||
jm1g: 0,
|
||||
jm2k: 0,
|
||||
jm2g: 0,
|
||||
jm3k: 0,
|
||||
jm3g: 0
|
||||
};
|
||||
|
||||
this.control = '正在加载中...';
|
||||
this.message = {};
|
||||
this.temp = '';
|
||||
this.liveData = {
|
||||
temp1: '数据加载中...',
|
||||
temp2: '数据加载中...',
|
||||
temp3: '数据加载中...',
|
||||
temp4: '数据加载中...',
|
||||
humi1: '数据加载中...',
|
||||
humi2: '数据加载中...',
|
||||
humi3: '数据加载中...',
|
||||
humi4: '数据加载中...'
|
||||
}
|
||||
},
|
||||
// 卡片点击事件(实际项目中调用接口修改状态) 功能标识
|
||||
handleCardClick(status, type) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue