测试定时停

master
xce 2026-01-10 08:28:55 +08:00
parent 347082bb30
commit 584ada5811
1 changed files with 54 additions and 8 deletions

View File

@ -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;