hookehuyr

✨ feat(数字输入控件): 根据新需求,调整新属性显示提交

max,min,count
1 <!-- 1 <!--
2 * @Date: 2022-09-14 14:44:30 2 * @Date: 2022-09-14 14:44:30
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-11-18 13:50:50 4 + * @LastEditTime: 2022-12-21 18:24:37
5 * @FilePath: /data-table/src/components/NumberField/index.vue 5 * @FilePath: /data-table/src/components/NumberField/index.vue
6 * @Description: 数字输入框 6 * @Description: 数字输入框
7 --> 7 -->
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 :id="item.name" 16 :id="item.name"
17 :name="item.name" 17 :name="item.name"
18 :placeholder="item.component_props.placeholder" 18 :placeholder="item.component_props.placeholder"
19 - :rules="item.rules" 19 + :rules="rules"
20 :required="item.component_props.required" 20 :required="item.component_props.required"
21 readonly 21 readonly
22 @touchstart.stop="showKeyboard($event)" 22 @touchstart.stop="showKeyboard($event)"
...@@ -65,12 +65,12 @@ watch( ...@@ -65,12 +65,12 @@ watch(
65 if (v !== props.item.name) { 65 if (v !== props.item.name) {
66 // 还原border颜色 66 // 还原border颜色
67 $(`#${props.item.name}`).parent().css("border-color", "#eaeaea"); 67 $(`#${props.item.name}`).parent().css("border-color", "#eaeaea");
68 - if (props.item.component_props.type === "decimal") { 68 + if (props.item.component_props.max_fraction_count === 0) {
69 - // 显示小数键盘
70 - showDecimal.value = false;
71 - } else {
72 // 显示整数键盘 69 // 显示整数键盘
73 showInteger.value = false; 70 showInteger.value = false;
71 + } else {
72 + // 显示小数键盘
73 + showDecimal.value = false;
74 } 74 }
75 document.getElementById("app").style.paddingBottom = "0"; 75 document.getElementById("app").style.paddingBottom = "0";
76 } 76 }
...@@ -99,24 +99,24 @@ const showKeyboard = (e) => { ...@@ -99,24 +99,24 @@ const showKeyboard = (e) => {
99 // TAG: 自定义主题颜色 99 // TAG: 自定义主题颜色
100 content.css("border-color", "#c2915f"); 100 content.css("border-color", "#c2915f");
101 setTimeout(() => { 101 setTimeout(() => {
102 - if (props.item.component_props.type === "decimal") { 102 + if (props.item.component_props.max_fraction_count === 0) {
103 - // 显示小数键盘
104 - showDecimal.value = true;
105 - } else {
106 // 显示整数键盘 103 // 显示整数键盘
107 showInteger.value = true; 104 showInteger.value = true;
105 + } else {
106 + // 显示小数键盘
107 + showDecimal.value = true;
108 } 108 }
109 }, 300); 109 }, 300);
110 // 记录点击field名 110 // 记录点击field名
111 store.changeFieldName(props.item.name); 111 store.changeFieldName(props.item.name);
112 }; 112 };
113 const blurKeyboard = () => { 113 const blurKeyboard = () => {
114 - if (props.item.component_props.type === "decimal") { 114 + if (props.item.component_props.max_fraction_count === 0) {
115 - // 显示小数键盘
116 - showDecimal.value = false;
117 - } else {
118 // 显示整数键盘 115 // 显示整数键盘
119 showInteger.value = false; 116 showInteger.value = false;
117 + } else {
118 + // 显示小数键盘
119 + showDecimal.value = false;
120 } 120 }
121 document.getElementById("app").style.paddingBottom = "0"; 121 document.getElementById("app").style.paddingBottom = "0";
122 // 还原border颜色 122 // 还原border颜色
...@@ -126,25 +126,38 @@ const blurKeyboard = () => { ...@@ -126,25 +126,38 @@ const blurKeyboard = () => {
126 const showDecimal = ref(false); 126 const showDecimal = ref(false);
127 const showInteger = ref(false); 127 const showInteger = ref(false);
128 128
129 -// // 校验函数返回 true 表示校验通过,false 表示不通过 129 +// 校验函数返回 true 表示校验通过,false 表示不通过
130 -// // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X 130 +const required = props.item.component_props.required;
131 -// const validator = (val) => { 131 +const min = props.item.component_props.min;
132 -// if (!props.item.component_props.required) { 132 +const max = props.item.component_props.max;
133 -// // 非必填 133 +const max_count = props.item.component_props.max_fraction_count; // 保留小数个数 null=不限,0=没有小数,大于0=最多只能输入的小数个数
134 -// return true; 134 +const reg = new RegExp("^([0-9]+)(\\.(\\d){" + max_count +"," + max_count +"})$", "g");
135 -// } else { 135 +const validator = (val) => {
136 -// return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(val); 136 + if (required && !val) { // 必填
137 -// } 137 + return false;
138 -// }; 138 + } else if (min && (val < min)) { // 小于最小值
139 -// // 错误提示文案 139 + return false;
140 -// const validatorMessage = (val, rule) => { 140 + } else if (max && (val > max)) { // 大于最大值
141 -// if (!val) { 141 + return false;
142 -// return "身份证号码不能为空"; 142 + } else if (max_count && !reg.test(val)) { // 不符合保留小数个数
143 -// } else if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(val)) { 143 + return false;
144 -// return "请输入正确身份证号码"; 144 + } else {
145 -// } 145 + return true;
146 -// }; 146 + }
147 -// const rules = [{ validator, message: validatorMessage }]; 147 +};
148 +// 错误提示文案
149 +const validatorMessage = (val, rule) => {
150 + if (required && !val) {
151 + return "输入不能为空";
152 + } else if (min && (val < min)) { // 小于最小值
153 + return "最小值为" + min;
154 + } else if (max && (val > max)) { // 大于最大值
155 + return "最大值为" + max;
156 + } else if (max_count && !reg.test(val)) { // 不符合保留小数个数
157 + return "保留小数点后" + max_count + "位";
158 + }
159 +};
160 +const rules = [{ validator, message: validatorMessage }];
148 161
149 const onInput = (value) => {}; 162 const onInput = (value) => {};
150 const onDelete = () => {}; 163 const onDelete = () => {};
......
1 <!-- 1 <!--
2 * @Date: 2022-07-18 10:22:22 2 * @Date: 2022-07-18 10:22:22
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-12-19 18:09:55 4 + * @LastEditTime: 2022-12-21 18:14:56
5 * @FilePath: /data-table/src/views/index.vue 5 * @FilePath: /data-table/src/views/index.vue
6 * @Description: 首页 6 * @Description: 首页
7 --> 7 -->
...@@ -212,21 +212,24 @@ onMounted(async () => { ...@@ -212,21 +212,24 @@ onMounted(async () => {
212 }; 212 };
213 } 213 }
214 formData.value = formatData(page_form); 214 formData.value = formatData(page_form);
215 - // mockData.value = [ 215 + mockData.value = [
216 - // { 216 + {
217 - // key: "", 217 + key: "111",
218 - // value: "", 218 + value: "",
219 - // component: "", 219 + component: "",
220 - // component_props: { 220 + component_props: {
221 - // name: "multi_rule", 221 + name: "number",
222 - // label: "同意活动规则之后才可提交", 222 + tag: "number",
223 - // required: "1", 223 + label: "数字",
224 - // count: "2", 224 + required: true,
225 - // }, 225 + max_fraction_count: null,
226 - // }, 226 + min: 30,
227 - // ]; 227 + max: 100
228 + },
229 + },
230 + ];
228 // 生成自定义组件 231 // 生成自定义组件
229 - // createComponentType(mockData.value); 232 + createComponentType(mockData.value);
230 createComponentType(formData.value); 233 createComponentType(formData.value);
231 // 过期时间显示 234 // 过期时间显示
232 notice_text.value = `表单报名将在 ${formSetting.value.sjsj_end_time} 后结束`; 235 notice_text.value = `表单报名将在 ${formSetting.value.sjsj_end_time} 后结束`;
...@@ -369,19 +372,19 @@ const onSubmit = async (values) => { ...@@ -369,19 +372,19 @@ const onSubmit = async (values) => {
369 // 检查非表单输入项 372 // 检查非表单输入项
370 if (validOther().status) { 373 if (validOther().status) {
371 console.warn(postData.value); 374 console.warn(postData.value);
372 - // 编辑模式不能提交数据 375 + // // 编辑模式不能提交数据
373 - if (model === 'edit') return false; 376 + // if (model === 'edit') return false;
374 - // 通过验证 377 + // // 通过验证
375 - const result = await addFormDataAPI({ 378 + // const result = await addFormDataAPI({
376 - form_code: $route.query.code, 379 + // form_code: $route.query.code,
377 - data: postData.value, 380 + // data: postData.value,
378 - }); 381 + // });
379 - if (result.code) { 382 + // if (result.code) {
380 - showSuccessToast("提交成功"); 383 + // showSuccessToast("提交成功");
381 - $router.push({ 384 + // $router.push({
382 - path: "/success", 385 + // path: "/success",
383 - }); 386 + // });
384 - } 387 + // }
385 } else { 388 } else {
386 console.warn(validOther().key + "不通过验证"); 389 console.warn(validOther().key + "不通过验证");
387 // // 图片上传控件报错提示 390 // // 图片上传控件报错提示
......