refactor(file): replace window.open with blob download pattern in registry

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-05-01 09:43:00 +07:00
parent 14195e972f
commit e5d9800294
9 changed files with 122 additions and 36 deletions

View file

@ -255,7 +255,7 @@ async function getHistory() {
rowsHistoryData.value = [];
await http
.get(
config.API.dataUserSalaryNopaidHistoryByType(link.value, idByRow.value)
config.API.dataUserSalaryNopaidHistoryByType(link.value, idByRow.value),
)
.then((res) => {
const data = res.data.result;
@ -278,8 +278,20 @@ async function getHistory() {
async function onDownloadFile(id: string, profileId: string) {
showLoader();
try {
const data = await getPathUploadFlie(fileGroup.value, profileId, id);
window.open(data.downloadUrl, "_blank");
const res = await getPathUploadFlie(fileGroup.value, profileId, id);
const downloadUrl = res.downloadUrl;
const response = await fetch(downloadUrl);
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `บันทึกวันที่ไม่ได้รับ${salaryText.value}`;
document.body.appendChild(link);
link.click();
setTimeout(() => {
document.body.removeChild(link);
URL.revokeObjectURL(url);
}, 100);
} catch (e) {
messageError($q, e);
} finally {
@ -292,7 +304,7 @@ function onSearch() {
rows.value = onSearchDataTable(
filter.value,
rowsData.value,
columns.value ? columns.value : []
columns.value ? columns.value : [],
);
}