From c869599d0b2a23cb3d52b133b470288654a2411e Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Mon, 7 Dec 2020 15:33:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=81=E4=BB=B6=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/custom/SysWxUserLogMapper.xml | 2 +- stdiet-ui/src/utils/ruoyi.js | 105 +++++++++++------- .../src/views/custom/signContract/index.vue | 19 +++- 3 files changed, 86 insertions(+), 40 deletions(-) diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml index 073a7b59e..943d4879d 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysWxUserLogMapper.xml @@ -59,7 +59,7 @@ and appid = #{appid} - or phone = #{phone} + and phone = #{phone} order by create_time asc diff --git a/stdiet-ui/src/utils/ruoyi.js b/stdiet-ui/src/utils/ruoyi.js index d3ee8500f..f73903fa7 100644 --- a/stdiet-ui/src/utils/ruoyi.js +++ b/stdiet-ui/src/utils/ruoyi.js @@ -155,10 +155,10 @@ export function handleTree(data, id, parentId, children, rootId) { } /** 数字逢三位加逗号 */ -export function toThousands(num){ +export function toThousands(num) { const str = num.toString(); const reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g; - return str.replace(reg,"$1,"); + return str.replace(reg, "$1,"); } export function digitUppercase(n) { @@ -210,44 +210,73 @@ export function digitUppercase(n) { * 十五,十六,十七都是数字0-9 * 十八位可能是数字0-9,也可能是X * */ -export function validatorIDCard(idcode) { - if (typeof idcode !== 'string') { - return { - code: -1, - msg: "为了避免javascript数值范围误差,idcode 必须是字符串" +export function validatorIDCard(idcode, type) { + if (type === 1) { + if (typeof idcode !== 'string') { + return { + code: -1, + msg: "为了避免javascript数值范围误差,idcode 必须是字符串" + } } - } - const idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/; - // 判断格式是否正确 - const format = idcard_patter.test(idcode); - if (!format) { - return { - code: -1, - msg: "身份证号码格式错误" + const idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/; + // 判断格式是否正确 + const format = idcard_patter.test(idcode); + if (!format) { + return { + code: -1, + msg: "身份证号码格式错误" + } + } + // 加权因子 + const weight_factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; + // 校验码 + const check_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; + const last = idcode[17];//最后一位 + const seventeen = idcode.substring(0, 17); + // ISO 7064:1983.MOD 11-2 + // 判断最后一位校验码是否正确 + const arr = seventeen.split(""); + const len = arr.length; + let num = 0; + for (let i = 0; i < len; i++) { + num += arr[i] * weight_factor[i]; + } + // 获取余数 + const resisue = num % 11; + const last_no = check_code[resisue]; + // 返回验证结果,校验码和格式同时正确才算是合法的身份证号码 + const result = last === last_no ? true : false; + return { + code: result ? 1 : -1, + msg: !result ? "身份证号码不合规" : "校验通过" + } + } else if (type === 2) { + const reg = /^([A-Z]\d{6,10}(\(\w{1}\))?)$/; + if (reg.test(idcode) === false) { + return {code: -1, msg: '港澳居民来往内地通行证号码不合规'}; + } else { + return {code: 1, msg: '校验通过'}; + } + } else if (type === 3) { + // 台湾居民来往大陆通行证 + // 规则: 新版8位或18位数字, 旧版10位数字 + 英文字母 + // 样本: 12345678 或 1234567890B + const reg = /^\d{8}|^[a-zA-Z0-9]{10}|^\d{18}$/; + if (reg.test(card) === false) { + return {code: -1, msg: '台湾居民来往大陆通行证号码不合规'}; + } else { + return {code: 1, msg: '校验通过'}; + } + } else if (type === 4) { + // 军官证 + // 规则: 军/兵/士/文/职/广/(其他中文) + "字第" + 4到8位字母或数字 + "号" + // 样本: 军字第2001988号, 士字第P011816X号 + const reg = /^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,8})(号?)$/; + if (reg.test(card) === false) { + return {code: -1, msg: '军官证号不合规'}; + } else { + return {code: 1, msg: '校验通过'}; } - } - // 加权因子 - const weight_factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; - // 校验码 - const check_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; - const last = idcode[17];//最后一位 - const seventeen = idcode.substring(0, 17); - // ISO 7064:1983.MOD 11-2 - // 判断最后一位校验码是否正确 - const arr = seventeen.split(""); - const len = arr.length; - let num = 0; - for (let i = 0; i < len; i++) { - num += arr[i] * weight_factor[i]; - } - // 获取余数 - const resisue = num % 11; - const last_no = check_code[resisue]; - // 返回验证结果,校验码和格式同时正确才算是合法的身份证号码 - const result = last === last_no ? true : false; - return { - code: result ? 1 : -1, - msg: !result ? "身份证号码格式错误" : "" } } diff --git a/stdiet-ui/src/views/custom/signContract/index.vue b/stdiet-ui/src/views/custom/signContract/index.vue index 5a336415f..9e4bf990f 100644 --- a/stdiet-ui/src/views/custom/signContract/index.vue +++ b/stdiet-ui/src/views/custom/signContract/index.vue @@ -23,6 +23,15 @@ + + + + + @@ -148,7 +157,7 @@ return callback(new Error('证件号码不能为空')) } setTimeout(() => { - const {code, msg} = validatorIDCard(value); + const {code, msg} = validatorIDCard(value, this.idType); if (code === 1) { callback() } else { @@ -162,6 +171,14 @@ form: {}, read: false, dialogVisible: false, + idType: 1, + idTypeOptions: [ + {label: '身份证', value: 1}, + {label: '港澳身份证', value: 2}, + {label: '台湾身份证', value: 3}, + {label: '护照', value: 4}, + {label: '军官证', value: 5}, + ], serveTimeIdOption: [ {label: '7天', value: 7}, {label: '1个月', value: 30},