Showing
1 changed file
with
23 additions
and
27 deletions
| 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: 2023-02-01 15:07:15 | 4 | + * @LastEditTime: 2023-04-06 10:16:18 |
| 5 | - * @FilePath: /data-table/src/components/IdentityField/index.vue | 5 | + * @FilePath: /custom_form/src/components/IdentityField/index.vue |
| 6 | * @Description: 身份证输入控件 | 6 | * @Description: 身份证输入控件 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| ... | @@ -12,30 +12,14 @@ | ... | @@ -12,30 +12,14 @@ |
| 12 | {{ item.component_props.label }} | 12 | {{ item.component_props.label }} |
| 13 | </div> | 13 | </div> |
| 14 | <!-- <div v-if="item.component_props.readonly" style="padding: 0.5rem 1rem;">{{ item.value }}</div> --> | 14 | <!-- <div v-if="item.component_props.readonly" style="padding: 0.5rem 1rem;">{{ item.value }}</div> --> |
| 15 | - <van-field | 15 | + <van-field ref="fieldRef" v-model="item.value" :id="item.name" :name="item.name" |
| 16 | - v-model="item.value" | 16 | + :placeholder="item.component_props.placeholder" :rules="rules" :required="item.component_props.required" |
| 17 | - :id="item.name" | 17 | + :disabled="item.component_props.readonly" :readonly="!edit_mode" right-icon="edit" |
| 18 | - :name="item.name" | 18 | + @click-right-icon="clickRightIcon" @touchstart.stop="openKeyboard($event)" :border="false"> |
| 19 | - :placeholder="item.component_props.placeholder" | ||
| 20 | - :rules="rules" | ||
| 21 | - :required="item.component_props.required" | ||
| 22 | - :disabled="item.component_props.readonly" | ||
| 23 | - readonly | ||
| 24 | - @touchstart.stop="openKeyboard($event)" | ||
| 25 | - :border="false" | ||
| 26 | - > | ||
| 27 | </van-field> | 19 | </van-field> |
| 28 | <!-- <div v-if="gender" class="gender"><span>性别:</span>{{ gender }}</div> --> | 20 | <!-- <div v-if="gender" class="gender"><span>性别:</span>{{ gender }}</div> --> |
| 29 | - <van-number-keyboard | 21 | + <van-number-keyboard v-model="item.value" :show="show" extra-key="X" close-button-text="完成" @blur="blurKeyboard()" |
| 30 | - v-model="item.value" | 22 | + @input="onInput" @delete="onDelete" safe-area-inset-bottom /> |
| 31 | - :show="show" | ||
| 32 | - extra-key="X" | ||
| 33 | - close-button-text="完成" | ||
| 34 | - @blur="blurKeyboard()" | ||
| 35 | - @input="onInput" | ||
| 36 | - @delete="onDelete" | ||
| 37 | - safe-area-inset-bottom | ||
| 38 | - /> | ||
| 39 | </div> | 23 | </div> |
| 40 | </template> | 24 | </template> |
| 41 | 25 | ||
| ... | @@ -44,6 +28,7 @@ import $ from "jquery"; | ... | @@ -44,6 +28,7 @@ import $ from "jquery"; |
| 44 | import { storeToRefs, mainStore } from "@/utils/generatePackage"; | 28 | import { storeToRefs, mainStore } from "@/utils/generatePackage"; |
| 45 | import { showSuccessToast, showFailToast } from "vant"; | 29 | import { showSuccessToast, showFailToast } from "vant"; |
| 46 | 30 | ||
| 31 | + | ||
| 47 | const props = defineProps({ | 32 | const props = defineProps({ |
| 48 | item: Object, | 33 | item: Object, |
| 49 | }); | 34 | }); |
| ... | @@ -71,8 +56,16 @@ watch( | ... | @@ -71,8 +56,16 @@ watch( |
| 71 | } | 56 | } |
| 72 | ); | 57 | ); |
| 73 | const readonly = props.item.component_props.readonly; | 58 | const readonly = props.item.component_props.readonly; |
| 59 | +const fieldRef = ref(null); | ||
| 60 | +const edit_mode = ref(false); | ||
| 61 | +const clickRightIcon = () => { // 编辑模式 | ||
| 62 | + edit_mode.value = true; | ||
| 63 | + nextTick(() => { | ||
| 64 | + fieldRef.value?.focus(); | ||
| 65 | + }) | ||
| 66 | +} | ||
| 74 | const openKeyboard = (e) => { | 67 | const openKeyboard = (e) => { |
| 75 | - if (readonly) return false; // 如果为只读,不能设置 | 68 | + if (readonly || e.target.className.indexOf('edit') > 0 || edit_mode.value) return false; // 如果为只读或者编辑模式,不能设置 |
| 76 | // // 键盘上移动 | 69 | // // 键盘上移动 |
| 77 | // const target_to_view_height = window.innerHeight - e.target.getBoundingClientRect().y; // 元素到适口高度 | 70 | // const target_to_view_height = window.innerHeight - e.target.getBoundingClientRect().y; // 元素到适口高度 |
| 78 | // const target_top = document.body.scrollHeight - $(e.target).offset().top; // 元素到正文高度 | 71 | // const target_top = document.body.scrollHeight - $(e.target).offset().top; // 元素到正文高度 |
| ... | @@ -143,8 +136,8 @@ const validatorMessage = (val, rule) => { | ... | @@ -143,8 +136,8 @@ const validatorMessage = (val, rule) => { |
| 143 | }; | 136 | }; |
| 144 | const rules = [{ validator, message: validatorMessage }]; | 137 | const rules = [{ validator, message: validatorMessage }]; |
| 145 | 138 | ||
| 146 | -const onInput = (value) => {}; | 139 | +const onInput = (value) => { }; |
| 147 | -const onDelete = () => {}; | 140 | +const onDelete = () => { }; |
| 148 | 141 | ||
| 149 | const gender = ref(''); | 142 | const gender = ref(''); |
| 150 | 143 | ||
| ... | @@ -178,13 +171,16 @@ const getGenderByIdNumber = (idNumber) => { | ... | @@ -178,13 +171,16 @@ const getGenderByIdNumber = (idNumber) => { |
| 178 | padding: 1rem 1rem 0 1rem; | 171 | padding: 1rem 1rem 0 1rem; |
| 179 | font-size: 0.9rem; | 172 | font-size: 0.9rem; |
| 180 | font-weight: bold; | 173 | font-weight: bold; |
| 174 | + | ||
| 181 | span { | 175 | span { |
| 182 | color: red; | 176 | color: red; |
| 183 | } | 177 | } |
| 184 | } | 178 | } |
| 179 | + | ||
| 185 | .gender { | 180 | .gender { |
| 186 | padding: 0 1rem 0 1rem; | 181 | padding: 0 1rem 0 1rem; |
| 187 | font-size: 0.9rem; | 182 | font-size: 0.9rem; |
| 183 | + | ||
| 188 | span { | 184 | span { |
| 189 | font-weight: bold; | 185 | font-weight: bold; |
| 190 | } | 186 | } | ... | ... |
-
Please register or login to post a comment