From 5f9109b1ef2616e74d0e21be8e4c18d0d0ed939a Mon Sep 17 00:00:00 2001
From: huangdeliang
Date: Fri, 6 Nov 2020 13:32:44 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BA=AB=E4=BB=BD=E8=AF=81?=
=?UTF-8?q?=E6=A0=A1=E9=AA=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ruoyi-ui/src/main.js | 4 +-
ruoyi-ui/src/utils/ruoyi.js | 60 +++++++++++++++++++
.../src/views/custom/signContract/index.vue | 19 +++---
3 files changed, 70 insertions(+), 13 deletions(-)
diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js
index a2be0932a..54003076a 100644
--- a/ruoyi-ui/src/main.js
+++ b/ruoyi-ui/src/main.js
@@ -26,7 +26,8 @@ import {
digitUppercase,
selectDictLabel,
selectDictLabels,
- toThousands
+ toThousands,
+ validatorIDCard
} from "@/utils/ruoyi";
import Pagination from "@/components/Pagination";
//自定义表格工具扩展
@@ -44,6 +45,7 @@ Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.toThousands = toThousands
Vue.prototype.digitUppercase = digitUppercase
+Vue.prototype.validatorIDCard = validatorIDCard
Vue.prototype.msgSuccess = function (msg) {
this.$message({showClose: true, message: msg, type: "success"});
diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js
index 58f7e4bc4..113be2069 100644
--- a/ruoyi-ui/src/utils/ruoyi.js
+++ b/ruoyi-ui/src/utils/ruoyi.js
@@ -197,3 +197,63 @@ export function digitUppercase(n) {
.replace(/(零.)+/g, '零')
.replace(/^整$/, '零元整');
};
+
+
+/*
+*
+* @params {string} idcode
+*
+* 函数参数必须是字符串,因为二代身份证号码是十八位,而在javascript中,十八位的数值会超出计算范围,造成不精确的结果,
+* 导致最后两位和计算的值不一致,从而该函数出现错误(详情查看javascript的数值范围)。
+* 为了避免这一误差,idcode必须是字符串
+*
+* 正则思路:
+* 第一位不可能是0
+* 第二位到第六位可以是0-9
+* 第七位到第十位是年份,所以七八位为19或者20
+* 十一位和十二位是月份,这两位是01-12之间的数值
+* 十三位和十四位是日期,是从01-31之间的数值
+* 十五,十六,十七都是数字0-9
+* 十八位可能是数字0-9,也可能是X
+* */
+export function validatorIDCard(idcode) {
+ 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 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/ruoyi-ui/src/views/custom/signContract/index.vue b/ruoyi-ui/src/views/custom/signContract/index.vue
index 36116747e..22022a4c6 100644
--- a/ruoyi-ui/src/views/custom/signContract/index.vue
+++ b/ruoyi-ui/src/views/custom/signContract/index.vue
@@ -65,7 +65,8 @@
第二条 合作内容及费用
经甲乙双方协商确定,乙方向甲方购买 {{form.serveTimeStr}} “胜唐体控瘦身指导服务”(以下简称服务)。
- 经甲乙双方协商一致,确定乙方向甲方支付服务费用为人民币 {{form.amount}},大写:{{form.amountUpper}}。
+ 经甲乙双方协商一致,确定乙方向甲方支付服务费用为人民币 {{form.amount}},大写:{{form.amountUpper}}。
+
第三条 服务期约定
@@ -105,7 +106,7 @@