Showing
3 changed files
with
100 additions
and
16 deletions
src/components/IdentityField/index.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2022-09-14 14:44:30 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-09-14 14:55:53 | ||
| 5 | + * @FilePath: /data-table/src/components/IdentityField/index.vue | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div class="identity-page"> | ||
| 10 | + <div class="label">{{ item.label }}<span v-if="item.required"> *</span></div> | ||
| 11 | + <van-field v-model="item.value" :name="item.name" :placeholder="item.placeholder" | ||
| 12 | + :rules="rules" :required="item.required" readonly @touchstart.stop="show = true" :border="false"> | ||
| 13 | + </van-field> | ||
| 14 | + <van-number-keyboard | ||
| 15 | + v-model="item.value" | ||
| 16 | + :show="show" | ||
| 17 | + extra-key="X" | ||
| 18 | + close-button-text="完成" | ||
| 19 | + @blur="show = false" | ||
| 20 | + @input="onInput" | ||
| 21 | + @delete="onDelete" | ||
| 22 | + /> | ||
| 23 | + </div> | ||
| 24 | +</template> | ||
| 25 | + | ||
| 26 | +<script setup> | ||
| 27 | +const props = defineProps({ | ||
| 28 | + item: Object | ||
| 29 | +}); | ||
| 30 | + | ||
| 31 | +const show = ref(false); | ||
| 32 | + | ||
| 33 | +// 校验函数返回 true 表示校验通过,false 表示不通过 | ||
| 34 | +// 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X | ||
| 35 | +const validator = (val) => { | ||
| 36 | + if (!props.item.required) { // 非必填 | ||
| 37 | + return true | ||
| 38 | + } else { | ||
| 39 | + return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(val); | ||
| 40 | + } | ||
| 41 | +}; | ||
| 42 | +// 错误提示文案 | ||
| 43 | +const validatorMessage = (val, rule) => { | ||
| 44 | + if (!val) { | ||
| 45 | + return '身份证号码不能为空'; | ||
| 46 | + } else if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(val)) { | ||
| 47 | + return '请输入正确身份证号码'; | ||
| 48 | + } | ||
| 49 | +} | ||
| 50 | +const rules = [{ validator, message: validatorMessage }] | ||
| 51 | + | ||
| 52 | +const onInput = (value) => {}; | ||
| 53 | +const onDelete = () => {}; | ||
| 54 | +</script> | ||
| 55 | + | ||
| 56 | +<style lang="less" scoped> | ||
| 57 | +.identity-page { | ||
| 58 | + .label { | ||
| 59 | + padding: 1rem 1rem 0 1rem; | ||
| 60 | + font-size: 0.9rem; | ||
| 61 | + font-weight: bold; | ||
| 62 | + span { | ||
| 63 | + color: red; | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | +</style> |
| ... | @@ -15,6 +15,7 @@ import EmailField from '@/components/EmailField/index.vue' | ... | @@ -15,6 +15,7 @@ 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' |
| 18 | +import IdentityField from '@/components/IdentityField/index.vue' | ||
| 18 | 19 | ||
| 19 | /** | 20 | /** |
| 20 | * 生成自定义组件类型 | 21 | * 生成自定义组件类型 |
| ... | @@ -34,6 +35,7 @@ import CalendarField from '@/components/CalendarField/index.vue' | ... | @@ -34,6 +35,7 @@ import CalendarField from '@/components/CalendarField/index.vue' |
| 34 | * @type sign 电子签名输入框 SignField | 35 | * @type sign 电子签名输入框 SignField |
| 35 | * @type rate_picker 评分选择器 RatePickerField | 36 | * @type rate_picker 评分选择器 RatePickerField |
| 36 | * @type calendar 日历选择器 CalendarField | 37 | * @type calendar 日历选择器 CalendarField |
| 38 | + * @type id_code 日历选择器 IdentityField | ||
| 37 | */ | 39 | */ |
| 38 | export function createComponentType(data) { | 40 | export function createComponentType(data) { |
| 39 | // 判断类型和使用组件 | 41 | // 判断类型和使用组件 |
| ... | @@ -103,5 +105,9 @@ export function createComponentType(data) { | ... | @@ -103,5 +105,9 @@ export function createComponentType(data) { |
| 103 | item.name = item.key; | 105 | item.name = item.key; |
| 104 | item.component = CalendarField; | 106 | item.component = CalendarField; |
| 105 | } | 107 | } |
| 108 | + if (item.component_props.name === 'id_code') { | ||
| 109 | + item.name = item.key; | ||
| 110 | + item.component = IdentityField; | ||
| 111 | + } | ||
| 106 | }) | 112 | }) |
| 107 | } | 113 | } | ... | ... |
| 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-09-14 14:38:05 | 4 | + * @LastEditTime: 2022-09-14 14:56:30 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -60,21 +60,21 @@ onMounted(() => { | ... | @@ -60,21 +60,21 @@ onMounted(() => { |
| 60 | // }, | 60 | // }, |
| 61 | // required: true, | 61 | // required: true, |
| 62 | // }, | 62 | // }, |
| 63 | - { | 63 | + // { |
| 64 | - key: 'date', | 64 | + // key: 'date', |
| 65 | - value: '', | 65 | + // value: '', |
| 66 | - label: '日历选择', | 66 | + // label: '日历选择', |
| 67 | - placeholder: '请选择日历日期', | 67 | + // placeholder: '请选择日历日期', |
| 68 | - component: '', | 68 | + // component: '', |
| 69 | - component_props: { | 69 | + // component_props: { |
| 70 | - name: 'calendar', | 70 | + // name: 'calendar', |
| 71 | - type: 'range', // 日期区间 ['multiple', 'range'] | 71 | + // type: 'range', // 日期区间 ['multiple', 'range'] |
| 72 | - minDate: new Date(2022, 0, 1), // 最小日期 | 72 | + // minDate: new Date(2022, 0, 1), // 最小日期 |
| 73 | - maxDate: new Date(2023, 0, 31), // 最大日期 | 73 | + // maxDate: new Date(2023, 0, 31), // 最大日期 |
| 74 | - maxRange: 5, // 最大可选天数 | 74 | + // maxRange: 5, // 最大可选天数 |
| 75 | - }, | 75 | + // }, |
| 76 | - required: false, | 76 | + // required: false, |
| 77 | - }, | 77 | + // }, |
| 78 | // { | 78 | // { |
| 79 | // key: 'email', | 79 | // key: 'email', |
| 80 | // value: '', | 80 | // value: '', |
| ... | @@ -86,6 +86,17 @@ onMounted(() => { | ... | @@ -86,6 +86,17 @@ onMounted(() => { |
| 86 | // }, | 86 | // }, |
| 87 | // required: true, | 87 | // required: true, |
| 88 | // }, | 88 | // }, |
| 89 | + { | ||
| 90 | + key: 'id_code', | ||
| 91 | + value: '', | ||
| 92 | + label: '身份证号码', | ||
| 93 | + placeholder: '请输入身份证号码', | ||
| 94 | + component: '', | ||
| 95 | + component_props: { | ||
| 96 | + name: 'id_code' | ||
| 97 | + }, | ||
| 98 | + required: true, | ||
| 99 | + }, | ||
| 89 | // { | 100 | // { |
| 90 | // key: 'age', | 101 | // key: 'age', |
| 91 | // value: '', | 102 | // value: '', | ... | ... |
-
Please register or login to post a comment