File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed
sparta/components/base/password-input/src Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 6565<template>
6666 <div class="md-demo-password-input">
6767 <sp-password-input
68- type="number "
68+ type="idCard "
6969 :length="4"
7070 v-model="value3"
7171 />
9494
9595| 参数 | 说明 | 类型 | 可选值 | 默认值 |
9696| ------------- | ---------------- | ---------------- | ---------------------- | -------- |
97- | type | 类型 | string | password,number | password
97+ | type | 类型 | string | password,number,idCard(身份证后4位) | password
9898| validateEvent | 验证 | boolean | — |true
9999| value | 绑定值 | string / number | — | — |
100100| length | 输入框长度 | number | — |6
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export default {
4444 type: {
4545 type: String ,
4646 default: ' password' ,
47- validator : (val ) => [' password' , ' number' ].includes (val)
47+ validator : (val ) => [' password' , ' number' , ' idCard ' ].includes (val)
4848 },
4949 validateEvent: {
5050 type: Boolean ,
@@ -57,7 +57,7 @@ export default {
5757 },
5858 data () {
5959 return {
60- code: this . value ,
60+ code: ' ' ,
6161 isFocus: false ,
6262 }
6363 },
@@ -71,7 +71,7 @@ export default {
7171 },
7272 watch: {
7373 code (newVal , oldVal ) {
74- if (newVal . replace ( / [ ^ \d ] / g , ' ' ) != newVal || (newVal && newVal . length > this .length )) {
74+ if (! this .isValidateCode (newVal )) {
7575 this .code = oldVal
7676 return false
7777 }
@@ -83,14 +83,27 @@ export default {
8383 }
8484 },
8585 mounted () {
86+ this .setCurrentValue (this .value )
8687 document .addEventListener (' click' , this .handleOtherAreaClick )
8788 },
8889 beforeDestroy () {
8990 document .removeEventListener (' click' , this .handleOtherAreaClick )
9091 },
9192 methods: {
9293 setCurrentValue (value ) {
93- this .code = value
94+ this .code = this .isValidateCode (value) ? value? .toString ().toUpperCase () : this .code
95+ },
96+ isValidateCode (value ) {
97+ if (value && value .length > this .length ) {
98+ return
99+ }
100+ if (value && [' password' , ' number' ].includes (this .type ) && value .replace (/ [^ \d ] / g , ' ' ) != value) {
101+ return
102+ }
103+ if (value && this .type === ' idCard' && ! / ^ \d {1,3} $ | ^ \d {3} [xX] $ | ^ \d {4} $ / .test (value)) {
104+ return
105+ }
106+ return true
94107 },
95108 handleFocus () {
96109 this .isFocus = true
You can’t perform that action at this time.
0 commit comments