fix env report

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-11-18 10:22:56 +07:00
parent c9d1d1e4ee
commit 7343405d19
7 changed files with 56 additions and 59 deletions

View file

@ -1,10 +1,12 @@
<script setup lang="ts">
import avatar from "@/assets/avatar_user.jpg";
import { ref, reactive, onMounted } from "vue";
import axios from "axios";
import { useCounterMixin } from "@/stores/mixin";
import { useDataStore } from "@/stores/data";
import { useRegistryInFormationStore } from "@/modules/10_registry/store/registry";
import axios from "axios";
import genReport from "@/plugins/genreport";
//
import InformationPage from "@/modules/10_registry/tabs/01_information.vue";
import GovernmentPage from "@/modules/10_registry/tabs/02_government.vue";
@ -18,8 +20,6 @@ import http from "@/plugins/http";
import config from "@/app.config";
import { useQuasar } from "quasar";
const apiGenReport =
"https://report-server.frappet.synology.me/api/v1/report-template/docx";
const store = useRegistryInFormationStore();
const $q = useQuasar();
const dataStore = useDataStore();
@ -42,14 +42,20 @@ async function onClickDownloadKp7(type: string) {
showLoader();
const url =
type === "FULL"
? config.API.profileReportId(store.profileId, dataStore.officerType == "OFFICER" ? 'profile':'profile-employee')
: config.API.profileKp7ShortId(store.profileId, dataStore.officerType == "OFFICER" ? 'profile':'profile-employee');
? config.API.profileReportId(
store.profileId,
dataStore.officerType == "OFFICER" ? "profile" : "profile-employee"
)
: config.API.profileKp7ShortId(
store.profileId,
dataStore.officerType == "OFFICER" ? "profile" : "profile-employee"
);
const fileName = type === "FULL" ? "ก.พ.7/ก.ก.1" : "ประวัติแบบย่อ";
await http
.get(url)
.then(async (res) => {
const data = await res.data.result;
await genReport(data, fileName);
await genReport(data, fileName, "pdf");
hideLoader();
})
.catch((err) => {
@ -59,46 +65,6 @@ async function onClickDownloadKp7(type: string) {
.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(() => {
hideLoader();
});
}
/**
* งชนกลบหนาหล
*/