From 7ce5eab6f467ed7124a34e9da6a0625c2f3d4eb1 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 1 May 2026 14:31:09 +0700 Subject: [PATCH] fix(HomeView): fetch Data --- src/views/HomeView.vue | 51 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index fde8b97..fef5d5e 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -9,6 +9,7 @@ import http from '@/plugins/http' import { useCounterMixin } from '@/stores/mixin' import { usePermissions } from '@/composables/usePermissions' import { usePrivacyStore } from '@/stores/privacy' +import { usePositionKeycloakStore } from '@/stores/positionKeycloak' import type { FormRef, OptionReason } from '@/interface/response/checkin' @@ -19,8 +20,28 @@ const { date2Thai, showLoader, hideLoader, messageError, dialogConfirm } = mixin const $q = useQuasar() const { checkPrivacyAccepted } = usePermissions() const privacyStore = usePrivacyStore() +const positionKeycloakStore = usePositionKeycloakStore() const MOCK_CHECK_DELAY_MS = 800 +// เช็คว่าผู้ใช้มีข้อมูลสังกัดหรือไม่ +const hasOrganization = computed(() => { + const data = positionKeycloakStore.dataPositionKeycloak + if (!data || !data.organization) return false + + const org = data.organization + // ตรวจสอบว่ามีค่าที่ไม่ใช่ null, undefined หรือ string ว่าง + const hasValue = (val: string | null | undefined) => + val && val.trim() !== '' + + return !!( + hasValue(org.root) || + hasValue(org.child1) || + hasValue(org.child2) || + hasValue(org.child3) || + hasValue(org.child4) + ) +}) + const modalTime = ref(false) // Dailog ลงเวลาเข้างานของคุณ const checkStatus = ref('') const statusCheckin = ref(true) // สถานะเวลา เข้า,ออก @@ -679,22 +700,40 @@ async function requestCamera() { /** Hook*/ onMounted(async () => { - isLoadingCheckTime.value = true + // เริ่มต้น clock เสมอ updateClock() clockInterval.value = setInterval(updateClock, 1000) - startChecking() //เช็ค status จาก คิว #1 + + // เพิ่ม event listeners สำหรับมือถือ + document.addEventListener('visibilitychange', handleVisibilityChange) + window.addEventListener('pagehide', handleAppClose) + + // ถ้ามีข้อมูลสังกัดแล้ว เริ่ม checking ได้เลย + if (hasOrganization.value) { + isLoadingCheckTime.value = true + startChecking() + } // เรียกแผนที่เฉพาะเมื่อยอมรับ privacy แล้ว if (privacyStore.isAccepted) { mapRef.value?.requestLocationPermission() requestCamera() } - - // เพิ่ม event listeners สำหรับมือถือ - document.addEventListener('visibilitychange', handleVisibilityChange) - window.addEventListener('pagehide', handleAppClose) }) +// เฝ้าดูการเปลี่ยนแปลงของ hasOrganization +// เพื่อเริ่ม startChecking เมื่อมีข้อมูลสังกัด +watch( + hasOrganization, + (newValue) => { + if (newValue && !isLoadingCheckTime.value) { + isLoadingCheckTime.value = true + startChecking() + } + }, + { immediate: false } +) + onBeforeUnmount(() => { resetCameraAndImage()