hookehuyr

🐞 fix(邮箱组件): 非必填情况下不校验有效性

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-18 10:54:23 4 + * @LastEditTime: 2022-11-21 16:08:20
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,8 +28,15 @@ const props = defineProps({ ...@@ -28,8 +28,15 @@ const props = defineProps({
28 item: Object, 28 item: Object,
29 }); 29 });
30 30
31 -const pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/; 31 +const validator = (val) => {
32 -const rules = [{ pattern, message: "请输入正确邮箱" }]; 32 + if (!props.item.component_props.required) {
33 + // 非必填
34 + return true;
35 + } else {
36 + return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(val);
37 + }
38 +};
39 +const rules = [{ validator, message: "请输入正确邮箱" }];
33 </script> 40 </script>
34 41
35 <style lang="less" scoped> 42 <style lang="less" scoped>
......