From 16593e60e5fc2dedddf838536046e7a6946a2b8c Mon Sep 17 00:00:00 2001 From: wupengfei <834520024@qq.com> Date: 星期一, 18 八月 2025 16:50:16 +0800 Subject: [PATCH] fix: bug --- src/views/FlexJobManage/components/StaffInfoDialog.vue | 13 +++++++++++-- src/utils/common/common.ts | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts index b05dfc3..9965df0 100644 --- a/src/utils/common/common.ts +++ b/src/utils/common/common.ts @@ -106,3 +106,27 @@ export function filterNumbersFromString(str: string) { return str.replace(/\D/g, ''); } + +export function calculateAge(idCardNumber) { + if (BoleRegExp.RegIDCard.test(idCardNumber)) { + const birthDateStr = idCardNumber.match(/(\d{6})(\d{8})/)[2]; + const birthDate = new Date( + birthDateStr.substring(0, 4), + birthDateStr.substring(4, 6) - 1, + birthDateStr.substring(6, 8) + ); + + // Calculate age + const today = new Date(); + const age = + today.getFullYear() - + birthDate.getFullYear() - + (today.getMonth() < birthDate.getMonth() || + (today.getMonth() === birthDate.getMonth() && today.getDate() < birthDate.getDate()) + ? 1 + : 0); + + return age; + } + return null; +} diff --git a/src/views/FlexJobManage/components/StaffInfoDialog.vue b/src/views/FlexJobManage/components/StaffInfoDialog.vue index f7367a0..0dd52d5 100644 --- a/src/views/FlexJobManage/components/StaffInfoDialog.vue +++ b/src/views/FlexJobManage/components/StaffInfoDialog.vue @@ -25,7 +25,11 @@ prop="identity" :check-rules="[{ message: '璇疯緭鍏ヨ韩浠借瘉鍙�', type: 'idCard' }]" > - <ProFormText placeholder="璇疯緭鍏ヨ韩浠借瘉鍙�" v-model.trim="form.identity"></ProFormText> + <ProFormText + placeholder="璇疯緭鍏ヨ韩浠借瘉鍙�" + v-model.trim="form.identity" + @blur="handleCalculateAge" + ></ProFormText> </ProFormItemV2> </ProFormColItem> <ProFormColItem :span="12"> @@ -148,8 +152,9 @@ ProFormUpload, ProFormInputNumber, } from '@bole-core/components'; -import { deepClone, format } from '@/utils'; +import { calculateAge, deepClone, format } from '@/utils'; import { EnumUserGender, EnumUserGenderTextForPerson } from '@/constants'; +import { BoleRegExp } from '@bole-core/core'; defineOptions({ name: 'StaffInfoDialog', @@ -215,4 +220,8 @@ function handleReset() { form.value = { ...defaultForm }; } + +function handleCalculateAge() { + form.value.age = calculateAge(form.value.identity); +} </script> -- Gitblit v1.9.1