逻辑完善
parent
4f8a72936b
commit
724f0eddc0
|
|
@ -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 ? "成功" : "失败"}`);
|
||||||
// (可匹配之前发布的指令msgId,更新UI状态)
|
// (可匹配之前发布的指令msgId,更新UI状态)
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue