ปรับ fetch profile

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-05-24 17:41:53 +07:00
parent ca74197163
commit 48ef8c19a6

View file

@ -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<boolean>(false);
const statusLoad = ref<StatusLoad>({ val: false, val2: false, val3: false }); //
const avatar = reactive<Avatar>({
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();
});
}
</script>