写法优化

master
lld 2025-12-30 20:48:07 +08:00
parent 15a5db4479
commit d4c8f4538a
1 changed files with 36 additions and 64 deletions

View File

@ -160,6 +160,8 @@ import UniDatetimePicker
from "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue"; from "../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue";
import { findDtuDataByInfo } from "@/api/system/data"; import { findDtuDataByInfo } from "@/api/system/data";
import { getMQTTClientInstance, publishMQTT } from '@/utils/mqtt';
export default { export default {
dicts: ['sys_data_map'], dicts: ['sys_data_map'],
components: { components: {
@ -167,6 +169,7 @@ export default {
}, },
data() { data() {
return { return {
mqttClient: null,
temp: "", temp: "",
mqttConfig: { mqttConfig: {
host: '1.94.254.176', host: '1.94.254.176',
@ -229,30 +232,19 @@ export default {
}, },
onLoad() { onLoad() {
this.title=""; this.title="";
if (this.status.jbk===1) { // [k, g]
this.status.jbg = 0; const mutexPairs = [
} ['jbk', 'jbg'],
if (this.status.jbg===1) { ['jm1k', 'jm1g'],
this.status.jbk = 0; ['jm2k', 'jm2g'],
} ['jm3k', 'jm3g']
if (this.status.jm1k===1) { ];
this.status.jm1g = 0;
} // k=1g=0g=1k=0
if (this.status.jm2k===1) { mutexPairs.forEach(([kKey, gKey]) => {
this.status.jm2g = 0; if (this.status[kKey] === 1) this.status[gKey] = 0;
} if (this.status[gKey] === 1) this.status[kKey] = 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;
}
}, },
onShow() { onShow() {
@ -274,16 +266,9 @@ export default {
imei: this.imei imei: this.imei
} }
findDtuDataByInfo(queryParams).then(response => { findDtuDataByInfo(queryParams).then(response => {
this.liveData = { Object.keys(response.data).forEach(key => {
temp1: response.data.temp1 || '已离线..', this.liveData[key] = response.data[key] || '已离线..';
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 || '已离线..'
}
this.temp = "最后更新时间:"+response.data.time; this.temp = "最后更新时间:"+response.data.time;
this.fontStyle = 'font-size:16px;' this.fontStyle = 'font-size:16px;'
}) })
@ -298,40 +283,27 @@ export default {
}, },
reset() { reset() {
this.show = {
jbk: "暂停", /*// 先定义固定的键列表和字面量的键一致
jbg: "暂停", const showKeys = ['jbk', 'jbg', 'jm1k', 'jm1g', 'jm2k', 'jm2g', 'jm3k', 'jm3g'];
jm1k: "暂停", // ""
jm1g: "暂停", showKeys.forEach(key => {
jm2k: "暂停", this.show[key] = "暂停";
jm2g: "暂停", });*/
jm3k: "暂停", Object.keys(this.show).forEach(key => {
jm3g: "暂停" 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.deviceType = '';
this.status = {
jbk: 0,
jbg: 0,
jm1k: 0,
jm1g: 0,
jm2k: 0,
jm2g: 0,
jm3k: 0,
jm3g: 0
};
this.control = '正在加载中...'; this.control = '正在加载中...';
this.message = {}; this.message = {};
this.temp = ''; this.temp = '';
this.liveData = {
temp1: '数据加载中...',
temp2: '数据加载中...',
temp3: '数据加载中...',
temp4: '数据加载中...',
humi1: '数据加载中...',
humi2: '数据加载中...',
humi3: '数据加载中...',
humi4: '数据加载中...'
}
}, },
// //
handleCardClick(status, type) { handleCardClick(status, type) {