ทะเบียนประวัติ => DownloadFile

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-05-28 13:09:12 +07:00
parent ead02a85dd
commit b74e9550ed

View file

@ -259,11 +259,33 @@ async function fetchDataPersonal() {
}
function onClickDownloadKp7(type: string) {
if (type === "FULL") {
window.open(config.API.profileReportId(profileId.value));
} else if (type === "SHORT") {
window.open(config.API.profileKp7ShortId(profileId.value));
}
showLoader();
const url =
type === "FULL"
? config.API.profileReportId(profileId.value)
: config.API.profileKp7ShortId(profileId.value);
const fileName = type === "FULL" ? "ก.พ.7/ก.ก.1" : "ประวัติแบบย่อ";
http
.get(url, {
responseType: "arraybuffer", //
})
.then((res) => {
const data = res.data;
console.log(data);
const blob = new Blob([data], { type: "application/pdf" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `${fileName}.pdf`;
document.body.appendChild(link);
link.click();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/** ช่วยราชการ */