แก้โหลดไฟล์ เป็น id

This commit is contained in:
STW_TTTY\stwtt 2024-08-13 10:25:45 +07:00
parent dd5c3a42f6
commit 232b5cf60d
5 changed files with 58 additions and 28 deletions

View file

@ -1058,6 +1058,22 @@ export const useCounterMixin = defineStore("mixin", () => {
}
}
function downloadRenameFileByLink(link: string, fileName: string) {
fetch(link)
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = fileName; // ชื่อไฟล์
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
})
.catch(error => console.error('ดาวน์โหลดไฟล์ไม่สำเร็จ:', error));
}
return {
calAge,
date2Thai,
@ -1099,5 +1115,6 @@ export const useCounterMixin = defineStore("mixin", () => {
findOrgNameOld,
findPosMasterNo,
findPosMasterNoOld,
downloadRenameFileByLink
};
});