hookehuyr

邮箱控件校验调整

1 <!-- 1 <!--
2 * @Date: 2022-08-29 14:31:20 2 * @Date: 2022-08-29 14:31:20
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-11-21 16:08:20 4 + * @LastEditTime: 2022-12-22 13:17:34
5 * @FilePath: /data-table/src/components/EmailField/index.vue 5 * @FilePath: /data-table/src/components/EmailField/index.vue
6 * @Description: 邮箱输入框 6 * @Description: 邮箱输入框
7 --> 7 -->
...@@ -28,15 +28,25 @@ const props = defineProps({ ...@@ -28,15 +28,25 @@ const props = defineProps({
28 item: Object, 28 item: Object,
29 }); 29 });
30 30
31 +const required = props.item.component_props.required;
31 const validator = (val) => { 32 const validator = (val) => {
32 - if (!props.item.component_props.required) { 33 + if (required && !val) {
33 - // 非必填 34 + return false;
34 - return true; 35 + } else if (val && !/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(val)) {
36 + return false;
35 } else { 37 } else {
36 - return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(val); 38 + return true;
39 + }
40 +};
41 +// 错误提示文案
42 +const validatorMessage = (val, rule) => {
43 + if (required && !val) {
44 + return "必填项不能为空";
45 + } else if (val && !/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(val)) { // 小于最小值
46 + return "请输入正确邮箱";
37 } 47 }
38 }; 48 };
39 -const rules = [{ validator, message: "请输入正确邮箱" }]; 49 +const rules = [{ validator, message: validatorMessage }];
40 </script> 50 </script>
41 51
42 <style lang="less" scoped> 52 <style lang="less" scoped>
......
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-12-22 11:28:05 4 + * @LastEditTime: 2022-12-22 13:15:32
5 * @FilePath: /data-table/src/components/NumberField/index.vue 5 * @FilePath: /data-table/src/components/NumberField/index.vue
6 * @Description: 数字输入框 6 * @Description: 数字输入框
7 --> 7 -->
...@@ -148,7 +148,7 @@ const validator = (val) => { ...@@ -148,7 +148,7 @@ const validator = (val) => {
148 // 错误提示文案 148 // 错误提示文案
149 const validatorMessage = (val, rule) => { 149 const validatorMessage = (val, rule) => {
150 if (required && !val) { 150 if (required && !val) {
151 - return "输入不能为空"; 151 + return "必填项不能为空";
152 } else if (val && min && (val < min)) { // 小于最小值 152 } else if (val && min && (val < min)) { // 小于最小值
153 return "最小值为" + min; 153 return "最小值为" + min;
154 } else if (val && max && (val > max)) { // 大于最大值 154 } else if (val && max && (val > max)) { // 大于最大值
......