hookehuyr

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

<!--
* @Date: 2022-08-29 14:31:20
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-11-18 10:54:23
* @LastEditTime: 2022-11-21 16:08:20
* @FilePath: /data-table/src/components/EmailField/index.vue
* @Description: 邮箱输入框
-->
......@@ -28,8 +28,15 @@ const props = defineProps({
item: Object,
});
const pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
const rules = [{ pattern, message: "请输入正确邮箱" }];
const validator = (val) => {
if (!props.item.component_props.required) {
// 非必填
return true;
} else {
return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(val);
}
};
const rules = [{ validator, message: "请输入正确邮箱" }];
</script>
<style lang="less" scoped>
......