From 3ae270ee2e6518522dce3153f483b8c5b3d3428d Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期五, 28 十一月 2025 16:42:05 +0800
Subject: [PATCH] fix: bug

---
 src/utils/common/common.ts |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts
index b05dfc3..f338db2 100644
--- a/src/utils/common/common.ts
+++ b/src/utils/common/common.ts
@@ -106,3 +106,32 @@
 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;
+}
+
+export const hiddenIDNumberForEnd4 = (realIDNumber: string) => {
+  if (!realIDNumber) return '';
+  return realIDNumber.replace(/^(\d+)(.{4})$/, '$1****');
+};

--
Gitblit v1.9.1