From d98cea8760770a5b305708f20f481d2a6657ae9e Mon Sep 17 00:00:00 2001 From: pengjun <158915633@qq.com> Date: Tue, 30 Dec 2025 16:47:45 +0800 Subject: [PATCH] seo --- .../patientRegister/PatientRegisterEdit.vue | 3 +- src/utlis/proFunc.js | 78 ++++++++++++++----- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/components/patientRegister/PatientRegisterEdit.vue b/src/components/patientRegister/PatientRegisterEdit.vue index fe8742d..15bf157 100644 --- a/src/components/patientRegister/PatientRegisterEdit.vue +++ b/src/components/patientRegister/PatientRegisterEdit.vue @@ -2059,6 +2059,7 @@ export default { this.$message.warning({ showClose: true, message: fields[Object.keys(fields)[0]][0].message }); return false } + // 手机号非必填时,如有填手机号,也要再验证手机号是否合法 if (this.form['mobileTelephone']) { if (!isValidMobileNumber(this.form['mobileTelephone'])) { @@ -2067,7 +2068,6 @@ export default { } } - //console.log('btnSubmit1', formName) if (this.form.customerOrgId != this.dict.personOrgId) { if (!this.form.customerOrgRegisterId) { @@ -2076,6 +2076,7 @@ export default { } } + // 如果有填身份证号,则验证合法性 if (this.form.idNo && checkIDCode(this.form.idNo) == false) { this.$message.warning({ showClose: true, message: "身份证号填写不合法!" }); return false diff --git a/src/utlis/proFunc.js b/src/utlis/proFunc.js index 4ee997d..f9c56d4 100644 --- a/src/utlis/proFunc.js +++ b/src/utlis/proFunc.js @@ -206,26 +206,6 @@ function arrayExistObjByKeys(arr, keys, values) { }; exports.arrayExistObjByKeys = arrayExistObjByKeys; -//判断身份证是否合法 -function checkIDCode(IDCode) { - // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X - let ret = false; - let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; - if (reg.test(IDCode)) { - ret = true; - } - if (!ret) return ret - if (IDCode.length == 15) { - if (IDCode.substring(8, 10).parseInt > 12 || IDCode.substring(8, 10).parseInt == 0) return false - if (IDCode.substring(10, 12).parseInt > 31 || IDCode.substring(10, 12).parseInt == 0) return false - } else { - if (IDCode.substring(10, 12).parseInt > 12 || IDCode.substring(10, 12).parseInt == 0) return false - if (IDCode.substring(12, 14).parseInt > 31 || IDCode.substring(12, 14).parseInt == 0) return false - } - return ret -}; -exports.checkIDCode = checkIDCode; - //根据身份证号判断出生日期(yyyy-MM-DD),当前年龄与性别 粗犷式,不精确判断闰年平年 function parseID(id) { let ret = { @@ -483,6 +463,64 @@ function isValidMobileNumber(tel) { exports.isValidMobileNumber = isValidMobileNumber; +/** + * 简化的身份证验证(仅验证格式和校验码) + */ +function checkIDCode(idCard) { + idCard = (idCard || '').trim().toUpperCase(); + + if (!idCard) return false; + + // 格式验证 + if (!/^\d{17}[\dX]$/.test(idCard) && !/^\d{15}$/.test(idCard)) { + return false; + } + + // 15位身份证验证出生日期 + if (idCard.length === 15) { + const birthDate = '19' + idCard.substring(6, 12); + const year = birthDate.substring(0, 4); + const month = birthDate.substring(4, 6); + const day = birthDate.substring(6, 8); + + const date = new Date(year, month - 1, day); + return date.getFullYear() === parseInt(year) && + date.getMonth() === month - 1 && + date.getDate() === parseInt(day); + } + + // 18位身份证验证校验码 + if (idCard.length === 18) { + // 验证出生日期 + const birthDate = idCard.substring(6, 14); + const year = birthDate.substring(0, 4); + const month = birthDate.substring(4, 6); + const day = birthDate.substring(6, 8); + + const date = new Date(year, month - 1, day); + if (date.getFullYear() !== parseInt(year) || + date.getMonth() !== month - 1 || + date.getDate() !== parseInt(day)) { + return false; + } + + // 计算校验码 + const weightingFactors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; + const checkCodes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; + + let sum = 0; + for (let i = 0; i < 17; i++) { + sum += parseInt(idCard.charAt(i)) * weightingFactors[i]; + } + + const mod = sum % 11; + return checkCodes[mod] === idCard.charAt(17); + } + + return false; +} +exports.checkIDCode = checkIDCode; +