fix:getReport
This commit is contained in:
parent
4b40d051e0
commit
e6cc3142c5
3 changed files with 19 additions and 16 deletions
|
|
@ -17,7 +17,7 @@ const config = ref<any>({
|
||||||
MEET_URI: "meet.frappet.com",
|
MEET_URI: "meet.frappet.com",
|
||||||
LINK_EVALUATE_PUBLISH: "https://bma-ehr-publish.frappet.synology.me",
|
LINK_EVALUATE_PUBLISH: "https://bma-ehr-publish.frappet.synology.me",
|
||||||
API_REPORT_TEMPLATE_URI:
|
API_REPORT_TEMPLATE_URI:
|
||||||
"https://report-server.frappet.synology.me/api/v1/report-template",
|
"https://hrmsbkk.case-collection.com/api/v1/report-template",
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
API_URI: "http://localhost:5010/api/v1",
|
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 API_URL_SUPPORT = ref<string>(config.value[env.value].API_URL_SUPPORT);
|
||||||
const MEET_URI = ref<string>(config.value[env.value].MEET_URI);
|
const MEET_URI = ref<string>(config.value[env.value].MEET_URI);
|
||||||
const LINK_EVALUATE_PUBLISH = ref<string>(
|
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>(
|
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 {
|
export default {
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ async function onClickDownloadKp7(type: string) {
|
||||||
store.profileId,
|
store.profileId,
|
||||||
dataStore.officerType == "OFFICER" ? "profile" : "profile-employee",
|
dataStore.officerType == "OFFICER" ? "profile" : "profile-employee",
|
||||||
);
|
);
|
||||||
const fileName = type === "FULL" ? "ทปอ. สามัญ" : "ประวัติแบบย่อ";
|
const fileName = type === "FULL" ? "ทปอ สามัญ" : "ประวัติแบบย่อ";
|
||||||
await http
|
await http
|
||||||
.get(url)
|
.get(url)
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
|
|
|
||||||
|
|
@ -10,17 +10,13 @@ async function genReport(data: any, fileName: string, type: string = "docx") {
|
||||||
showLoader();
|
showLoader();
|
||||||
await axios
|
await axios
|
||||||
.post(config.API.reportTemplate + `/docx`, data, {
|
.post(config.API.reportTemplate + `/docx`, data, {
|
||||||
headers:
|
headers: {
|
||||||
type == "docx"
|
"content-Type": "application/json",
|
||||||
? {
|
accept:
|
||||||
accept:
|
type === "docx"
|
||||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
? "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
||||||
"content-Type": "application/json",
|
: "application/pdf",
|
||||||
}
|
},
|
||||||
: {
|
|
||||||
accept: "application/pdf",
|
|
||||||
"content-Type": "application/json",
|
|
||||||
},
|
|
||||||
responseType: "arraybuffer",
|
responseType: "arraybuffer",
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
@ -34,10 +30,17 @@ async function genReport(data: any, fileName: string, type: string = "docx") {
|
||||||
// สร้าง URL สำหรับไฟล์ Blob
|
// สร้าง URL สำหรับไฟล์ Blob
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
// 1. ตัดนามสกุลเดิมที่ติดมากับ fileName ออก (ถ้ามี)
|
||||||
|
const baseName = fileName.replace(/\.[^/.]+$/, "");
|
||||||
|
|
||||||
|
// 2. กำหนดนามสกุลใหม่ตามเงื่อนไข
|
||||||
|
const extension = type === "docx" ? "docx" : "pdf";
|
||||||
|
|
||||||
// สร้างลิงก์เพื่อดาวน์โหลดไฟล์
|
// สร้างลิงก์เพื่อดาวน์โหลดไฟล์
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
link.href = url;
|
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);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue