feat(registry-edit): previewFile excel Position

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-04-24 14:06:01 +07:00
parent 433a0ce9b8
commit 9132efed11
3 changed files with 512 additions and 34 deletions

View file

@ -21,6 +21,7 @@ import type {
import DialogForm from "@/modules/04_registryPerson/views/edit/components/DialogForm.vue";
import DialogSort from "@/modules/04_registryPerson/views/edit/components/DialogSort.vue";
import DialogExcelPreview from "@/modules/04_registryPerson/views/edit/components/DialogExcelPreview.vue";
import CurruncyInput from "@/components/CurruncyInput.vue";
const $q = useQuasar();
@ -53,6 +54,11 @@ const amountRef = ref<any>(null);
const amountSpecialRef = ref<any>(null);
const currencyPopupRef = ref<any>(null);
// Excel Preview
const excelPreviewModal = ref<boolean>(false);
const selectedExcelFile = ref<File | null>(null);
const isParsingExcel = ref<boolean>(false);
//Table
const isLoad = ref<boolean>(true);
const rowIndex = ref<number>(0);
@ -851,7 +857,7 @@ async function validateAndSave(
/**
* งกนอปโหลดไฟล Excel
* งไฟล Excel ไปย API โดยตรง
* เป preview modal อนอปโหลด
*/
function handUploadFile() {
const input = document.createElement("input");
@ -859,48 +865,73 @@ function handUploadFile() {
input.accept = ".xlsx,.xls";
input.onchange = async (e: Event) => {
try {
const file = (e.target as HTMLInputElement).files?.[0];
if (!file) return;
const file = (e.target as HTMLInputElement).files?.[0];
if (!file) return;
//
const validExtensions = [".xlsx", ".xls"];
const fileExtension = file.name
.substring(file.name.lastIndexOf("."))
.toLowerCase();
//
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",
if (!validExtensions.includes(fileExtension)) {
messageError($q, {
response: {
data: {
title: "กรุณาเลือกไฟล์ Excel เท่านั้น (.xlsx, .xls)",
},
}
);
success($q, "อัปโหลดไฟล์สำเร็จ");
await fetchData();
} catch (error) {
messageError($q, error);
} finally {
hideLoader();
},
});
return;
}
// preview modal
selectedExcelFile.value = file;
excelPreviewModal.value = true;
};
input.click();
}
/**
* งกนยนยนการอปโหลดไฟล
* งไฟลไปย API เม user นยนจาก preview modal
*/
async function onConfirmUpload(file: File) {
try {
isParsingExcel.value = true;
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();
excelPreviewModal.value = false;
} catch (error) {
messageError($q, error);
} finally {
hideLoader();
isParsingExcel.value = false;
}
}
/**
* งกนยกเลกการอปโหลด
* preview modal และลางค
*/
function onCancelUpload() {
selectedExcelFile.value = null;
excelPreviewModal.value = false;
}
onMounted(async () => {
await Promise.all([fetchData(), fetchType()]);
});
@ -1794,6 +1825,13 @@ onMounted(async () => {
:fetch-data="fetchData"
:columns="columns"
/>
<DialogExcelPreview
v-model:modal="excelPreviewModal"
:file="selectedExcelFile"
@confirm="onConfirmUpload"
@cancel="onCancelUpload"
/>
</template>
<style scoped></style>