Commit c3fe5dc0457f1cd7dce4be7b9a598146ded80780

Authored by 张红振
1 parent a8fe69d3

fix bug

src/utils/validate.ts
@@ -43,6 +43,14 @@ export function validPwd(str) { @@ -43,6 +43,14 @@ export function validPwd(str) {
43 export function tphone(value) { 43 export function tphone(value) {
44 return /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/.test(value) 44 return /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/.test(value)
45 } 45 }
  46 +/**
  47 + * 数字校验
  48 + * @param {string} str
  49 + * @returns {Boolean}
  50 + */
  51 +export function price(value) {
  52 + return /^\d+.?\d{0,2}$/.test(value)
  53 +}
46 54
47 /** 55 /**
48 * 身份证号码校验 56 * 身份证号码校验
src/views/community/housekeeper/houseDetail.vue
@@ -8,6 +8,7 @@ import { @@ -8,6 +8,7 @@ import {
8 } from "vue"; 8 } from "vue";
9 import { addOrUpdate } from "@/api/community/housekeeper.ts"; 9 import { addOrUpdate } from "@/api/community/housekeeper.ts";
10 import { getTableList } from "@/api/community/residence.ts"; 10 import { getTableList } from "@/api/community/residence.ts";
  11 +import { price } from "@/utils/validate";
11 12
12 const ruleFormRef = ref<InstanceType<typeof ElForm>>(); 13 const ruleFormRef = ref<InstanceType<typeof ElForm>>();
13 let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例 14 let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
@@ -48,6 +49,24 @@ const getSelectList = (): void =&gt; { @@ -48,6 +49,24 @@ const getSelectList = (): void =&gt; {
48 onMounted(() => { 49 onMounted(() => {
49 getSelectList(); 50 getSelectList();
50 }); 51 });
  52 +
  53 +/**
  54 + * 校验身份证
  55 + * @param {object} rules 验证规则
  56 + * @param {string} value 待验证数值
  57 + * @callback checkCard~checkCallback
  58 + */
  59 +const checkPrice = (rules, value, callback) => {
  60 + if (price(value)) {
  61 + if (value > 50000) {
  62 + callback(new Error("请输入正确的数值"));
  63 + } else {
  64 + callback();
  65 + }
  66 + } else {
  67 + callback(new Error("请输入正确的数值"));
  68 + }
  69 +};
51 // 表单验证 70 // 表单验证
52 const rules = reactive({ 71 const rules = reactive({
53 neighborhoodId: [ 72 neighborhoodId: [
@@ -85,13 +104,9 @@ const rules = reactive({ @@ -85,13 +104,9 @@ const rules = reactive({
85 required: true, 104 required: true,
86 message: "请输入建筑面积", 105 message: "请输入建筑面积",
87 trigger: "blur", 106 trigger: "blur",
88 - // whitespace: true,  
89 }, 107 },
90 { 108 {
91 - type: "number",  
92 - message: "请输入正确的建筑面积",  
93 - max: 50000,  
94 - transform: (value) => Number(value), 109 + validator: checkPrice,
95 }, 110 },
96 ], 111 ],
97 houseCount: [ 112 houseCount: [
@@ -107,13 +122,9 @@ const rules = reactive({ @@ -107,13 +122,9 @@ const rules = reactive({
107 required: true, 122 required: true,
108 message: "请输入使用面积", 123 message: "请输入使用面积",
109 trigger: "blur", 124 trigger: "blur",
110 - // whitespace: true,  
111 }, 125 },
112 { 126 {
113 - type: "number",  
114 - message: "请输入正确的使用面积",  
115 - max: 50000,  
116 - transform: (value) => Number(value), 127 + validator: checkPrice,
117 }, 128 },
118 ], 129 ],
119 }); 130 });