refactor code & fixed location

This commit is contained in:
Warunee Tamkoo 2026-04-27 19:21:23 +07:00
parent 41c1aa8e45
commit 487a6b520e
23 changed files with 566 additions and 145 deletions

View file

@ -5,7 +5,7 @@ import { useQuasar } from 'quasar'
import { useRouter } from 'vue-router'
import http from '@/plugins/http'
import config from '@/app.config'
import { useChekIn } from '@/stores/chekin'
import { useCheckIn } from '@/stores/checkin'
import { useCounterMixin } from '@/stores/mixin'
import { calculateFiscalYear } from '@/utils/function'
@ -14,7 +14,7 @@ import ToolBar from '@/components/ToolBar.vue' // เมนู Herder
const $q = useQuasar() // noti quasar
const router = useRouter()
const stores = useChekIn()
const stores = useCheckIn()
const { showLoader, hideLoader, messageError } = useCounterMixin()
const { fetchHistoryList } = stores
@ -195,7 +195,7 @@ watch(
:tab="stores.tab"
/>
<TableHistory
:fetchData="functionFetch"
:fetch-data="functionFetch"
:page-size="pageSize"
:total="total"
:page="page"

View file

@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, reactive, onMounted, watch, onBeforeUnmount } from 'vue'
import { useQuasar } from 'quasar'
import moment from 'moment'
import { format } from 'date-fns'
import Camera from 'simple-vue-camera'
import config from '@/app.config'
@ -69,15 +69,16 @@ const formattedM = ref()
const formattedH = ref()
const formattedHH = ref()
const formattedA = ref()
const clockInterval = ref<number | NodeJS.Timeout | undefined>()
/** function อัพเดทเวลา*/
function updateClock() {
const date = Date.now()
const hh = moment(date).format('HH')
const mm = moment(date).format('mm')
const ss = moment(date).format('ss')
const HH = moment(date).format('hh')
const A = moment(date).format('a')
const date = new Date()
const hh = format(date, 'HH')
const mm = format(date, 'mm')
const ss = format(date, 'ss')
const HH = format(date, 'hh')
const A = format(date, 'a')
formattedS.value = ss
formattedM.value = mm
@ -85,7 +86,6 @@ function updateClock() {
formattedHH.value = HH
formattedA.value = A
}
setInterval(updateClock, 1000)
/** form-data */
const formLocation = reactive({
@ -137,7 +137,10 @@ async function getDelayedFreshPosition() {
maximumAge: 0,
})
await wait(MOCK_CHECK_DELAY_MS)
// Only add delay in development mode for testing
if (import.meta.env.DEV) {
await wait(MOCK_CHECK_DELAY_MS)
}
try {
return await getCurrentPositionAsync({
@ -191,7 +194,7 @@ const availableCameras = ref<any[]>([])
const currentCameraIndex = ref<number>(0)
const currentCameraType = ref<'front' | 'back' | 'unknown'>('unknown')
const intervalId = ref<number | undefined>(undefined) // interval
const intervalId = ref<number | NodeJS.Timeout | undefined>(undefined) // interval
/**
* เรมจาก onMounted #1 เช status
@ -246,18 +249,6 @@ async function fetchCheckStatus() {
}
}
/** ตัวเก่าก่อนเปลี่ยน */
// async function stopChecking() {
// if (intervalId.value !== undefined) {
// clearInterval(intervalId.value) // interval
// setTimeout(() => {
// fetchCheckTime()
// }, 1000)
// intervalId.value = undefined //
// }
// }
/**
* เรมจาก onMounted #3 เช status
*
@ -674,6 +665,7 @@ async function requestCamera() {
onMounted(async () => {
isLoadingCheckTime.value = true
updateClock()
clockInterval.value = setInterval(updateClock, 1000)
startChecking() // status #1
// privacy
@ -690,6 +682,12 @@ onMounted(async () => {
onBeforeUnmount(() => {
resetCameraAndImage()
// clock interval
if (clockInterval.value !== undefined) {
clearInterval(clockInterval.value)
clockInterval.value = undefined
}
// interval
if (intervalId.value !== undefined) {
clearInterval(intervalId.value)
@ -1279,7 +1277,7 @@ watch(
</div>
<div class="col-12 text-center row q-pt-md">
<div class="col-12 text-subtitle1 text-weight-medium text-secondary">
นทใกลเคยง {{ formLocation.POI ?? formLocation.POI }}
นทใกลเคยง {{ formLocation.POI }}
</div>
<div class="col-12 text-subtitle1 text-weight-medium text-secondary">
{{ location }}
@ -1318,7 +1316,7 @@ watch(
.card-container {
position: relative;
overflow: hidden;
height: autu; /* Adjust as needed */
height: auto; /* Adjust as needed */
background: #f5f5f5;
height: 35vh !important;
box-shadow: none !important;
@ -1327,7 +1325,7 @@ watch(
.card-container-xs {
position: relative;
overflow: hidden;
height: autu; /* Adjust as needed */
height: auto; /* Adjust as needed */
background: #ffffff;
height: 35vh !important;
border-radius: 10px;

View file

@ -10,6 +10,7 @@ import { logout, tokenParsed, getCookie, gotoLeavePage } from '@/plugins/auth'
import { useCounterMixin } from '@/stores/mixin'
import { usePrivacyStore } from '@/stores/privacy'
import { usePositionKeycloakStore } from '@/stores/positionKeycloak'
import type { KeycloakPosition } from '@/interface/keycloak-position'
// import type { notiType } from '@/interface/index/Main'
// import type { Noti } from '@/interface/response/Main'
@ -144,6 +145,8 @@ function onClickLogout() {
ok: 'ยืนยัน',
persistent: true,
}).onOk(async () => {
// positionKeycloak logout
positionKeycloakStore.clearPositionKeycloak()
await http.post(config.API.keycloakLogSSO, { text: 'ออกจากระบบ' })
await logout()
})
@ -174,16 +177,50 @@ const landingPageUrl = ref<string>(configParam.landingPageUrl)
/** ฟังก์ชันเรียกข้อมูลผู้ใช่งาน*/
async function fetchKeycloakPosition() {
// store ( localStorage)
const existingData = positionKeycloakStore.dataPositionKeycloak
if (existingData) {
//
privacyStore.modalPrivacy = !existingData.privacyCheckin
privacyStore.setAccepted(existingData.privacyCheckin)
//
if (existingData.avatarName) {
getImg(existingData.profileId, existingData.avatarName)
} else {
profileImg.value = avatar
}
return
}
// fetch API
await http
.get(config.API.keycloakPosition())
.then(async (res) => {
const data = await res.data.result
positionKeycloakStore.setPositionKeycloak(data)
privacyStore.modalPrivacy = !data.privacyCheckin ? true : false
privacyStore.setAccepted(data.privacyCheckin)
const apiData = await res.data.result
// Map API response to KeycloakPosition interface
const keycloakData: KeycloakPosition = {
privacyCheckin: apiData.privacyCheckin ?? false,
avatarName: apiData.avatarName,
profileId: apiData.profileId,
organization: {
root: apiData.root,
child1: apiData.child1,
child2: apiData.child2,
child3: apiData.child3,
child4: apiData.child4,
},
}
positionKeycloakStore.setPositionKeycloak(keycloakData)
privacyStore.modalPrivacy = !keycloakData.privacyCheckin
privacyStore.setAccepted(keycloakData.privacyCheckin)
//
if (data.avatarName) {
getImg(data.profileId, data.avatarName)
if (keycloakData.avatarName) {
getImg(keycloakData.profileId, keycloakData.avatarName)
} else {
profileImg.value = avatar
}
@ -297,6 +334,7 @@ onMounted(async () => {
const checkTokenParsed = await tokenParsed()
const SSO_TOKEN = await getCookie('SSO')
isSsoToken.value = SSO_TOKEN === 'y' ? true : false
if (checkTokenParsed != null) {
fullName.value = checkTokenParsed.name
}