แก้ ดาวโหลด

This commit is contained in:
STW_TTTY\stwtt 2024-09-20 16:29:04 +07:00
parent 92c3d9bf78
commit 72d597b465

View file

@ -3,7 +3,7 @@ import avatar from "@/assets/avatar_user.jpg";
import { ref, reactive, onMounted } from "vue"; import { ref, reactive, onMounted } from "vue";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useRegistryInFormationStore } from "@/modules/10_registry/store/registry"; import { useRegistryInFormationStore } from "@/modules/10_registry/store/registry";
import axios from "axios";
// //
import InformationPage from "@/modules/10_registry/tabs/01_information.vue"; import InformationPage from "@/modules/10_registry/tabs/01_information.vue";
import GovernmentPage from "@/modules/10_registry/tabs/02_government.vue"; import GovernmentPage from "@/modules/10_registry/tabs/02_government.vue";
@ -17,6 +17,8 @@ import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
const apiGenReport =
"https://report-server.frappet.synology.me/api/v1/report-template/docx";
const store = useRegistryInFormationStore(); const store = useRegistryInFormationStore();
const $q = useQuasar(); const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
@ -98,29 +100,61 @@ function getType() {
}); });
} }
function onClickDownloadKp7(type: string) { async function onClickDownloadKp7(type: string) {
showLoader(); showLoader();
const url = const url =
type === "FULL" type === "FULL"
? config.API.profileReportId(store.profileId) ? config.API.profileReportId(store.profileId)
: config.API.profileKp7ShortId(store.profileId); : config.API.profileKp7ShortId(store.profileId);
const fileName = type === "FULL" ? "ก.พ.7/ก.ก.1" : "ประวัติแบบย่อ"; const fileName = type === "FULL" ? "ก.พ.7/ก.ก.1" : "ประวัติแบบย่อ";
http await http
.get(url, { .get(url)
responseType: "arraybuffer", // .then(async (res) => {
}) const data = await res.data.result;
.then((res) => { await genReport(data, fileName);
const data = res.data; hideLoader();
const blob = new Blob([data], { type: "application/pdf" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `${fileName}.pdf`;
document.body.appendChild(link);
link.click();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
hideLoader();
})
.finally(() => {});
}
async function genReport(data: any, fileName: string) {
showLoader();
await axios
.post(apiGenReport, data, {
headers: {
accept: "application/pdf",
"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}.pdf`; //
document.body.appendChild(link);
link.click();
// URL
URL.revokeObjectURL(url);
}
})
.catch((e) => {
messageError($q, e);
}) })
.finally(() => { .finally(() => {
hideLoader(); hideLoader();