From cf053cb306dded6c957e5ccd6a96eaf781b58f95 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Thu, 23 Apr 2026 16:42:31 +0700 Subject: [PATCH] feat(registry-edit): uploadFile profileSalaryTemp --- src/api/02_organizational/api.organization.ts | 2 + .../views/edit/components/Table.vue | 65 ++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index bcb7e54d9..b30ec3ec1 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -192,6 +192,8 @@ export default { `${orgProfile}/keycloak/permissionProfile/${rootId}`, profileidPosition: (type: string) => `${orgProfile}${type}/profileid/position`, + uploadProfile: (type: string, id: string) => + `${organization}/upload/${type}-profileSalaryTemp/${id}`, workflowCommanderOperate: `${workflow}/commander/operate`, workflowCommanderSign: `${workflow}/commander/sign`, diff --git a/src/modules/04_registryPerson/views/edit/components/Table.vue b/src/modules/04_registryPerson/views/edit/components/Table.vue index 7d99fd725..74849426c 100644 --- a/src/modules/04_registryPerson/views/edit/components/Table.vue +++ b/src/modules/04_registryPerson/views/edit/components/Table.vue @@ -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 () => { >
+ + อัปโหลดไฟล์แก้ไข + { icon="download" :disable="rows.length == 0" @click="exportToExcel()" - /> + > + ดาวน์โหลดไฟล์ +