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,4 +1,6 @@
import axios from "axios";
import config from "@/app.config";
import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
@ -7,18 +9,21 @@ 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) {
async function genReport(data: any, fileName: string, type: string = "docx") {
showLoader();
await axios
.post(apiGenReport, data, {
headers: {
accept:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"content-Type": "application/json",
},
.post(config.API.reportTemplate + `/docx`, data, {
headers:
type == "docx"
? {
accept:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"content-Type": "application/json",
}
: {
accept: "application/pdf",
"content-Type": "application/json",
},
responseType: "arraybuffer",
})
.then((res) => {
@ -35,7 +40,7 @@ async function genReport(data: any, fileName: string) {
// สร้างลิงก์เพื่อดาวน์โหลดไฟล์
const link = document.createElement("a");
link.href = url;
link.download = `${fileName}.docx`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด
link.download = `${fileName}.${type === "docx" ? "docx" : "pdf"}`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด
document.body.appendChild(link);
link.click();