逻辑完善

master
lld 2025-12-26 00:00:03 +08:00
parent 4f8a72936b
commit 724f0eddc0
1 changed files with 108 additions and 13 deletions

View File

@ -274,7 +274,13 @@ $uni-success: #18bc37 !default;
<view class="container"> <view class="container">
<!-- 控制设置标题 --> <!-- 控制设置标题 -->
<view class="control-title">控制设置</view> <view class="control-title">控制设置</view>
<uni-section :title="title" titleFontSize="16px" type="line"> <uni-section title="请选择大棚:" titleFontSize="16px" type="line">
<view class="uni-px-5 uni-pb-5">
<uni-data-select v-model="value" :localdata="range" @change="change"></uni-data-select>
</view>
</uni-section>
<uni-section :title="title" titleFontSize="16px" type="line" v-if="value!== 1">
<!-- 卷膜/卷被卡片容器2列栅格布局 --> <!-- 卷膜/卷被卡片容器2列栅格布局 -->
<view class="card-grid"> <view class="card-grid">
@ -383,7 +389,18 @@ export default {
password: 'Admin#12345678', password: 'Admin#12345678',
subscribeTopic:'/up', subscribeTopic:'/up',
}, },
imei:'864536071808560', value: 1,
range: [{
"value": '864865085016294',
"text": "十方北棚"
}, {
"value": '864536071808560',
"text": "七方北棚",
}, {
"value": '864865085008135',
"text": "八方北棚"
}],
imei:'',
publishTopic: '/down', publishTopic: '/down',
title:'', title:'',
message: {}, message: {},
@ -413,9 +430,7 @@ export default {
}; };
}, },
onLoad() { onLoad() {
this.publishTopic = "dtu/"+this.imei+this.publishTopic; this.title="";
this.mqttConfig.subscribeTopic = "dtu/"+this.imei+this.mqttConfig.subscribeTopic;
this.title="设备【"+this.imei+"】";
if (this.status.jbk===1) { if (this.status.jbk===1) {
this.status.jbg = 0; this.status.jbg = 0;
} }
@ -448,29 +463,101 @@ export default {
this.disconnectMqtt() this.disconnectMqtt()
}, },
methods: { methods: {
change(e) {
this.imei = e;
this.publishTopic = "dtu/"+this.imei+"/down";
this.mqttConfig.subscribeTopic = "dtu/"+this.imei+"/up";
const selectedItem = this.range.find(item => item.value === e);
if (selectedItem) {
this.selectedText = selectedItem.text; //
this.title= this.selectedText;
} else {
this.selectedText = ''; //
this.title='';
this.value=1;
}
this.reset();
},
reset() {
this.show= {
jbk: "暂停",
jbg: "暂停",
jm1k: "暂停",
jm1g: "暂停",
jm2k: "暂停",
jm2g: "暂停",
jm3k: "暂停",
jm3g: "暂停"
}
this.deviceType= '';
this.status= {
jbk: 0,
jbg: 0,
jm1k: 0,
jm1g: 0,
jm2k: 0,
jm2g: 0,
jm3k: 0,
jm3g: 0
};
this.message={};
},
// //
handleCardClick(status, type) { handleCardClick(status, type) {
//
//
const tipMap = {
'jbk': { opposite: 'jbg', name: '卷被关', op: '卷被开' },
'jbg': { opposite: 'jbk', name: '卷被开', op: '卷被关' },
'jm1k': { opposite: 'jm1g', name: '卷膜1关', op: '卷膜1开' },
'jm1g': { opposite: 'jm1k', name: '卷膜1开', op: '卷膜1关' },
'jm2k': { opposite: 'jm2g', name: '卷膜2关', op: '卷膜2开' },
'jm2g': { opposite: 'jm2k', name: '卷膜2开', op: '卷膜2关' },
'jm3k': { opposite: 'jm3g', name: '卷膜3关', op: '卷膜3开' },
'jm3g': { opposite: 'jm3k', name: '卷膜3开', op: '卷膜3关' }
};
// case
if (!tipMap[type]) return;
const { opposite, name, op } = tipMap[type];
//
if (status === 1 && this.status[opposite] === 1) {
this.$modal.msgError(`${this.selectedText}${name}在运行状态,不能运行${op}操作!`);
// return
return;
}
if (!this.connected) { if (!this.connected) {
// mqtt // mqtt
this.connectMqtt() this.connectMqtt()
} }
if (this.value===1) {
this.$modal.msgError("设备控制失败!");
console.info("大棚选取失败!")
return;
}
uni.showModal({ uni.showModal({
title: '操作提示:', title: '操作提示:',
content: '确定'+(status===1?"运行":"暂停")+'设备?', content: '确定'+(status===1?"运行":"暂停")+'【'+this.selectedText+'】设备?',
cancelText: '取消', cancelText: '取消',
confirmText: '确定', confirmText: '确定',
success: (res) =>{ success: (res) =>{
if (res.confirm) { if (res.confirm) {
console.info("操作功能:【"+type+"】,变更状态为:"+ status) console.info("操作功能:【"+type+"】,变更状态为:"+ status)
// // //
this.message = JSON.stringify({[type]: status}) this.message = JSON.stringify({[type]: status})
console.info("指令:"+this.message) console.info("指令:"+this.message+";大棚:"+this.publishTopic)
// //
this.publishMessage(); // this.publishMessage();
// // //
this.deviceType=type; // this.deviceType=type;
this.status[type] = this.status[type] === 0 ? 1 : 0;
this.show[type] = this.status[type] === 0 ? "运行" : "暂停";
} }
} }
}) })
@ -570,9 +657,7 @@ export default {
console.info("提示消息:"+content) console.info("提示消息:"+content)
}, },
switchChange() {
},
// //
handleCommandAck(ackData,type) { handleCommandAck(ackData,type) {
console.info("回执消息11111"+ackData) console.info("回执消息11111"+ackData)
@ -586,6 +671,8 @@ export default {
this.show[type] = this.status[type] === 0 ? "运行" : "暂停"; this.show[type] = this.status[type] === 0 ? "运行" : "暂停";
} }
this.deviceType=''; this.deviceType='';
this.$modal.msgSuccess("设备操作成功!")
// / // /
console.log(`指令[${commandField}=${commandValue}]执行${isSuccess ? "成功" : "失败"}`); console.log(`指令[${commandField}=${commandValue}]执行${isSuccess ? "成功" : "失败"}`);
// msgIdUI // msgIdUI
@ -676,4 +763,12 @@ export default {
.card-icon.active { .card-icon.active {
background-color: #007aff; background-color: #007aff;
} }
.uni-px-5 {
padding-left: 20rpx;
padding-right: 20rpx;
}
.uni-pb-5 {
padding-bottom: 40rpx;
}
</style> </style>