diff --git a/src/api/evaluate/api.evaluate.ts b/src/api/evaluate/api.evaluate.ts index 99b9f37..b8ae7c5 100644 --- a/src/api/evaluate/api.evaluate.ts +++ b/src/api/evaluate/api.evaluate.ts @@ -1,7 +1,3 @@ import env from "../index"; -const report = `${env.API_GEN_REPORT}`; - -export default { - reportTemplate: () => `${report}/report-template/docx`, -}; +export default {}; diff --git a/src/api/index.ts b/src/api/index.ts index 10e9cfc..d001eaf 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -11,7 +11,6 @@ const config = ref({ // API_URI: "https://localhost:7260/api", API_URI: "https://bma-ehr.frappet.synology.me/api/v1", MEET_URI: "meet.frappet.com", - API_GEN_REPORT: "https://report-server.frappet.synology.me/api/v1", }, test: { API_URI: "http://localhost:5010/api/v1", @@ -27,12 +26,10 @@ const config = ref({ const API_URI = ref(config.value[env.value].API_URI); const MEET_URI = ref(config.value[env.value].MEET_URI); -const API_GEN_REPORT = ref(config.value[env.value].API_GEN_REPORT); export default { env: env.value, config: config.value, API_URI: API_URI.value, MEET_URI: MEET_URI.value, - API_GEN_REPORT: API_GEN_REPORT.value, }; diff --git a/src/modules/06_evaluate/components/step/step2.vue b/src/modules/06_evaluate/components/step/step2.vue index c46d758..91d7cba 100644 --- a/src/modules/06_evaluate/components/step/step2.vue +++ b/src/modules/06_evaluate/components/step/step2.vue @@ -3,6 +3,7 @@ import { ref, onMounted } from "vue"; import keycloak from "@/plugins/keycloak"; import http from "@/plugins/http"; import config from "@/app.config"; +import genReport from "@/plugins/genreport"; import { useQuasar } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; @@ -47,7 +48,11 @@ function backPage() { } } -async function onClickDowloadFile(tp: string, templateName: string) { +async function onClickDowloadFile( + tp: string, + templateName: string, + fileName: string +) { showLoader(); const data = Object.assign( { fullName: fullName.value }, @@ -61,17 +66,7 @@ async function onClickDowloadFile(tp: string, templateName: string) { data: data, }; console.log(body); - await http - .post(config.API.reportTemplate(), body) - .then((res) => { - console.log(res); - }) - .catch((err) => { - messageError($q,err) - }) - .finally(() => { - hideLoader(); - }); + await genReport(body, fileName); } @@ -94,7 +89,13 @@ async function onClickDowloadFile(tp: string, templateName: string) { icon="download" label="ดาวน์โหลดต้นแบบ" color="primary" - @click="onClickDowloadFile('EV1_005', 'template-1')" + @click=" + onClickDowloadFile( + 'EV1_005', + 'template-1', + 'แบบพิจารณาคุณสมบัติบุคคล' + ) + " > ดาวน์โหลดต้นแบบ @@ -156,7 +157,13 @@ async function onClickDowloadFile(tp: string, templateName: string) { icon="download" label="ดาวน์โหลดต้นแบบ" color="primary" - @click="onClickDowloadFile('EV1_006', 'template-2')" + @click=" + onClickDowloadFile( + 'EV1_006', + 'template-2', + 'แบบแสดงรายละเอียดการเสนอผลงาน' + ) + " > ดาวน์โหลดต้นแบบ @@ -216,7 +223,13 @@ async function onClickDowloadFile(tp: string, templateName: string) { icon="download" label="ดาวน์โหลดต้นแบบ" color="primary" - @click="onClickDowloadFile('EV1_007', 'template-3')" + @click=" + onClickDowloadFile( + 'EV1_007', + 'template-3', + 'แบบตรวจสอบความถูกต้องครบถ้วนของข้อมูลเพื่อประกอบการคัดเลือกบุคคล' + ) + " > ดาวน์โหลดต้นแบบ @@ -276,7 +289,13 @@ async function onClickDowloadFile(tp: string, templateName: string) { icon="download" label="ดาวน์โหลดต้นแบบ" color="primary" - @click="onClickDowloadFile('EV1_008', 'template-4')" + @click=" + onClickDowloadFile( + 'EV1_008', + 'template-4', + 'แบบประเมินคุณลักษณะบุคคล' + ) + " > ดาวน์โหลดต้นแบบ @@ -336,7 +355,13 @@ async function onClickDowloadFile(tp: string, templateName: string) { icon="download" label="ดาวน์โหลดต้นแบบ" color="primary" - @click="onClickDowloadFile('EV1_009', 'template-5')" + @click=" + onClickDowloadFile( + 'EV1_009', + 'template-5', + 'แบบสรุปข้อมูลของผู้ขอรับการคัดเลือก' + ) + " > ดาวน์โหลดต้นแบบ @@ -349,7 +374,6 @@ async function onClickDowloadFile(tp: string, templateName: string) { icon="visibility" label="ดูไฟล์เอกสาร" color="primary" - @click="onClickDowloadFile('EV1_009', 'template-5')" > ดูไฟล์เอกสาร @@ -397,7 +421,13 @@ async function onClickDowloadFile(tp: string, templateName: string) { icon="download" label="ดาวน์โหลดต้นแบบ" color="primary" - @click="onClickDowloadFile('EV1_010', 'template-6')" + @click=" + onClickDowloadFile( + 'EV1_010', + 'template-6', + 'ผลงานที่จะส่งประเมิน' + ) + " > ดาวน์โหลดต้นแบบ diff --git a/src/plugins/genreport.ts b/src/plugins/genreport.ts new file mode 100644 index 0000000..5346948 --- /dev/null +++ b/src/plugins/genreport.ts @@ -0,0 +1,54 @@ +import axios from "axios"; +import { useQuasar } from "quasar"; +import { useCounterMixin } from "@/stores/mixin"; + +const $q = useQuasar(); + +const mixin = useCounterMixin(); +const { showLoader, hideLoader, messageError } = mixin; + +const apiGenReport = + "https://report-server.frappet.synology.me/api/v1/report-template/docx"; + +async function genReport(data: any, fileName: string) { + showLoader(); + await axios + .post(apiGenReport, data, { + headers: { + accept: + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "content-Type": "application/json", + }, + responseType: "arraybuffer", + }) + .then((res) => { + const data = res.data; + if (data) { + // สร้าง Blob จาก array buffer + const blob = new Blob([data], { + type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + }); + + // สร้าง URL สำหรับไฟล์ Blob + const url = URL.createObjectURL(blob); + + // สร้างลิงก์เพื่อดาวน์โหลดไฟล์ + const link = document.createElement("a"); + link.href = url; + link.download = `${fileName}.docx`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด + document.body.appendChild(link); + link.click(); + + // ลบ URL ที่สร้างขึ้นหลังจากใช้งาน + URL.revokeObjectURL(url); + } + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +export default genReport;