From 03adabeabd4125530cefe4f9625c857dcb23aa6e Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Fri, 4 Jul 2025 16:24:55 +0700 Subject: [PATCH] refactor: add btn uploand file passport --- .../FormEmployeePassport.vue | 50 +++++++++++++------ src/pages/03_customer-management/MainPage.vue | 2 + src/pages/03_customer-management/form.ts | 13 +++-- src/stores/employee/types.ts | 2 +- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/components/03_customer-management/FormEmployeePassport.vue b/src/components/03_customer-management/FormEmployeePassport.vue index c87f13dd..040c9676 100644 --- a/src/components/03_customer-management/FormEmployeePassport.vue +++ b/src/components/03_customer-management/FormEmployeePassport.vue @@ -9,6 +9,8 @@ import useOptionStore from 'stores/options'; import DatePicker from '../shared/DatePicker.vue'; +import { dateFormat } from 'src/utils/datetime'; + const optionStore = useOptionStore(); const { locale } = useI18n(); @@ -32,6 +34,8 @@ const firstName = defineModel('firstName'); const namePrefix = defineModel('namePrefix'); const passportNumber = defineModel('passportNumber'); +const file = defineModel('file'); + const passportValidator = /[a-zA-Z]{1}[a-zA-Z0-9]{1}[0-9]{5,7}$/; const genderOptions = ref[]>([]); @@ -177,6 +181,30 @@ watch( }, ); +function browse() { + inputFile?.click(); +} + +const inputFile = (() => { + const _element = document.createElement('input'); + _element.type = 'file'; + _element.accept = 'image/jpeg,image/png'; + _element.addEventListener('change', change); + return _element; +})(); + +async function change(e: Event) { + const _element = e.target as HTMLInputElement | null; + const _file = _element?.files?.[0]; + + if (_file) { + const newFileName = `passport-${dateFormat(new Date().toISOString())}-${_file.name}`; + const renamedFile = new File([_file], newFileName, { type: _file.type }); + + file.value = renamedFile; + } +} + watch( () => namePrefix.value, (v) => { @@ -221,20 +249,14 @@ watch(
-
- +
+