refactor(file): replace window.open with blob download pattern in registry
This commit is contained in:
parent
14195e972f
commit
e5d9800294
9 changed files with 122 additions and 36 deletions
|
|
@ -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 : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue