From 48ef8c19a68a4e1f0828387de38cbf8e270e57f6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 24 May 2024 17:41:53 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20fetch=20?= =?UTF-8?q?profile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Dialogs/PopupPersonalNew.vue | 30 +++++---------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/components/Dialogs/PopupPersonalNew.vue b/src/components/Dialogs/PopupPersonalNew.vue index 33182a51f..109ebd3f9 100644 --- a/src/components/Dialogs/PopupPersonalNew.vue +++ b/src/components/Dialogs/PopupPersonalNew.vue @@ -40,16 +40,8 @@ const props = defineProps({ /** emit*/ const emit = defineEmits(["update:modal"]); -/** interface*/ -interface StatusLoad { - val: boolean; - val2: boolean; - val3: boolean; -} - /** ตัวแปร*/ const modal = ref(false); -const statusLoad = ref({ val: false, val2: false, val3: false }); // เช็คสถานะการโหลด const avatar = reactive({ avatar: "", fullname: "", @@ -119,17 +111,14 @@ async function fetchInformation(id: string) { avatar.position = data.position ? data.position : "-"; if (data.avatarName) { - fetchProfile(data.id as string); - } else { - statusLoad.value.val = true; + fetchProfile(data.id as string,data.avatarName); } }) .catch((err) => { messageError($q, err); }) .finally(() => { - statusLoad.value.val2 = true; - loaderFunction(); + hideLoader(); }); } @@ -162,17 +151,10 @@ async function fetchProfileGov(id: string) { messageError($q, err); }) .finally(() => { - statusLoad.value.val3 = true; - loaderFunction(); + hideLoader(); }); } -/** functoion เช็คการโหลดของข้อมูล*/ -function loaderFunction() { - const allTrue = Object.values(statusLoad.value).every((val) => val); - allTrue && hideLoader(); -} - function redirecToRegistry() { router.push(`/registry-new/${props.id}`); modal.value = false; @@ -199,15 +181,15 @@ watch(modal, (newValue) => { } }); -async function fetchProfile(id: string) { +async function fetchProfile(id: string, avatarName: string) { showLoader(); await http - .get(config.API.fileByFile("ทะเบียนประวัติ", "โปรไฟล์", id, fileName.value)) + .get(config.API.fileByFile("ทะเบียนประวัติ", "โปรไฟล์", id, avatarName)) .then(async (res) => { avatar.avatar = res.data.downloadUrl; }) .finally(() => { - statusLoad.value.val = true; + hideLoader(); }); }