|
|
@ -136,7 +136,7 @@ function format(date) { |
|
|
|
} |
|
|
|
/** |
|
|
|
* 身份证加密 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function maskIDCard(idCard) { |
|
|
|
// 判断身份证号是否有效
|
|
|
|
if (idCard.length === 18) { |
|
|
@ -261,29 +261,30 @@ function calculateAge(idCard) { |
|
|
|
if (idCard && idCard.length === 18) { |
|
|
|
// 提取出生日期(前 6 位)
|
|
|
|
let birthDate = idCard.substring(6, 14); |
|
|
|
|
|
|
|
|
|
|
|
// 从出生日期创建 Date 对象,格式为 YYYY-MM-DD
|
|
|
|
let year = birthDate.substring(0, 4); |
|
|
|
let month = birthDate.substring(4, 6) - 1; // 月份从 0 开始
|
|
|
|
let day = birthDate.substring(6, 8); |
|
|
|
|
|
|
|
|
|
|
|
let birth = new Date(year, month, day); |
|
|
|
|
|
|
|
|
|
|
|
// 获取当前日期
|
|
|
|
let now = new Date(); |
|
|
|
|
|
|
|
|
|
|
|
// 计算年龄
|
|
|
|
let age = now.getFullYear() - birth.getFullYear(); |
|
|
|
|
|
|
|
|
|
|
|
// 如果生日还没过,年龄减一
|
|
|
|
if (now.getMonth() < birth.getMonth() || (now.getMonth() === birth.getMonth() && now.getDate() < birth.getDate())) { |
|
|
|
age--; |
|
|
|
if (now.getMonth() < birth.getMonth() || (now.getMonth() === birth.getMonth() && now.getDate() < birth |
|
|
|
.getDate())) { |
|
|
|
age--; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
patientAge = age; |
|
|
|
} |
|
|
|
return patientAge; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
export default { |
|
|
|