From 51575afd7a853757c0b58ed33ca0a88bf0432a36 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 9 Feb 2026 17:18:54 +0700 Subject: [PATCH] fix:genReport --- src/modules/10_registry/views/main.vue | 2 +- src/plugins/genreport.ts | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/modules/10_registry/views/main.vue b/src/modules/10_registry/views/main.vue index 33b8030..5e3a40c 100644 --- a/src/modules/10_registry/views/main.vue +++ b/src/modules/10_registry/views/main.vue @@ -58,7 +58,7 @@ async function onClickDownloadKp7(type: string) { store.profileId, dataStore.officerType == "OFFICER" ? "profile" : "profile-employee", ); - const fileName = type === "FULL" ? "ทปอ สามัญ" : "ประวัติแบบย่อ"; + const fileName = type === "FULL" ? "ทปอ. สามัญ" : "ประวัติแบบย่อ"; await http .get(url) .then(async (res) => { diff --git a/src/plugins/genreport.ts b/src/plugins/genreport.ts index d4b4a18..520ec00 100644 --- a/src/plugins/genreport.ts +++ b/src/plugins/genreport.ts @@ -22,7 +22,6 @@ async function genReport(data: any, fileName: string, type: string = "docx") { .then((res) => { const responseData = res.data; if (responseData) { - // --- ส่วนที่ปรับปรุง 1: กำหนด MIME Type ให้ตรงกับไฟล์ที่รับมาจริง --- const mimeType = type === "docx" ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" @@ -31,21 +30,15 @@ async function genReport(data: any, fileName: string, type: string = "docx") { const blob = new Blob([responseData], { type: mimeType }); const url = URL.createObjectURL(blob); - // --- ส่วนที่ปรับปรุง 2: จัดการชื่อไฟล์ (ป้องกันนามสกุลซ้อน) --- - // ตัดช่องว่างหัวท้าย และตัดนามสกุลไฟล์เดิมที่อาจติดมาออก (.pdf, .docx ฯลฯ) - const baseName = fileName.trim().replace(/\.[^/.]+$/, ""); + const baseName = fileName.trim(); const extension = type === "docx" ? "docx" : "pdf"; const link = document.createElement("a"); link.href = url; link.download = `${baseName}.${extension}`; - - // --- ส่วนที่ปรับปรุง 3: สำหรับ Android/Mobile --- - // บางครั้งการ click() ทันทีอาจถูก block หรือมีปัญหา ต้อง append เข้าไปจริงๆ document.body.appendChild(link); link.click(); - // หน่วงเวลาเล็กน้อยก่อนลบ element และ revoke URL เพื่อให้ Browser ทำงานเสร็จ setTimeout(() => { document.body.removeChild(link); URL.revokeObjectURL(url);