测试定时停
parent
347082bb30
commit
584ada5811
|
|
@ -92,7 +92,12 @@
|
|||
</view>
|
||||
<view class="modal-input-wrap" >
|
||||
<text class="modal-label">修改后时间:</text>
|
||||
<uni-number-box v-model="newLimitTime" />
|
||||
<input
|
||||
class="modal-input"
|
||||
type="number"
|
||||
v-model.number="newLimitTime"
|
||||
/>
|
||||
<!-- <uni-number-box v-model="newLimitTime" />-->
|
||||
<text class="modal-unit">秒</text>
|
||||
</view>
|
||||
<view class="modal-btn-wrap">
|
||||
|
|
@ -314,7 +319,6 @@ export default {
|
|||
text: item.agriName,
|
||||
value: item.imei // 提取并改名
|
||||
}));
|
||||
console.info(this.range);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
@ -393,15 +397,55 @@ export default {
|
|||
// 设备回执
|
||||
this.deviceType = type;
|
||||
//todo
|
||||
|
||||
// this.$set(this.status, type, this.status[type] === 0 ? 1 : 0);
|
||||
// this.$set(this.show, type, this.status[type] === 0 ? "暂停" : "运行");
|
||||
// this.testAuto(type);
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 测试专用
|
||||
testAuto(type) {
|
||||
this.$set(this.status, type, this.status[type] === 0 ? 1 : 0);
|
||||
this.$set(this.show, type, this.status[type] === 0 ? "暂停" : "运行");
|
||||
|
||||
// ========== 核心新增:开启指令成功后启动定时器(带快照) ==========
|
||||
const isStartCommand = status === 1; // 1=开启指令,0=停止指令
|
||||
if (isStartCommand) {
|
||||
// 1. 清除同type旧定时器(避免重复计时)
|
||||
if (this.timers[type]?.timerId) {
|
||||
clearTimeout(this.timers[type].timerId);
|
||||
delete this.timers[type];
|
||||
}
|
||||
|
||||
// 2. 快照:保存当前所有关键数据(值拷贝,永不改变)
|
||||
const snapInfo = {
|
||||
imei: this.imei, // 旧大棚imei
|
||||
publishTopic: this.publishTopic, // 旧大棚Topic
|
||||
delayTime: Number(this.limitTimes[`${type}Limit`] || 0) * 1000, // 旧运行时长(毫秒)
|
||||
deviceType: type, // 设备类型
|
||||
connected: this.connected // 连接状态
|
||||
};
|
||||
// 3. 仅当设置了运行时间才启动定时器
|
||||
if (snapInfo.delayTime && snapInfo.delayTime > 0) {
|
||||
console.info(`定时记录:大棚:${snapInfo.imei}; 指令:${this.message}`)
|
||||
|
||||
// 4. 启动定时器,存储timerId和快照
|
||||
const timerId = setTimeout(() => {
|
||||
// 计时结束:执行自动停止逻辑(使用快照数据)
|
||||
this.sendAutoStopCommand(snapInfo);
|
||||
// 清除当前定时器记录
|
||||
delete this.timers[type];
|
||||
}, snapInfo.delayTime);
|
||||
|
||||
// 5. 保存定时器信息
|
||||
this.timers[type] = {
|
||||
timerId: timerId,
|
||||
snapInfo: snapInfo
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
publishMessage() {
|
||||
if (!this.connected || !this.publishTopic || !this.message) {
|
||||
uni.showToast({
|
||||
|
|
@ -520,8 +564,8 @@ export default {
|
|||
if (needStop) {
|
||||
// 3. 组装停止指令(使用快照中的设备类型)
|
||||
const stopMessage = JSON.stringify({[snapInfo.deviceType]: 0});
|
||||
|
||||
// 4. 使用快照中的Topic发送指令(精准发往旧大棚)
|
||||
console.info(`自动停:${snapInfo.publishTopic}:${stopMessage}`);
|
||||
// todo 4. 使用快照中的Topic发送指令(精准发往旧大棚)
|
||||
const publishSuccess = mqttUtil.publishMqtt(snapInfo.publishTopic, stopMessage);
|
||||
if (publishSuccess) {
|
||||
this.addMessage(`【自动停止-旧大棚${snapInfo.imei}】设备${snapInfo.deviceType},指令: ${stopMessage}`);
|
||||
|
|
@ -530,6 +574,7 @@ export default {
|
|||
if (this.imei === snapInfo.imei) {
|
||||
this.$set(this.status, snapInfo.deviceType, 0);
|
||||
this.$set(this.show, snapInfo.deviceType, "暂停");
|
||||
|
||||
}
|
||||
} else {
|
||||
this.addMessage(`【自动停止失败-旧大棚${snapInfo.imei}】设备${snapInfo.deviceType}`);
|
||||
|
|
@ -835,15 +880,16 @@ export default {
|
|||
color: #666;
|
||||
}
|
||||
.modal-current {
|
||||
margin-left: 14rpx;
|
||||
color: #333;
|
||||
}
|
||||
.modal-input {
|
||||
flex: 1;
|
||||
height: 60rpx;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 8rpx;
|
||||
padding: 0 15rpx;
|
||||
font-size: 26rpx;
|
||||
width: 80rpx;
|
||||
}
|
||||
.modal-unit {
|
||||
margin-left: 10rpx;
|
||||
|
|
|
|||
Loading…
Reference in New Issue