Showing
3 changed files
with
87 additions
and
37 deletions
| 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: 2023-01-18 15:58:11 | 4 | + * @LastEditTime: 2023-04-06 17:19:02 |
| 5 | - * @FilePath: /data-table/src/components/EmailField/index.vue | 5 | + * @FilePath: /custom_form/src/components/EmailField/index.vue |
| 6 | * @Description: 邮箱输入框 | 6 | * @Description: 邮箱输入框 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| 9 | <div v-if="HideShow" class="text-field-page"> | 9 | <div v-if="HideShow" class="text-field-page"> |
| 10 | <div class="label"> | 10 | <div class="label"> |
| 11 | - <span v-if="item.component_props.required"> *</span> | 11 | + <text v-if="item.component_props.required"> *</text> |
| 12 | {{ item.component_props.label }} | 12 | {{ item.component_props.label }} |
| 13 | </div> | 13 | </div> |
| 14 | - <van-field | 14 | + <nut-input |
| 15 | - v-model="item.value" | 15 | + v-model="input_value" |
| 16 | :name="item.name" | 16 | :name="item.name" |
| 17 | type="email" | 17 | type="email" |
| 18 | :placeholder="item.component_props.placeholder" | 18 | :placeholder="item.component_props.placeholder" |
| 19 | - :rules="rules" | ||
| 20 | - :required="item.component_props.required" | ||
| 21 | :disabled="item.component_props.disabled" | 19 | :disabled="item.component_props.disabled" |
| 22 | :readonly="item.component_props.readonly" | 20 | :readonly="item.component_props.readonly" |
| 23 | clearable | 21 | clearable |
| 22 | + :border="false" | ||
| 23 | + @blur="onBlur" | ||
| 24 | + style="border: 1px solid #eaeaea; border-radius: 0.25rem; padding: 0.25rem 0.5rem;" | ||
| 24 | /> | 25 | /> |
| 26 | + <div | ||
| 27 | + v-if="show_error" | ||
| 28 | + style="padding-left: 20px; color: red; font-size: 12px;" | ||
| 29 | + > | ||
| 30 | + {{ error_msg }} | ||
| 31 | + </div> | ||
| 25 | </div> | 32 | </div> |
| 26 | </template> | 33 | </template> |
| 27 | 34 | ||
| 28 | <script setup> | 35 | <script setup> |
| 36 | +import { ref, computed, watch, onMounted, nextTick } from "vue"; | ||
| 37 | + | ||
| 29 | const props = defineProps({ | 38 | const props = defineProps({ |
| 30 | item: Object, | 39 | item: Object, |
| 31 | }); | 40 | }); |
| 41 | + | ||
| 32 | // 隐藏显示 | 42 | // 隐藏显示 |
| 33 | const HideShow = computed(() => { | 43 | const HideShow = computed(() => { |
| 34 | return !props.item.component_props.disabled | 44 | return !props.item.component_props.disabled |
| 35 | }) | 45 | }) |
| 46 | + | ||
| 47 | +const onBlur = () => { | ||
| 48 | + // 发送自定义回调数字 | ||
| 49 | + props.item.value = { | ||
| 50 | + key: "email", | ||
| 51 | + filed_name: props.item.key, | ||
| 52 | + value: input_value.value, | ||
| 53 | + }; | ||
| 54 | + emit("active", props.item.value); | ||
| 55 | + validEmail() | ||
| 56 | +} | ||
| 57 | + | ||
| 36 | const required = props.item.component_props.required; | 58 | const required = props.item.component_props.required; |
| 37 | -const validator = (val) => { | 59 | +const emit = defineEmits(["active"]); |
| 38 | - if (required && !val) { | 60 | +const input_value = ref(props.item.component_props.default); |
| 39 | - return false; | 61 | + |
| 40 | - } else if (val && !/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(val)) { | 62 | +const show_error = ref(false); |
| 41 | - return false; | 63 | +const error_msg = ref(''); |
| 64 | + | ||
| 65 | +// 校验模块 | ||
| 66 | +const validEmail = () => { | ||
| 67 | + if (required && !input_value.value) { | ||
| 68 | + show_error.value = true; | ||
| 69 | + error_msg.value = '必填项不能为空'; | ||
| 70 | + } else if (input_value.value && !/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(input_value.value)) { | ||
| 71 | + show_error.value = true; | ||
| 72 | + error_msg.value = '请输入正确邮箱'; | ||
| 42 | } else { | 73 | } else { |
| 43 | - return true; | 74 | + show_error.value = false; |
| 44 | - } | 75 | + error_msg.value = ''; |
| 45 | -}; | ||
| 46 | -// 错误提示文案 | ||
| 47 | -const validatorMessage = (val, rule) => { | ||
| 48 | - if (required && !val) { | ||
| 49 | - return "必填项不能为空"; | ||
| 50 | - } else if (val && !/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(val)) { // 小于最小值 | ||
| 51 | - return "请输入正确邮箱"; | ||
| 52 | } | 76 | } |
| 77 | + return !show_error.value; | ||
| 53 | }; | 78 | }; |
| 54 | -const rules = [{ validator, message: validatorMessage }]; | 79 | + |
| 80 | +defineExpose({ validEmail, id: props.item.key }); | ||
| 55 | </script> | 81 | </script> |
| 56 | 82 | ||
| 57 | -<style lang="less" scoped> | 83 | +<style lang="less"> |
| 58 | .text-field-page { | 84 | .text-field-page { |
| 59 | .label { | 85 | .label { |
| 60 | - padding: 1rem 1rem 0 1rem; | 86 | + padding: 30px 30px 0 30px; |
| 61 | - font-size: 0.9rem; | 87 | + font-size: 26px; |
| 62 | font-weight: bold; | 88 | font-weight: bold; |
| 63 | - span { | 89 | + text { |
| 64 | color: red; | 90 | color: red; |
| 65 | } | 91 | } |
| 66 | } | 92 | } |
| 67 | -} | ||
| 68 | 93 | ||
| 69 | -:deep(.van-field__body) { | 94 | + .nut-input { |
| 70 | - border: 1px solid #eaeaea; | 95 | + padding: 20px 25px; |
| 71 | - border-radius: 0.25rem; | 96 | + } |
| 72 | - padding: 0.25rem 0.5rem; | ||
| 73 | } | 97 | } |
| 98 | + | ||
| 99 | +// :deep(.van-field__body) { | ||
| 100 | +// border: 1px solid #eaeaea; | ||
| 101 | +// border-radius: 0.25rem; | ||
| 102 | +// padding: 0.25rem 0.5rem; | ||
| 103 | +// } | ||
| 74 | </style> | 104 | </style> | ... | ... |
| ... | @@ -11,7 +11,7 @@ import PickerField from '@/components/PickerField/index.vue' | ... | @@ -11,7 +11,7 @@ import PickerField from '@/components/PickerField/index.vue' |
| 11 | // import ImageUploaderField from '@/components/ImageUploaderField/index.vue' | 11 | // import ImageUploaderField from '@/components/ImageUploaderField/index.vue' |
| 12 | // import FileUploaderField from '@/components/FileUploaderField/index.vue' | 12 | // import FileUploaderField from '@/components/FileUploaderField/index.vue' |
| 13 | import PhoneField from '@/components/PhoneField/index.vue' | 13 | import PhoneField from '@/components/PhoneField/index.vue' |
| 14 | -// import EmailField from '@/components/EmailField/index.vue' | 14 | +import EmailField from '@/components/EmailField/index.vue' |
| 15 | // import SignField from '@/components/SignField/index.vue' | 15 | // import SignField from '@/components/SignField/index.vue' |
| 16 | // import RatePickerField from '@/components/RatePickerField/index.vue' | 16 | // import RatePickerField from '@/components/RatePickerField/index.vue' |
| 17 | // import CalendarField from '@/components/CalendarField/index.vue' | 17 | // import CalendarField from '@/components/CalendarField/index.vue' |
| ... | @@ -115,10 +115,10 @@ export function createComponentType(data) { | ... | @@ -115,10 +115,10 @@ export function createComponentType(data) { |
| 115 | item.name = item.key | 115 | item.name = item.key |
| 116 | item.component = PhoneField | 116 | item.component = PhoneField |
| 117 | } | 117 | } |
| 118 | - // if (item.component_props.tag === 'email') { | 118 | + if (item.component_props.tag === 'email') { |
| 119 | - // item.name = item.key | 119 | + item.name = item.key |
| 120 | - // item.component = EmailField | 120 | + item.component = EmailField |
| 121 | - // } | 121 | + } |
| 122 | // if (item.component_props.tag === 'sign') { | 122 | // if (item.component_props.tag === 'sign') { |
| 123 | // item.name = item.key | 123 | // item.name = item.key |
| 124 | // item.component = SignField | 124 | // item.component = SignField | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2023-03-24 09:19:27 | 2 | * @Date: 2023-03-24 09:19:27 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-04-06 16:38:28 | 4 | + * @LastEditTime: 2023-04-06 17:14:16 |
| 5 | * @FilePath: /custom_form/src/pages/table/index.vue | 5 | * @FilePath: /custom_form/src/pages/table/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -134,6 +134,7 @@ const multi_rule = ref([]); | ... | @@ -134,6 +134,7 @@ const multi_rule = ref([]); |
| 134 | const picker = ref([]); | 134 | const picker = ref([]); |
| 135 | const number = ref([]); | 135 | const number = ref([]); |
| 136 | const phone = ref([]); | 136 | const phone = ref([]); |
| 137 | +const email = ref([]); | ||
| 137 | const area_picker = ref([]); | 138 | const area_picker = ref([]); |
| 138 | const image_uploader = ref([]); | 139 | const image_uploader = ref([]); |
| 139 | const file_uploader = ref([]); | 140 | const file_uploader = ref([]); |
| ... | @@ -166,6 +167,9 @@ const setRefMap = (el, item) => { | ... | @@ -166,6 +167,9 @@ const setRefMap = (el, item) => { |
| 166 | if (item.component_props.tag === "phone") { | 167 | if (item.component_props.tag === "phone") { |
| 167 | phone.value.push(el); | 168 | phone.value.push(el); |
| 168 | } | 169 | } |
| 170 | + if (item.component_props.tag === "email") { | ||
| 171 | + email.value.push(el); | ||
| 172 | + } | ||
| 169 | if (item.component_props.tag === "area_picker") { | 173 | if (item.component_props.tag === "area_picker") { |
| 170 | area_picker.value.push(el); | 174 | area_picker.value.push(el); |
| 171 | } | 175 | } |
| ... | @@ -431,6 +435,9 @@ const onActive = (item) => { | ... | @@ -431,6 +435,9 @@ const onActive = (item) => { |
| 431 | if (item.key === "phone") { | 435 | if (item.key === "phone") { |
| 432 | postData.value[item.filed_name] = item.value; | 436 | postData.value[item.filed_name] = item.value; |
| 433 | } | 437 | } |
| 438 | + if (item.key === "email") { | ||
| 439 | + postData.value[item.filed_name] = item.value; | ||
| 440 | + } | ||
| 434 | if (item.key === "image_uploader") { | 441 | if (item.key === "image_uploader") { |
| 435 | postData.value[item.filed_name] = item.value; | 442 | postData.value[item.filed_name] = item.value; |
| 436 | } | 443 | } |
| ... | @@ -561,6 +568,19 @@ const validOther = () => { | ... | @@ -561,6 +568,19 @@ const validOther = () => { |
| 561 | } | 568 | } |
| 562 | }); | 569 | }); |
| 563 | } | 570 | } |
| 571 | + if (email.value) { | ||
| 572 | + // 邮箱 | ||
| 573 | + email.value.forEach((item, index) => { | ||
| 574 | + if (!email.value[index].validEmail()) { | ||
| 575 | + valid = { | ||
| 576 | + status: email.value[index].validEmail(), | ||
| 577 | + key: "email", | ||
| 578 | + id: email.value[index]?.id | ||
| 579 | + }; | ||
| 580 | + return false; | ||
| 581 | + } | ||
| 582 | + }); | ||
| 583 | + } | ||
| 564 | if (area_picker.value) { | 584 | if (area_picker.value) { |
| 565 | // 省市区地址 | 585 | // 省市区地址 |
| 566 | area_picker.value.forEach((item, index) => { | 586 | area_picker.value.forEach((item, index) => { | ... | ... |
-
Please register or login to post a comment