แก้ download ทะเบียนประวัติ

This commit is contained in:
STW_TTTY\stwtt 2024-05-31 16:08:20 +07:00
parent 21fb81243c
commit e24f66f978

View file

@ -21,7 +21,7 @@ import { useQuasar } from "quasar";
const store = useRegistryInFormationStore();
const $q = useQuasar();
const mixin = useCounterMixin();
const { messageError, dialogConfirm } = mixin;
const { messageError, dialogConfirm ,showLoader,hideLoader } = mixin;
const profileImg = ref<string>("");
const router = useRouter();
const tab = ref<string>("information");
@ -89,11 +89,32 @@ function getType() {
}
function onClickDownloadKp7(type: string) {
if (type === "FULL") {
window.open(config.API.profileReportId(store.profileId));
} else if (type === "SHORT") {
window.open(config.API.profileKp7ShortId(store.profileId));
}
showLoader();
const url =
type === "FULL"
? config.API.profileReportId(store.profileId)
: config.API.profileKp7ShortId(store.profileId);
const fileName = type === "FULL" ? "ก.พ.7/ก.ก.1" : "ประวัติแบบย่อ";
http
.get(url, {
responseType: "arraybuffer", //
})
.then((res) => {
const data = res.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();
});
}
/**