feat(registry-edit): uploadFile profileSalaryTemp
This commit is contained in:
parent
1de3d35752
commit
cf053cb306
2 changed files with 66 additions and 1 deletions
|
|
@ -847,6 +847,58 @@ async function validateAndSave(
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันอัปโหลดไฟล์ Excel
|
||||
* ส่งไฟล์ Excel ไปยัง API โดยตรง
|
||||
*/
|
||||
function handUploadFile() {
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".xlsx,.xls";
|
||||
|
||||
input.onchange = async (e: Event) => {
|
||||
try {
|
||||
const file = (e.target as HTMLInputElement).files?.[0];
|
||||
if (!file) return;
|
||||
|
||||
// ตรวจสอบชนิดไฟล์โดยตรวจสอบนามสกุล
|
||||
const validExtensions = [".xlsx", ".xls"];
|
||||
const fileExtension = file.name
|
||||
.substring(file.name.lastIndexOf("."))
|
||||
.toLowerCase();
|
||||
|
||||
if (!validExtensions.includes(fileExtension)) {
|
||||
messageError("กรุณาเลือกไฟล์ Excel เท่านั้น (.xlsx, .xls)");
|
||||
return;
|
||||
}
|
||||
|
||||
showLoader();
|
||||
const type = empType.value === "officer" ? "office" : "employee";
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
|
||||
await http.post(
|
||||
config.API.uploadProfile(type, profileId.value),
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
success($q, "อัปโหลดไฟล์สำเร็จ");
|
||||
await fetchData();
|
||||
} catch (error) {
|
||||
messageError($q, error);
|
||||
} finally {
|
||||
hideLoader();
|
||||
}
|
||||
};
|
||||
|
||||
input.click();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([fetchData(), fetchType()]);
|
||||
});
|
||||
|
|
@ -886,6 +938,15 @@ onMounted(async () => {
|
|||
>
|
||||
<q-space />
|
||||
<div>
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
color="blue"
|
||||
icon="upload"
|
||||
@click="handUploadFile()"
|
||||
>
|
||||
<q-tooltip>อัปโหลดไฟล์แก้ไข</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
|
|
@ -893,7 +954,9 @@ onMounted(async () => {
|
|||
icon="download"
|
||||
:disable="rows.length == 0"
|
||||
@click="exportToExcel()"
|
||||
/>
|
||||
>
|
||||
<q-tooltip>ดาวน์โหลดไฟล์</q-tooltip>
|
||||
</q-btn>
|
||||
</div>
|
||||
|
||||
<q-input
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue