From 1698d86024844b0510c74ea3907f5e8f9a6334c9 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Thu, 31 Jul 2025 09:49:22 +0700 Subject: [PATCH] =?UTF-8?q?fixing=20await=20&=20clear=20code=20=20?= =?UTF-8?q?=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B9=80=E0=B8=81=E0=B9=87=E0=B8=9A?= =?UTF-8?q?=20dataProfile=20=E0=B8=95=E0=B8=AD=E0=B8=99=20get=20profile=20?= =?UTF-8?q?main=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/08_KPI/store.ts | 80 +++++++++++++++++++++---------- src/modules/08_KPI/views/form.vue | 6 +-- src/views/MainLayout.vue | 31 ++++++------ 3 files changed, 72 insertions(+), 45 deletions(-) diff --git a/src/modules/08_KPI/store.ts b/src/modules/08_KPI/store.ts index f9fc0a0..d18861d 100644 --- a/src/modules/08_KPI/store.ts +++ b/src/modules/08_KPI/store.ts @@ -19,35 +19,63 @@ export const useKpiDataStore = defineStore("KPIDate", () => { const work = ref(false); const tabMain = ref(""); const dataProfile = ref({ - profileId: null, - prefix: "", - rank: "", - firstName: "", - lastName: "", + amountSpecial: 0, + avatar: "", + avatarName: "", + birthDate: "", + child1: "", + child1DnaId: "", + child1Id: "", + child1ShortName: "", + child2: "", + child2DnaId: "", + child2Id: "", + child2ShortName: "", + child3: "", + child3DnaId: "", + child3Id: "", + child3ShortName: "", + child4: "", + child4DnaId: "", + child4Id: "", + child4ShortName: "", citizenId: "", - position: "", - posMaster: null, - posLevelName: null, - posLevelRank: null, - posLevelId: null, - posTypeName: null, - posTypeRank: null, - posTypeId: null, - posExecutiveName: "", - posExecutivePriority: null, + dateRetireLaw: "", + dateStart: "", + firstName: "", + isDirector: false, + isProbation: false, + keycloak: "", + lastName: "", + leaveDate: null, + node: 0, + nodeDnaId: "", + nodeId: "", + nodeShortName: "", posExecutiveId: null, - rootId: null, + posExecutiveName: null, + posExecutivePriority: null, + posLevelId: "", + posLevelName: "", + posLevelRank: 0, + posMaster: 0, + posMasterNo: 0, + posNo: "", + posTypeId: "", + posTypeName: "", + posTypeRank: 0, + position: "", + positionArea: null, + positionExecutiveField: null, + prefix: "", + profileId: "", + profileType: "", + rank: null, root: "", - child1Id: null, - child1: null, - child2Id: null, - child2: null, - child3Id: null, - child3: null, - child4Id: null, - child4: null, - node: null, - nodeId: null, + rootDnaId: "", + rootId: "", + rootShortName: "", + salary: 0, }); const dataEvaluation = ref({ diff --git a/src/modules/08_KPI/views/form.vue b/src/modules/08_KPI/views/form.vue index cb8cd2a..9bfd689 100644 --- a/src/modules/08_KPI/views/form.vue +++ b/src/modules/08_KPI/views/form.vue @@ -481,9 +481,9 @@ async function getProfile() { if (!store.dataProfile.profileId) { await http .get(config.API.profilePosition()) - .then(async (res) => { - const data = await res.data.result; - store.dataProfile = await data; + .then((res) => { + const data = res.data.result; + store.dataProfile = data; }) .catch((e) => { messageError($q, e); diff --git a/src/views/MainLayout.vue b/src/views/MainLayout.vue index 534beb3..fdbb1ef 100644 --- a/src/views/MainLayout.vue +++ b/src/views/MainLayout.vue @@ -16,6 +16,7 @@ import { } from "@/plugins/auth"; import { useDataStore } from "@/stores/data"; +import { useKpiDataStore } from "@/modules/08_KPI/store"; // landing page config url const configParam = { @@ -27,6 +28,7 @@ const router = useRouter(); const $q = useQuasar(); const dataStore = useDataStore(); +const kpiDataStore = useKpiDataStore(); const mixin = useCounterMixin(); const { @@ -44,15 +46,13 @@ const notiList = ref([]); const notiTrigger = ref(false); const currentRouteName = router.currentRoute.value.name; const tab = ref(currentRouteName); -const link = ref(""); const isSsoToken = ref(false); /** * เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้ */ onMounted(async () => { - await checkUser(); - await fetchTotolNotificate(); + await Promise.all([checkUser(), fetchTotolNotificate()]); const user = await tokenParsed(); const SSO_TOKEN = await getCookie("SSO"); isSsoToken.value = SSO_TOKEN === "y" ? true : false; @@ -63,9 +63,10 @@ async function checkUser() { await http .get(config.API.profilePosition()) .then(async (res) => { - const data = await res.data.result; + const data = res.data.result; await dataStore.getData(data); await dataStore.getProFileType(); + kpiDataStore.dataProfile = data; // Set dataProfile in kpiDataStore if (data.avatarName) { await getImg(data.profileId, data.avatarName); } else { @@ -77,17 +78,19 @@ async function checkUser() { component: CustomComponent, componentProps: { title: "ข้อความแจ้งเตือน", - message: err.response.data.message, + message: + err.response?.data?.message || "เกิดข้อผิดพลาดที่ไม่ทราบสาเหตุ", icon: "warning", color: "red", onlycancel: true, }, - }).onCancel(async () => { + }).onCancel(() => { showLoader(); - await logout(); - setTimeout(() => { - hideLoader(); - }, 1000); + logout().then(() => { + setTimeout(() => { + hideLoader(); + }, 1000); + }); }); }); } @@ -97,11 +100,7 @@ function getImg(id: string, pathName: string) { .get(config.API.fileByFile("ทะเบียนประวัติ", "โปรไฟล์", id, pathName)) .then((res) => { dataStore.profileImg = res.data.downloadUrl; - }) - .catch((e) => { - // messageError($q, e); - }) - .finally(() => {}); + }); } const totalNoti = ref(0); @@ -160,7 +159,7 @@ const doLogout = () => { async () => { await http.post(config.API.keycloakLogSSO, { text: "ออกจากระบบ" }); // authen with client - await logoutSSO(); + logoutSSO(); }, "ยืนยันการออกจากระบบ", "ต้องการออกจากระบบใช่หรือไม่"