diff --git a/src/api/index.ts b/src/api/index.ts index e5e225c..6e753fb 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -17,7 +17,7 @@ const config = ref({ MEET_URI: "meet.frappet.com", LINK_EVALUATE_PUBLISH: "https://bma-ehr-publish.frappet.synology.me", API_REPORT_TEMPLATE_URI: - "https://report-server.frappet.synology.me/api/v1/report-template", + "https://hrmsbkk.case-collection.com/api/v1/report-template", }, test: { API_URI: "http://localhost:5010/api/v1", @@ -36,10 +36,10 @@ const API_URI = ref(config.value[env.value].API_URI); const API_URL_SUPPORT = ref(config.value[env.value].API_URL_SUPPORT); const MEET_URI = ref(config.value[env.value].MEET_URI); const LINK_EVALUATE_PUBLISH = ref( - config.value[env.value].LINK_EVALUATE_PUBLISH + config.value[env.value].LINK_EVALUATE_PUBLISH, ); const API_REPORT_TEMPLATE_URI = ref( - config.value[env.value].API_REPORT_TEMPLATE_URI + config.value[env.value].API_REPORT_TEMPLATE_URI, ); export default { diff --git a/src/modules/10_registry/views/main.vue b/src/modules/10_registry/views/main.vue index 5e3a40c..33b8030 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 8b2b917..d26eb62 100644 --- a/src/plugins/genreport.ts +++ b/src/plugins/genreport.ts @@ -10,17 +10,13 @@ async function genReport(data: any, fileName: string, type: string = "docx") { showLoader(); await axios .post(config.API.reportTemplate + `/docx`, data, { - headers: - type == "docx" - ? { - accept: - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - "content-Type": "application/json", - } - : { - accept: "application/pdf", - "content-Type": "application/json", - }, + headers: { + "content-Type": "application/json", + accept: + type === "docx" + ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + : "application/pdf", + }, responseType: "arraybuffer", }) .then((res) => { @@ -34,10 +30,17 @@ async function genReport(data: any, fileName: string, type: string = "docx") { // สร้าง URL สำหรับไฟล์ Blob const url = URL.createObjectURL(blob); + // 1. ตัดนามสกุลเดิมที่ติดมากับ fileName ออก (ถ้ามี) + const baseName = fileName.replace(/\.[^/.]+$/, ""); + + // 2. กำหนดนามสกุลใหม่ตามเงื่อนไข + const extension = type === "docx" ? "docx" : "pdf"; + // สร้างลิงก์เพื่อดาวน์โหลดไฟล์ const link = document.createElement("a"); link.href = url; - link.download = `${fileName}.${type === "docx" ? "docx" : "pdf"}`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด + link.download = `${baseName}.${extension}`; + // link.download = `${fileName}.${type === "docx" ? "docx" : "pdf"}`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด document.body.appendChild(link); link.click();