ปรับ fetch profile
This commit is contained in:
parent
ca74197163
commit
48ef8c19a6
1 changed files with 6 additions and 24 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue