diff --git a/src/api/api.checkin.ts b/src/api/api.checkin.ts index a0078fa..8172c07 100644 --- a/src/api/api.checkin.ts +++ b/src/api/api.checkin.ts @@ -13,8 +13,9 @@ export default { fileByFile: (name: string, group: string, id: string, fileName: string) => `${urlFile}/file/${name}/${group}/${id}/${fileName}`, - changePassword:`${orgKeycloak}/user/change-password`, - resetPassword:`${orgKeycloak}/user/reset-password`, + changePassword: `${orgKeycloak}/user/change-password`, + resetPassword: `${orgKeycloak}/user/reset-password`, - checkoutCheck:`${leave}/user/checkout-check` + checkoutCheck: `${leave}/user/checkout-check`, + privacy: `${env.API_URI}/org/profile/privacy`, } diff --git a/src/components/AscGISMap.vue b/src/components/AscGISMap.vue index b32e32a..c9ab17d 100644 --- a/src/components/AscGISMap.vue +++ b/src/components/AscGISMap.vue @@ -4,9 +4,11 @@ import { loadModules } from 'esri-loader' import axios from 'axios' import { useCounterMixin } from '@/stores/mixin' import { useQuasar } from 'quasar' +import { usePrivacyStore } from '@/stores/privacy' const mixin = useCounterMixin() const { messageError } = mixin +const privacyStore = usePrivacyStore() // import type { LocationObject } from '@/interface/index/Main' const mapElement = ref(null) @@ -200,6 +202,16 @@ async function initializeMap() { const locationGranted = ref(false) // Function to request location permission const requestLocationPermission = () => { + // เช็คสิทธิ์ privacy ก่อนเข้าถึงแผนที่ + if (!privacyStore.isAccepted) { + $q.notify({ + type: 'warning', + message: 'กรุณายอมรับนโยบายคุ้มครองข้อมูลส่วนบุคคลก่อนใช้งานแผนที่', + position: 'top', + }) + return + } + if (!navigator.geolocation) { messageError( $q, @@ -261,7 +273,10 @@ defineExpose({ }) onMounted(async () => { - await initializeMap() + // เรียกแผนที่เฉพาะเมื่อยอมรับ privacy แล้ว + if (privacyStore.isAccepted) { + await initializeMap() + } }) diff --git a/src/components/PopupPrivacy.vue b/src/components/PopupPrivacy.vue new file mode 100644 index 0000000..dd9debf --- /dev/null +++ b/src/components/PopupPrivacy.vue @@ -0,0 +1,352 @@ + + + + + diff --git a/src/composables/usePermissions.ts b/src/composables/usePermissions.ts new file mode 100644 index 0000000..dd624d8 --- /dev/null +++ b/src/composables/usePermissions.ts @@ -0,0 +1,52 @@ +import { useQuasar } from 'quasar' +import { usePrivacyStore } from '@/stores/privacy' + +export function usePermissions() { + const $q = useQuasar() + const privacyStore = usePrivacyStore() + + // const checkCameraPermission = (): boolean => { + // if (!privacyStore.isAccepted) { + // privacyStore.modalPrivacy = true + // $q.notify({ + // type: 'warning', + // message: 'กรุณายอมรับนโยบายคุ้มครองข้อมูลส่วนบุคคลก่อนใช้งานกล้อง', + // position: 'top', + // }) + // return false + // } + // return true + // } + + // const checkLocationPermission = (): boolean => { + // if (!privacyStore.isAccepted) { + // privacyStore.modalPrivacy = true + // $q.notify({ + // type: 'warning', + // message: 'กรุณายอมรับนโยบายคุ้มครองข้อมูลส่วนบุคคลก่อนใช้งานแผนที่', + // position: 'top', + // }) + // return false + // } + // return true + // } + + const checkPrivacyAccepted = (): boolean => { + if (!privacyStore.isAccepted) { + privacyStore.modalPrivacy = true + $q.notify({ + type: 'warning', + message: 'กรุณายอมรับนโยบายคุ้มครองข้อมูลส่วนบุคคลก่อนใช้งาน', + position: 'top', + }) + return false + } + return true + } + + return { + // checkCameraPermission, + // checkLocationPermission, + checkPrivacyAccepted, + } +} diff --git a/src/stores/privacy.ts b/src/stores/privacy.ts new file mode 100644 index 0000000..ce2dc83 --- /dev/null +++ b/src/stores/privacy.ts @@ -0,0 +1,22 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +export const usePrivacyStore = defineStore('privacy', () => { + const modalPrivacy = ref(false) + const isAccepted = ref(false) + + const setAccepted = (value: boolean) => { + isAccepted.value = value + } + + const reset = () => { + isAccepted.value = false + } + + return { + modalPrivacy, + isAccepted, + setAccepted, + reset, + } +}) diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index a64742b..34369c2 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -7,6 +7,8 @@ import Camera from 'simple-vue-camera' import config from '@/app.config' import http from '@/plugins/http' import { useCounterMixin } from '@/stores/mixin' +import { usePermissions } from '@/composables/usePermissions' +import { usePrivacyStore } from '@/stores/privacy' import type { FormRef, OptionReason } from '@/interface/response/checkin' @@ -15,6 +17,8 @@ import MapCheck from '@/components/AscGISMap.vue' const mixin = useCounterMixin() const { date2Thai, showLoader, hideLoader, messageError, dialogConfirm } = mixin const $q = useQuasar() +const { checkPrivacyAccepted } = usePermissions() +const privacyStore = usePrivacyStore() const modalTime = ref(false) // Dailog ลงเวลาเข้างานของคุณ const checkStatus = ref('') @@ -261,6 +265,11 @@ async function stopChecking() { /** function เปิดกล้อง*/ async function openCamera() { + // เช็คสิทธิ์ privacy ก่อนเปิดกล้อง + if (!checkPrivacyAccepted()) { + return + } + // change camera device if (cameraIsOn.value) { await camera.value?.stop() @@ -336,6 +345,11 @@ const timeChickin = ref('') //เวลาเข้างาน,เว /** function ยืนยันการลงเวลาเข้า - ออก*/ async function confirm() { + // เช็คสิทธิ์ privacy ก่อนใช้งานแผนที่และกล้อง + if (!checkPrivacyAccepted()) { + return + } + if (!formLocation.POI || !formLocation.lat || !formLocation.lng) { mapRef.value?.requestLocationPermission() return @@ -473,7 +487,11 @@ onMounted(async () => { isLoadingCheckTime.value = true updateClock() startChecking() //เช็ค status จาก คิว #1 - mapRef.value?.requestLocationPermission() + + // เรียกแผนที่เฉพาะเมื่อยอมรับ privacy แล้ว + if (privacyStore.isAccepted) { + mapRef.value?.requestLocationPermission() + } }) diff --git a/src/views/MainView.vue b/src/views/MainView.vue index 572e08b..18c30d0 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -8,13 +8,16 @@ import config from '@/app.config' import avatar from '@/assets/avatar_user.jpg' import { logout, tokenParsed, getCookie } from '@/plugins/auth' import { useCounterMixin } from '@/stores/mixin' +import { usePrivacyStore } from '@/stores/privacy' import type { notiType } from '@/interface/index/Main' import type { Noti } from '@/interface/response/Main' import DialogHeader from '@/components/DialogHeader.vue' +import PopupPrivacy from '@/components/PopupPrivacy.vue' const mixin = useCounterMixin() +const privacyStore = usePrivacyStore() const { date2Thai, hideLoader, @@ -23,6 +26,7 @@ const { success, showLoader, } = mixin + const router = useRouter() const $q = useQuasar() @@ -53,6 +57,7 @@ const reNewPassWord = ref('') const isPwdOld = ref(true) const isPwdNewOld = ref(true) const isPwdReNewOld = ref(true) + /** * ฟังก์ชั่นดึงข้อมูลจำนวนการแจ้งเตือน */ @@ -168,6 +173,7 @@ async function fetchKeycloakPosition() { .get(config.API.keycloakPosition()) .then(async (res) => { const data = await res.data.result + privacyStore.modalPrivacy = !data.privacyCheckin ? true : false //เช็คว่ามีรูปไหม ถ้ามีรูปเรียกข้อมูลรูป if (data.avatarName) { await getImg(data.profileId, data.avatarName) @@ -599,6 +605,8 @@ onMounted(async () => { + +