ปรับ 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*/ /** emit*/
const emit = defineEmits(["update:modal"]); const emit = defineEmits(["update:modal"]);
/** interface*/
interface StatusLoad {
val: boolean;
val2: boolean;
val3: boolean;
}
/** ตัวแปร*/ /** ตัวแปร*/
const modal = ref<boolean>(false); const modal = ref<boolean>(false);
const statusLoad = ref<StatusLoad>({ val: false, val2: false, val3: false }); //
const avatar = reactive<Avatar>({ const avatar = reactive<Avatar>({
avatar: "", avatar: "",
fullname: "", fullname: "",
@ -119,17 +111,14 @@ async function fetchInformation(id: string) {
avatar.position = data.position ? data.position : "-"; avatar.position = data.position ? data.position : "-";
if (data.avatarName) { if (data.avatarName) {
fetchProfile(data.id as string); fetchProfile(data.id as string,data.avatarName);
} else {
statusLoad.value.val = true;
} }
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
}) })
.finally(() => { .finally(() => {
statusLoad.value.val2 = true; hideLoader();
loaderFunction();
}); });
} }
@ -162,17 +151,10 @@ async function fetchProfileGov(id: string) {
messageError($q, err); messageError($q, err);
}) })
.finally(() => { .finally(() => {
statusLoad.value.val3 = true; hideLoader();
loaderFunction();
}); });
} }
/** functoion เช็คการโหลดของข้อมูล*/
function loaderFunction() {
const allTrue = Object.values(statusLoad.value).every((val) => val);
allTrue && hideLoader();
}
function redirecToRegistry() { function redirecToRegistry() {
router.push(`/registry-new/${props.id}`); router.push(`/registry-new/${props.id}`);
modal.value = false; modal.value = false;
@ -199,15 +181,15 @@ watch(modal, (newValue) => {
} }
}); });
async function fetchProfile(id: string) { async function fetchProfile(id: string, avatarName: string) {
showLoader(); showLoader();
await http await http
.get(config.API.fileByFile("ทะเบียนประวัติ", "โปรไฟล์", id, fileName.value)) .get(config.API.fileByFile("ทะเบียนประวัติ", "โปรไฟล์", id, avatarName))
.then(async (res) => { .then(async (res) => {
avatar.avatar = res.data.downloadUrl; avatar.avatar = res.data.downloadUrl;
}) })
.finally(() => { .finally(() => {
statusLoad.value.val = true; hideLoader();
}); });
} }
</script> </script>