From b74e9550ed086ace3cd3b3bb5b2f72f7de79cb71 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Tue, 28 May 2024 13:09:12 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5?= =?UTF-8?q?=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1?= =?UTF-8?q?=E0=B8=95=E0=B8=B4=20=3D>=20DownloadFile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../04_registryNew/views/detailView.vue | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/modules/04_registryNew/views/detailView.vue b/src/modules/04_registryNew/views/detailView.vue index d7b3e6f7c..c259d03d0 100644 --- a/src/modules/04_registryNew/views/detailView.vue +++ b/src/modules/04_registryNew/views/detailView.vue @@ -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(); + }); } /** ช่วยราชการ */