fix(HomeView): fetch Data
This commit is contained in:
parent
6c819a6097
commit
7ce5eab6f4
1 changed files with 45 additions and 6 deletions
|
|
@ -9,6 +9,7 @@ import http from '@/plugins/http'
|
||||||
import { useCounterMixin } from '@/stores/mixin'
|
import { useCounterMixin } from '@/stores/mixin'
|
||||||
import { usePermissions } from '@/composables/usePermissions'
|
import { usePermissions } from '@/composables/usePermissions'
|
||||||
import { usePrivacyStore } from '@/stores/privacy'
|
import { usePrivacyStore } from '@/stores/privacy'
|
||||||
|
import { usePositionKeycloakStore } from '@/stores/positionKeycloak'
|
||||||
|
|
||||||
import type { FormRef, OptionReason } from '@/interface/response/checkin'
|
import type { FormRef, OptionReason } from '@/interface/response/checkin'
|
||||||
|
|
||||||
|
|
@ -19,8 +20,28 @@ const { date2Thai, showLoader, hideLoader, messageError, dialogConfirm } = mixin
|
||||||
const $q = useQuasar()
|
const $q = useQuasar()
|
||||||
const { checkPrivacyAccepted } = usePermissions()
|
const { checkPrivacyAccepted } = usePermissions()
|
||||||
const privacyStore = usePrivacyStore()
|
const privacyStore = usePrivacyStore()
|
||||||
|
const positionKeycloakStore = usePositionKeycloakStore()
|
||||||
const MOCK_CHECK_DELAY_MS = 800
|
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<boolean>(false) // Dailog ลงเวลาเข้างานของคุณ
|
const modalTime = ref<boolean>(false) // Dailog ลงเวลาเข้างานของคุณ
|
||||||
const checkStatus = ref<string>('')
|
const checkStatus = ref<string>('')
|
||||||
const statusCheckin = ref<boolean>(true) // สถานะเวลา เข้า,ออก
|
const statusCheckin = ref<boolean>(true) // สถานะเวลา เข้า,ออก
|
||||||
|
|
@ -679,22 +700,40 @@ async function requestCamera() {
|
||||||
|
|
||||||
/** Hook*/
|
/** Hook*/
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
isLoadingCheckTime.value = true
|
// เริ่มต้น clock เสมอ
|
||||||
updateClock()
|
updateClock()
|
||||||
clockInterval.value = setInterval(updateClock, 1000)
|
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 แล้ว
|
// เรียกแผนที่เฉพาะเมื่อยอมรับ privacy แล้ว
|
||||||
if (privacyStore.isAccepted) {
|
if (privacyStore.isAccepted) {
|
||||||
mapRef.value?.requestLocationPermission()
|
mapRef.value?.requestLocationPermission()
|
||||||
requestCamera()
|
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(() => {
|
onBeforeUnmount(() => {
|
||||||
resetCameraAndImage()
|
resetCameraAndImage()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue