From 17c5c4e12048eae5630b261b98682cfd400cee2a Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 17 Jan 2025 17:56:14 +0700 Subject: [PATCH 1/4] fix --- src/views/HomeView.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 857a040..23b8c0b 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -232,6 +232,7 @@ async function confirm() { timeChickin.value = timeString setTimeout(() => { modalTime.value = true + remark.value = '' hideLoader() }, 2000) }) From c3ed910fb96e324a6556af9a7be843985ace846b Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Mon, 20 Jan 2025 16:13:55 +0700 Subject: [PATCH 2/4] fixing landing redirect --- src/views/MainView.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/MainView.vue b/src/views/MainView.vue index c4b155c..bbc733a 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -143,7 +143,7 @@ function onLoad(index: number, done: Function) { // landing page redirect const landingPageUrl = ref(getLandingUrl()) function getLandingUrl() { - return `${configParam.landingPageUrl}/landing` + return configParam.landingPageUrl } /** ฟังก์ชันเรียกข้อมูลผู้ใช่งาน*/ From 3f79bde5435a4ff599b13c607068ef1992689011 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 29 Jan 2025 16:25:47 +0700 Subject: [PATCH 3/4] =?UTF-8?q?fix=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20check=20Status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/api.checkin.ts | 1 + src/views/HomeView.vue | 149 +++++++++++++++++++++++++++-------------- 2 files changed, 98 insertions(+), 52 deletions(-) diff --git a/src/api/api.checkin.ts b/src/api/api.checkin.ts index 49143ca..f9fb724 100644 --- a/src/api/api.checkin.ts +++ b/src/api/api.checkin.ts @@ -5,6 +5,7 @@ const urlFile = `${env.API_URI}/salary` export default { checkin: () => `${leave}/check-in`, checkTime: () => `${leave}/check-time`, + checkStatus: () => `${leave}/check-status`, keycloakLogSSO: `${env.API_URI}/org/keycloak/log/sso`, keycloakPosition: () => `${env.API_URI}/org/profile/keycloak/position`, diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 23b8c0b..a043f79 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -51,9 +51,7 @@ const formattedS = ref() const formattedM = ref() const formattedH = ref() -/** - * function อัพเดทเวลา - */ +/** function อัพเดทเวลา*/ function updateClock() { const date = Date.now() const hh = moment(date).format('HH') @@ -103,9 +101,7 @@ const options = ref([ 'อื่นๆ', ]) -/** - * function เลือกสถานที่ - */ +/** function เลือกสถานที่*/ function selectLocation() { if (model.value === 'อื่นๆ') { useLocation.value = '' @@ -121,51 +117,44 @@ const img = ref(undefined) const photoWidth = ref(350) const photoHeight = ref(350) -/** - * function เปิดกล้อง - */ +/** function เปิดกล้อง*/ async function openCamera() { // change camera device if (cameraIsOn.value) { - camera.value?.stop() + await camera.value?.stop() } else { await camera.value?.start() - changeCamera() + await changeCamera() // ต้องรอให้ start() เสร็จก่อน } cameraIsOn.value = !cameraIsOn.value } -/** - * change camera device - */ +/** change camera device*/ async function changeCamera() { const devices: any = await camera.value?.devices(['videoinput']) const device = await devices[0] camera.value?.changeCamera(device.deviceId) } -/** - * function ถ่ายรูป - */ +/** function ถ่ายรูป*/ async function capturePhoto() { const imageBlob: any = await camera.value?.snapshot( { width: photoWidth.value, height: photoHeight.value }, 'image/png', 0.5 ) + if (!imageBlob) return const fileName = 'photo.png' //ไฟล์รูป const file = new File([imageBlob], fileName, { type: 'image/png' }) fileImg.value = file //แสดงรูป - camera.value?.stop() + await camera.value?.stop() const url = URL.createObjectURL(imageBlob) img.value = url } -/** - * function เปลี่ยนรูปภาพ - */ +/** function เปลี่ยนรูปภาพ*/ function refreshPhoto() { img.value = undefined camera.value?.start() @@ -179,9 +168,7 @@ const objectRef: FormRef = { useLocation: useLocationRef, } -/** - * function ตรวจสอบค่าว่างของ input - */ +/** function ตรวจสอบค่าว่างของ input*/ function validateForm() { const hasError = [] for (const key in objectRef) { @@ -200,9 +187,7 @@ function validateForm() { const timeChickin = ref('') //เวลาเข้างาน,เวลาออกงาน -/** - * function ยืนยันการลงเวลาเข้า - ออก - */ +/** function ยืนยันการลงเวลาเข้า - ออก*/ async function confirm() { showLoader() const isLocation = workplace.value === 'in-place' //*true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง @@ -221,6 +206,7 @@ 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', @@ -230,37 +216,33 @@ async function confirm() { dateObject ) timeChickin.value = timeString - setTimeout(() => { - modalTime.value = true - remark.value = '' - hideLoader() - }, 2000) + modalTime.value = true + remark.value = '' }) .catch((err) => { - hideLoader() messageError($q, err) }) + .finally(() => { + hideLoader() + }) } -/** - * ปิด popup แสดงการลงเวลา - */ +/** ปิด popup แสดงการลงเวลา*/ async function onClickConfirm() { showLoader() - setTimeout(async () => { - if (!stetusCheckin.value) { - stetusCheckin.value = true - } - await fetchCheckTime() - }, 2000) + if (!stetusCheckin.value) { + stetusCheckin.value = true + } + + await fetchCheckTime() + startChecking() + cameraIsOn.value = false img.value = undefined modalTime.value = false } -/** - * เลือกสถานที่ทำงาน - */ +/** เลือกสถานที่ทำงาน*/ function updateWorkplace() { useLocation.value = '' model.value = '' @@ -277,10 +259,52 @@ 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 = 'กำลังดำเนินงาน' + } else { + isDisabledCheckTime.value = false + msgCheckTime.value = '' + stopChecking() // หยุดการทำงาน + fetchCheckTime() + console.log('Response เป็น false, หยุด interval') + } + } catch (error) { + console.log('เกิดข้อผิดพลาด', error) + stopChecking() // หยุดการทำงาน + } +} +const intervalId = ref(undefined) // ต้องใช้ตัวแปรเก็บค่า interval + +function startChecking() { + if (intervalId.value === undefined) { + // ป้องกันการสร้าง interval ซ้ำ + intervalId.value = setInterval(fetchCheckStatus, 3000) + } +} + +function stopChecking() { + if (intervalId.value !== undefined) { + clearInterval(intervalId.value) // หยุด interval + fetchCheckTime() + intervalId.value = undefined // รีเซ็ตค่า + } +} + /** Hook*/ onMounted(async () => { - await fetchCheckTime() + // await fetchCheckTime() updateClock() + startChecking() }) @@ -291,10 +315,29 @@ onMounted(async () => {
- + + + + ลงเวลาออกงาน (รอประมวลผล) + + + + ลงเวลาเข้างาน (รอประมวลผล) + + + ลงเวลาเข้างาน - ลงเวลาออกงาน + + ลงเวลาออกงาน
@@ -323,7 +366,9 @@ onMounted(async () => {
- +
+ +
@@ -344,6 +389,7 @@ onMounted(async () => {
+ { *หมายเหตุ คลิกลงเวลาเข้างานแล้วระบบจะลงเวลาทันที

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 4/4] 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 () => {
--> - ลงเวลาออกงาน (รอประมวลผล) + ลงเวลาออกงาน (ระบบกำลังประมวลผล) - ลงเวลาเข้างาน (รอประมวลผล) + ลงเวลาเข้างาน (ระบบกำลังประมวลผล)