From e24f66f978419da9c777d7d726ad62e868defa64 Mon Sep 17 00:00:00 2001 From: "STW_TTTY\\stwtt" Date: Fri, 31 May 2024 16:08:20 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20download=20?= =?UTF-8?q?=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/10_registry/views/main.vue | 33 +++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/modules/10_registry/views/main.vue b/src/modules/10_registry/views/main.vue index 76694af..99db19a 100644 --- a/src/modules/10_registry/views/main.vue +++ b/src/modules/10_registry/views/main.vue @@ -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(""); const router = useRouter(); const tab = ref("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(); + }); } /**