From 3cb02c2896f71fc65d88795821ac668ef576b6eb Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 29 Jan 2025 18:11:14 +0700 Subject: [PATCH] fix --- src/views/HomeView.vue | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index a043f79..f098690 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -206,7 +206,6 @@ async function confirm() { .then(async (res) => { const data = await res.data.result const dateObject = new Date(data.date) - localStorage.setItem('taskid', data.taskId) const options: Intl.DateTimeFormatOptions = { hour12: false, hour: '2-digit', @@ -234,7 +233,8 @@ async function onClickConfirm() { stetusCheckin.value = true } - await fetchCheckTime() + // await fetchCheckTime() + // fetchCheckStatus() startChecking() cameraIsOn.value = false @@ -262,20 +262,17 @@ const getClass = (val: boolean) => { const inQueue = ref(false) async function fetchCheckStatus() { - // let taskId = localStorage.getItem('taskid') - // console.log(taskId) - // if (!taskId) return try { const res = await http.get(config.API.checkStatus()) inQueue.value = res.data.result.inQueue if (res.data.result.inQueue) { isDisabledCheckTime.value = true - msgCheckTime.value = 'กำลังดำเนินงาน' + msgCheckTime.value = 'ระบบกำลังประมวลผล' + hideLoader() } else { isDisabledCheckTime.value = false msgCheckTime.value = '' stopChecking() // หยุดการทำงาน - fetchCheckTime() console.log('Response เป็น false, หยุด interval') } } catch (error) { @@ -285,17 +282,23 @@ async function fetchCheckStatus() { } const intervalId = ref(undefined) // ต้องใช้ตัวแปรเก็บค่า interval -function startChecking() { +async function startChecking() { + showLoader() + fetchCheckStatus() if (intervalId.value === undefined) { // ป้องกันการสร้าง interval ซ้ำ - intervalId.value = setInterval(fetchCheckStatus, 3000) + intervalId.value = setInterval(async () => { + await fetchCheckStatus() // รอให้ fetchCheckStatus ทำงานเสร็จก่อน + }, 3000) } } -function stopChecking() { +async function stopChecking() { if (intervalId.value !== undefined) { clearInterval(intervalId.value) // หยุด interval - fetchCheckTime() + setTimeout(() => { + fetchCheckTime() + }, 1000) intervalId.value = undefined // รีเซ็ตค่า } } @@ -320,14 +323,14 @@ onMounted(async () => { --> - ลงเวลาออกงาน (รอประมวลผล) + ลงเวลาออกงาน (ระบบกำลังประมวลผล) - ลงเวลาเข้างาน (รอประมวลผล) + ลงเวลาเข้างาน (ระบบกำลังประมวลผล)