fix:getReport

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-02-09 16:34:20 +07:00
parent 4b40d051e0
commit e6cc3142c5
3 changed files with 19 additions and 16 deletions

View file

@ -17,7 +17,7 @@ const config = ref<any>({
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<string>(config.value[env.value].API_URI);
const API_URL_SUPPORT = ref<string>(config.value[env.value].API_URL_SUPPORT);
const MEET_URI = ref<string>(config.value[env.value].MEET_URI);
const LINK_EVALUATE_PUBLISH = ref<string>(
config.value[env.value].LINK_EVALUATE_PUBLISH
config.value[env.value].LINK_EVALUATE_PUBLISH,
);
const API_REPORT_TEMPLATE_URI = ref<string>(
config.value[env.value].API_REPORT_TEMPLATE_URI
config.value[env.value].API_REPORT_TEMPLATE_URI,
);
export default {

View file

@ -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) => {

View file

@ -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();