移除倒數計時相關的程式碼,簡化 MQTT 模組的邏輯

This commit is contained in:
koko 2025-08-29 15:53:12 +08:00
parent 64f35db51b
commit 65ace7a093

View File

@ -12,9 +12,9 @@ const { iotSchemaTag } = inject("asset_modal_options");
// MQTT
const receivedMessages = ref([]); //
const countdown = ref(60); // 60
const hasStartedCountdown = ref(false); //
let timer = null; //
// const countdown = ref(60); // 60
// const hasStartedCountdown = ref(false); //
// let timer = null; //
let mqttInterval = null;
const mqttCardDataList = ref([]); //
@ -56,11 +56,11 @@ const openModal = async () => {
time: payload.time,
});
//
if (!hasStartedCountdown.value) {
hasStartedCountdown.value = true;
startCountdown();
}
// //
// if (!hasStartedCountdown.value) {
// hasStartedCountdown.value = true;
// startCountdown();
// }
} else {
// console.log("", payload.time);
}
@ -73,26 +73,26 @@ const openModal = async () => {
}, 5000);
};
const startCountdown = () => {
countdown.value = 60;
timer = setInterval(() => {
if (countdown.value > 1) {
countdown.value--;
} else {
clearInterval(timer);
timer = null;
onCancel(); // 60
}
}, 1000);
};
// const startCountdown = () => {
// countdown.value = 60;
//
// timer = setInterval(() => {
// if (countdown.value > 1) {
// countdown.value--;
// } else {
// clearInterval(timer);
// timer = null;
// onCancel(); // 60
// }
// }, 1000);
// };
const onCancel = async () => {
//
receivedMessages.value = [];
mqttCardDataList.value = [];
countdown.value = 60;
hasStartedCountdown.value = false;
// countdown.value = 60;
// hasStartedCountdown.value = false;
mqtt_test.close();
@ -112,11 +112,11 @@ const onCancel = async () => {
mqttInterval = null;
}
// Timer
if (timer) {
clearInterval(timer);
timer = null;
}
// // Timer
// if (timer) {
// clearInterval(timer);
// timer = null;
// }
};
const onSubmit = async () => {
@ -212,15 +212,6 @@ const onSubmit = async () => {
</template>
<template #modalAction>
<div class="relative w-full flex justify-end items-center gap-12">
<!-- 資料出現後才顯示倒數計時置中顯示 -->
<div
v-if="mqttCardDataList.length > 0"
class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 flex items-center gap-2 text-sm"
>
<span>Auto close in</span>
<span>{{ countdown }}s</span>
</div>
<button
type="reset"
class="btn btn-outline-success"