fix โหลดไฟล์ รายละเอียดคำร้องขอแก้ไขทะเบียนประวัติ
This commit is contained in:
parent
8e982af4bc
commit
8df59017db
1 changed files with 39 additions and 4 deletions
|
|
@ -156,6 +156,7 @@ function classInput(val: boolean) {
|
|||
|
||||
const checkFile = ref<null | false | "img" | "doc">(null); // เช็คไฟล์อัปโหลด null ค่าเริ่มต้น, false ไม่มีไฟล์, "img" รูปภาพ, "doc" เอกสาร
|
||||
const urlDownload = ref<string>(""); // url ไฟล์อัปโหลด
|
||||
const fileDownloadName = ref<string>("");
|
||||
/**
|
||||
* function หาชื่อไฟล์
|
||||
* @param id รายการยื่นคำร้องขอแก้ไขข้อมูล
|
||||
|
|
@ -196,8 +197,9 @@ async function downloadUrl(id: string, fileName: string) {
|
|||
fileName
|
||||
)
|
||||
)
|
||||
.then((res) => {
|
||||
.then(async (res) => {
|
||||
urlDownload.value = res.data.downloadUrl;
|
||||
fileDownloadName.value = res.data.fileName;
|
||||
if (dataRequest.value.topic == "ขอแก้ไขรูปภาพประจำตัว") {
|
||||
checkFile.value = "img";
|
||||
} else {
|
||||
|
|
@ -254,6 +256,34 @@ function fetchCheckIsofficer() {
|
|||
}
|
||||
}
|
||||
|
||||
async function onDownloadFil() {
|
||||
try {
|
||||
// ดึงข้อมูลไฟล์จาก URL
|
||||
const response = await fetch(urlDownload.value);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("ไม่สามารถดาวน์โหลดไฟล์ได้");
|
||||
}
|
||||
|
||||
// แปลงไฟล์เป็น Blob
|
||||
const blob = await response.blob();
|
||||
|
||||
// สร้าง URL ชั่วคราว
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
// สร้าง <a> เพื่อบังคับดาวน์โหลด
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = fileDownloadName.value;
|
||||
link.click();
|
||||
|
||||
// ลบ URL ชั่วคราวเพื่อประหยัดหน่วยความจำ
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (error) {
|
||||
console.error("เกิดข้อผิดพลาด:", error);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([fetchDataRequest(), fetchCheckIsofficer()]);
|
||||
});
|
||||
|
|
@ -402,11 +432,16 @@ onMounted(async () => {
|
|||
icon="mdi-download"
|
||||
dense
|
||||
flat
|
||||
:label="checkFile == 'img' ? 'ดาวน์โหลดรูปภาพประจำตัว':'ดาวน์โหลดเอกสารหลักฐาน'"
|
||||
:label="
|
||||
checkFile == 'img'
|
||||
? 'ดาวน์โหลดรูปภาพประจำตัว'
|
||||
: 'ดาวน์โหลดเอกสารหลักฐาน'
|
||||
"
|
||||
color="blue"
|
||||
:href="urlDownload"
|
||||
target="_blank"
|
||||
@click="onDownloadFil"
|
||||
/>
|
||||
<!-- target="_blank" -->
|
||||
<!-- :href="urlDownload" -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue