feat(registry-edit): uploadFile profileSalaryTemp

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-04-23 16:42:31 +07:00
parent 1de3d35752
commit cf053cb306
2 changed files with 66 additions and 1 deletions

View file

@ -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