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
|
|
@ -136,10 +136,6 @@ async function onDownloadFile(id: string, profileId: string) {
|
|||
),
|
||||
)
|
||||
.then(async (res) => {
|
||||
// const data = res.data.downloadUrl;
|
||||
// window.open(data, "_blank");
|
||||
console.log(res.data);
|
||||
|
||||
const downloadUrl = res.data.downloadUrl;
|
||||
const response = await fetch(downloadUrl);
|
||||
const blob = await response.blob();
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ function onSearch() {
|
|||
rows.value = onSearchDataTable(
|
||||
filter.value,
|
||||
rowsData.value,
|
||||
columns.value ? columns.value : []
|
||||
columns.value ? columns.value : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -258,12 +258,23 @@ async function onDownloadFile(id: string, profileId: string) {
|
|||
"เอกสารความสามารถพิเศษ",
|
||||
profileId,
|
||||
id,
|
||||
"เอกสารหลักฐาน"
|
||||
)
|
||||
"เอกสารหลักฐาน",
|
||||
),
|
||||
)
|
||||
.then(async (res) => {
|
||||
const data = res.data;
|
||||
window.open(data.downloadUrl, "_blank");
|
||||
const downloadUrl = res.data.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 = `เอกสารความสามารถพิเศษ_`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
|
|
|
|||
|
|
@ -194,8 +194,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 = `เอกสารวินัย`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
} catch (e) {
|
||||
messageError($q, e);
|
||||
} finally {
|
||||
|
|
@ -208,7 +220,7 @@ function onSearch() {
|
|||
rows.value = onSearchDataTable(
|
||||
filter.value,
|
||||
rowsData.value,
|
||||
columns.value ? columns.value : []
|
||||
columns.value ? columns.value : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -297,8 +297,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 = `เอกสารปฏิบัติราชการพิเศษ`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
} catch (e) {
|
||||
messageError($q, e);
|
||||
} finally {
|
||||
|
|
@ -311,7 +323,7 @@ function onSearch() {
|
|||
rows.value = onSearchDataTable(
|
||||
filter.value,
|
||||
rowsData.value,
|
||||
columns.value ? columns.value : []
|
||||
columns.value ? columns.value : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -302,12 +302,23 @@ async function onDownloadFile(id: string, profileId: string) {
|
|||
"ช่วยราชการ",
|
||||
profileId,
|
||||
id,
|
||||
"เอกสารหลักฐาน"
|
||||
)
|
||||
"เอกสารหลักฐาน",
|
||||
),
|
||||
)
|
||||
.then(async (res) => {
|
||||
const data = res.data;
|
||||
window.open(data.downloadUrl, "_blank");
|
||||
const downloadUrl = res.data.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 = `เอกสารช่วยราชการ`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
|
|
@ -322,7 +333,7 @@ function onSearch() {
|
|||
rows.value = onSearchDataTable(
|
||||
filter.value,
|
||||
rowsData.value,
|
||||
columns.value ? columns.value : []
|
||||
columns.value ? columns.value : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -253,8 +253,8 @@ async function getHistory() {
|
|||
config.API.dataUserCertificateHistoryByType(
|
||||
link.value,
|
||||
"certificate",
|
||||
idByRow.value
|
||||
)
|
||||
idByRow.value,
|
||||
),
|
||||
)
|
||||
.then((res) => {
|
||||
const data = res.data.result;
|
||||
|
|
@ -278,7 +278,19 @@ async function onDownloadFile(id: string, profileId: string) {
|
|||
showLoader();
|
||||
try {
|
||||
const data = await getPathUploadFlie(fileGroup.value, profileId, id);
|
||||
window.open(data.downloadUrl, "_blank");
|
||||
const downloadUrl = data.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 = `เอกสารใบอนุญาตประกอบวิชาชีพ`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
messageError($q, error);
|
||||
} finally {
|
||||
|
|
@ -291,7 +303,7 @@ function onSearch() {
|
|||
rows.value = onSearchDataTable(
|
||||
filter.value,
|
||||
rowsData.value,
|
||||
columns.value ? columns.value : []
|
||||
columns.value ? columns.value : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -469,8 +469,8 @@ async function getHistory() {
|
|||
config.API.dataUserCertificateHistoryByType(
|
||||
link.value,
|
||||
"insignia",
|
||||
idByRow.value
|
||||
)
|
||||
idByRow.value,
|
||||
),
|
||||
)
|
||||
.then((res) => {
|
||||
const data = res.data.result;
|
||||
|
|
@ -494,7 +494,18 @@ async function onDownloadFile(id: string, profileId: string) {
|
|||
showLoader();
|
||||
try {
|
||||
const data = await getPathUploadFlie(fileGroup.value, profileId, id);
|
||||
window.open(data.downloadUrl, "_blank");
|
||||
const response = await fetch(data.downloadUrl);
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = `เอกสารเครื่องราชอิสริยาภรณ์`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
messageError($q, error);
|
||||
} finally {
|
||||
|
|
@ -507,7 +518,7 @@ function onSearch() {
|
|||
rows.value = onSearchDataTable(
|
||||
filter.value,
|
||||
rowsData.value,
|
||||
columns.value ? columns.value : []
|
||||
columns.value ? columns.value : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -647,7 +658,6 @@ onMounted(async () => {
|
|||
dense
|
||||
round
|
||||
size="14px"
|
||||
class="absolute_button"
|
||||
@click="onHistory(props.row.id)"
|
||||
>
|
||||
<q-tooltip>ประวัติแก้ไขเครื่องราชอิสริยาภรณ์</q-tooltip>
|
||||
|
|
|
|||
|
|
@ -278,7 +278,18 @@ async function onDownloadFile(id: string, profileId: string) {
|
|||
showLoader();
|
||||
try {
|
||||
const data = await getPathUploadFlie(fileGroup.value, profileId, id);
|
||||
window.open(data.downloadUrl, "_blank");
|
||||
const response = await fetch(data.downloadUrl);
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = `เอกสารประกาศเกียรติคุณ`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
messageError($q, error);
|
||||
} finally {
|
||||
|
|
@ -291,7 +302,7 @@ function onSearch() {
|
|||
rows.value = onSearchDataTable(
|
||||
filter.value,
|
||||
rowsData.value,
|
||||
columns.value ? columns.value : []
|
||||
columns.value ? columns.value : [],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -429,7 +440,6 @@ onMounted(async () => {
|
|||
dense
|
||||
round
|
||||
size="14px"
|
||||
class="absolute_button"
|
||||
@click="onHistory(props.row.id)"
|
||||
>
|
||||
<q-tooltip>ประวัติแก้ไขประกาศเกียรติคุณ</q-tooltip>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue