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