fix download file log

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-11-19 09:32:32 +07:00
parent 1288a7b08f
commit 658fd6705e
3 changed files with 13 additions and 9 deletions

View file

@ -31,7 +31,7 @@ defineProps<{
<q-separator />
<q-card-actions align="right">
<q-btn
label="ดาวน์โหลด (.TXT)"
label="ดาวน์โหลด (.docx)"
color="blue"
type="submit"
icon="download"

View file

@ -462,17 +462,17 @@ function onSendCSV() {
.finally(() => {});
}
function downloadTxt() {
async function downloadTxt() {
const queryString = {
id: currentlogData.value?.id,
};
http
await http
.get(`${config.API.log}/report/logsDetail`, {
params: queryString,
})
.then((res) => {
.then(async (res) => {
const data = res.data;
generateTxt(data, `LOG_${date2Thai(new Date(startDate.value))}`);
await generateTxt(data, `LOG_${date2Thai(new Date(startDate.value))}`);
})
.catch((e) => {
messageError($q, e);

View file

@ -12,11 +12,15 @@ const { showLoader, hideLoader, messageError } = mixin;
async function generateTxt(data: any, fileName: string) {
showLoader();
await axios
.post(`${config.API.reportTemplate}/txt`, data, {
.post(`${config.API.reportTemplate}/docx`, data, {
headers: {
"Content-Type": "text/plain;charset=utf-8",
accept:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"content-Type": "application/json",
// "Content-Type": "text/plain;charset=utf-8",
},
responseType: "blob",
// responseType: "blob",
responseType: "arraybuffer",
})
.then((res) => {
const data = res.data;
@ -30,7 +34,7 @@ async function generateTxt(data: any, fileName: string) {
// สร้างลิงก์เพื่อดาวน์โหลดไฟล์
const link = document.createElement("a");
link.href = url;
link.download = `${fileName}.txt`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด
link.download = `${fileName}.docx`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด
document.body.appendChild(link);
link.click();