fix download file log
This commit is contained in:
parent
1288a7b08f
commit
658fd6705e
3 changed files with 13 additions and 9 deletions
|
|
@ -31,7 +31,7 @@ defineProps<{
|
||||||
<q-separator />
|
<q-separator />
|
||||||
<q-card-actions align="right">
|
<q-card-actions align="right">
|
||||||
<q-btn
|
<q-btn
|
||||||
label="ดาวน์โหลด (.TXT)"
|
label="ดาวน์โหลด (.docx)"
|
||||||
color="blue"
|
color="blue"
|
||||||
type="submit"
|
type="submit"
|
||||||
icon="download"
|
icon="download"
|
||||||
|
|
|
||||||
|
|
@ -462,17 +462,17 @@ function onSendCSV() {
|
||||||
.finally(() => {});
|
.finally(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadTxt() {
|
async function downloadTxt() {
|
||||||
const queryString = {
|
const queryString = {
|
||||||
id: currentlogData.value?.id,
|
id: currentlogData.value?.id,
|
||||||
};
|
};
|
||||||
http
|
await http
|
||||||
.get(`${config.API.log}/report/logsDetail`, {
|
.get(`${config.API.log}/report/logsDetail`, {
|
||||||
params: queryString,
|
params: queryString,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then(async (res) => {
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
generateTxt(data, `LOG_${date2Thai(new Date(startDate.value))}`);
|
await generateTxt(data, `LOG_${date2Thai(new Date(startDate.value))}`);
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
messageError($q, e);
|
messageError($q, e);
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,15 @@ const { showLoader, hideLoader, messageError } = mixin;
|
||||||
async function generateTxt(data: any, fileName: string) {
|
async function generateTxt(data: any, fileName: string) {
|
||||||
showLoader();
|
showLoader();
|
||||||
await axios
|
await axios
|
||||||
.post(`${config.API.reportTemplate}/txt`, data, {
|
.post(`${config.API.reportTemplate}/docx`, data, {
|
||||||
headers: {
|
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) => {
|
.then((res) => {
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
|
|
@ -30,7 +34,7 @@ async function generateTxt(data: any, fileName: string) {
|
||||||
// สร้างลิงก์เพื่อดาวน์โหลดไฟล์
|
// สร้างลิงก์เพื่อดาวน์โหลดไฟล์
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = `${fileName}.txt`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด
|
link.download = `${fileName}.docx`; // กำหนดชื่อไฟล์ที่จะดาวน์โหลด
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue