From c014962eed4f34337a6c29d03acf2f0cf33d0e05 Mon Sep 17 00:00:00 2001 From: "STW_TTTY\\stwtt" Date: Thu, 22 Aug 2024 12:05:41 +0700 Subject: [PATCH] =?UTF-8?q?download=20file=20=E0=B8=97=E0=B8=94=E0=B8=A5?= =?UTF-8?q?=E0=B8=AD=E0=B8=87=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/reports/api.report.ts | 2 +- .../components/probation/FormAssign.vue | 24 +++++---- .../probation/FormEvaluation/FormEvaluate.vue | 3 +- .../FormEvaluation/FormEvaluateScore.vue | 3 +- .../probation/FormEvaluation/FormReport.vue | 27 ++++++---- .../probation/FormEvaluation/Template1.vue | 50 ++++++++----------- .../FormEvaluation/Template1Commader.vue | 33 ++++++------ .../probation/FormEvaluation/Template2.vue | 20 +++++--- 8 files changed, 85 insertions(+), 77 deletions(-) diff --git a/src/api/reports/api.report.ts b/src/api/reports/api.report.ts index 5508f22b4..8570cb24a 100644 --- a/src/api/reports/api.report.ts +++ b/src/api/reports/api.report.ts @@ -36,7 +36,7 @@ export default { reportEvaluateChairman: (type: string, id: string) => `${reportProbation}/17/${type}/${id}`, reportEvaluateResult: (type: string, id: string) => - `${reportProbation}/19/${type}/${id}`, + `${reportProbation}/18/${type}/${id}`, // reportSurvey:(type:string, id:string) => `${reportProbation}/19/${type}/${id}`, //filetransfer diff --git a/src/modules/05_placement/components/probation/FormAssign.vue b/src/modules/05_placement/components/probation/FormAssign.vue index abb908835..f3565d906 100644 --- a/src/modules/05_placement/components/probation/FormAssign.vue +++ b/src/modules/05_placement/components/probation/FormAssign.vue @@ -6,6 +6,8 @@ import { useQuasar } from "quasar"; import http from "@/plugins/http"; import config from "@/app.config"; +import genReport from "@/plugins/genreport"; + const $q = useQuasar(); const isEdit = ref(true); const router = useRouter(); @@ -917,21 +919,21 @@ function downloadFile(response: any, filename: string) { async function clickdownloadFile(type: string) { showLoader(); await http - .get(config.API.reportAssign(type, assignId.value), { - responseType: "blob", - }) - .then((res) => { - downloadFile( - res, - `แบบมอบหมายงานการทดลองปฏิบัติหน้าที่ราชการ-${fullname.value}.${type}` + .get(config.API.reportAssign(type, assignId.value)) + .then(async (res) => { + const data = res.data.result; + await genReport( + data, + `แบบมอบหมายงานการทดลองปฏิบัติหน้าที่ราชการ-${fullname.value}`, + type ); + hideLoader(); }) .catch(async (e) => { messageError($q, JSON.parse(await e.response.data.text())); - }) - .finally(() => { hideLoader(); - }); + }) + .finally(() => {}); } /** เช็ค จำนวนเดือน เเละ วันที่เริ่ม ไม่เท่ากับ undefined*/ @@ -1088,7 +1090,7 @@ onMounted(async () => {
แบบมอบหมายงานการทดลองปฏิบัติหน้าที่ราชการ
(route.name == "probationFormDetail"); const assignId = ref(route.params.form.toString()); -const { assign } = probationStore; +const { fecthAssignoutput,assign } = probationStore; const Autherise = ref(null); const dateAutherise = ref(new Date()); const option = ref([]); @@ -106,6 +106,7 @@ async function fecthAssign() { await http .get(config.API.evaluateCreate(assignId.value)) .then(async (res) => { + await fecthAssignoutput(res.data.data); // if (props.action == "add") { person.value = res.data.data.person; // option.value.push(res.data.data.commander); diff --git a/src/modules/05_placement/components/probation/FormEvaluation/FormEvaluateScore.vue b/src/modules/05_placement/components/probation/FormEvaluation/FormEvaluateScore.vue index 17ee2c6ec..8ca314f02 100644 --- a/src/modules/05_placement/components/probation/FormEvaluation/FormEvaluateScore.vue +++ b/src/modules/05_placement/components/probation/FormEvaluation/FormEvaluateScore.vue @@ -21,7 +21,7 @@ const router = useRouter(); const routeName = router.currentRoute.value.name; const $q = useQuasar(); const probationStore = useProbationDataStore(); -const { assign } = probationStore; +const { fecthAssignoutput, assign } = probationStore; const mixin = useCounterMixin(); const { date2Thai, @@ -218,6 +218,7 @@ async function fecthAssign() { await http .get(config.API.evaluateChairman(assignId.value)) .then(async (res: any) => { + await fecthAssignoutput(res.data.data); assign.value = res.data.data.assign; evaluate_no.value = res.data.data.evaluate_no; start_date.value = res.data.data.start_date; diff --git a/src/modules/05_placement/components/probation/FormEvaluation/FormReport.vue b/src/modules/05_placement/components/probation/FormEvaluation/FormReport.vue index a6fddcc9f..eedf3eac3 100644 --- a/src/modules/05_placement/components/probation/FormEvaluation/FormReport.vue +++ b/src/modules/05_placement/components/probation/FormEvaluation/FormReport.vue @@ -6,6 +6,8 @@ import { useRoute, useRouter } from "vue-router"; import http from "@/plugins/http"; import config from "@/app.config"; import { useProbationDataStore } from "@/modules/05_placement/storeProbation"; +import genReport from "@/plugins/genreport"; + const probationStore = useProbationDataStore(); const $q = useQuasar(); @@ -156,21 +158,21 @@ function downloadFile(response: any, filename: string) { async function clickdownloadFile(type: string) { showLoader(); await http - .get(config.API.reportEvaluateResult(type, assignId.value), { - responseType: "blob", - }) - .then((res) => { - downloadFile( - res, - `แบบรายงานการประเมินฯ_${probationStore.person.name}.${type}` + .get(config.API.reportEvaluateResult(type, assignId.value)) + .then(async (res) => { + const data = res.data.result; + await genReport( + data, + `แบบรายงานการประเมินฯ_${person.value.name}.${type}`, + type ); + hideLoader(); }) .catch(async (e) => { messageError($q, JSON.parse(await e.response.data.text())); - }) - .finally(() => { hideLoader(); - }); + }) + .finally(() => {}); } /** post/put data @@ -717,7 +719,10 @@ onMounted(() => {
- + diff --git a/src/modules/05_placement/components/probation/FormEvaluation/Template1.vue b/src/modules/05_placement/components/probation/FormEvaluation/Template1.vue index 5d0b6665e..cd889be25 100644 --- a/src/modules/05_placement/components/probation/FormEvaluation/Template1.vue +++ b/src/modules/05_placement/components/probation/FormEvaluation/Template1.vue @@ -6,6 +6,7 @@ import { useRoute, useRouter } from "vue-router"; import { useProbationDataStore } from "@/modules/05_placement/storeProbation"; import http from "@/plugins/http"; import config from "@/app.config"; +import genReport from "@/plugins/genreport"; const Header = defineAsyncComponent( () => @@ -63,17 +64,6 @@ function changeTab(tabVal: string) { dataArrayNumber.value = Number(tabVal.charAt(4)); } -/** convert file */ -function downloadFile(response: any, filename: string) { - const link = document.createElement("a"); - var fileName = filename; - link.href = window.URL.createObjectURL(new Blob([response.data])); - link.setAttribute("download", fileName); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); -} - /** download file */ async function FileDownload(type: string) { let numTab = probationStore.evaluate.find( @@ -83,40 +73,40 @@ async function FileDownload(type: string) { if (dataRole.value == "mentor") { showLoader(); await http - .get(config.API.reportEvaluateRecord1(type, numTab.id), { - responseType: "blob", - }) + .get(config.API.reportEvaluateRecord1(type, numTab.id)) .then(async (res) => { - downloadFile( - res, - `แบบบันทึกผล(ผู้ดูเเล)_${probationStore.person.name}_ครั้งที่${numTab.no}.${type}` + const data = res.data.result; + await genReport( + data, + `แบบบันทึกผล(ผู้ดูเเล)_${probationStore.person.name}_ครั้งที่${numTab.no}`, + type ); + hideLoader(); }) .catch(async (e) => { messageError($q, JSON.parse(await e.response.data.text())); - }) - .finally(() => { hideLoader(); - }); + }) + .finally(() => {}); } else { //ผุ้บังคับ showLoader(); await http - .get(config.API.reportEvaluateRecord1(type, numTab.id), { - responseType: "blob", - }) + .get(config.API.reportEvaluateRecord1(type, numTab.id)) .then(async (res) => { - downloadFile( - res, - `แบบบันทึกผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}.${type}` + const data = res.data.result; + await genReport( + data, + `แบบบันทึกผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}`, + type ); + hideLoader(); }) .catch(async (e) => { messageError($q, JSON.parse(await e.response.data.text())); - }) - .finally(() => { hideLoader(); - }); + }) + .finally(() => {}); } } @@ -167,7 +157,7 @@ onMounted(async () => {
import( @@ -87,39 +89,42 @@ async function FileDownload(type: string) { if (dataRole.value == "mentor") { showLoader(); await http - .get(config.API.reportEvaluateRecord1(type, numTab.id), { - responseType: "blob", - }) + .get(config.API.reportEvaluateRecord1(type, numTab.id)) .then(async (res) => { - downloadFile( - res, - `แบบบันทึกผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}.${type}` + const data = res.data.result; + await genReport( + data, + `แบบบันทึกผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}`, + type ); + hideLoader(); }) .catch(async (e) => { messageError($q, JSON.parse(await e.response.data.text())); + hideLoader(); }) .finally(() => { - hideLoader(); + }); } else { //ผุ้บังคับ showLoader(); await http - .get(config.API.reportEvaluateRecord1(type, numTab.id), { - responseType: "blob", - }) + .get(config.API.reportEvaluateRecord1(type, numTab.id)) .then(async (res) => { - downloadFile( - res, - `แบบบันทึกผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}.${type}` + const data = res.data.result; + await genReport( + data, + `แบบบันทึกผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}`, + type ); + hideLoader(); }) .catch(async (e) => { messageError($q, JSON.parse(await e.response.data.text())); + hideLoader(); }) .finally(() => { - hideLoader(); }); } } diff --git a/src/modules/05_placement/components/probation/FormEvaluation/Template2.vue b/src/modules/05_placement/components/probation/FormEvaluation/Template2.vue index 1b5a9b50d..3cb509a87 100644 --- a/src/modules/05_placement/components/probation/FormEvaluation/Template2.vue +++ b/src/modules/05_placement/components/probation/FormEvaluation/Template2.vue @@ -7,6 +7,8 @@ import { useRoute, useRouter } from "vue-router"; import { useCounterMixin } from "@/stores/mixin"; import { useProbationDataStore } from "@/modules/05_placement/storeProbation"; +import genReport from "@/plugins/genreport"; + const Header = defineAsyncComponent( () => import( @@ -86,20 +88,22 @@ async function FileDownload(type: string) { let numTab = evaluate.value.find((e: any) => e.no === dataArrayNumber.value); showLoader(); await http - .get(config.API.reportEvaluate(type, numTab.id), { - responseType: "blob", - }) + .get(config.API.reportEvaluate(type, numTab.id)) .then(async (res) => { - downloadFile( - res, - `แบบประเมินผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}.${type}` + const data = res.data.result; + await genReport( + data, + `แบบประเมินผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}`, + type ); + hideLoader(); }) .catch(async (e) => { messageError($q, JSON.parse(await e.response.data.text())); + hideLoader(); }) .finally(() => { - hideLoader(); + }); } @@ -146,7 +150,7 @@ onMounted(() => { /> - +