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 65
65
<template>
66
66
<div class="md-demo-password-input">
67
67
<sp-password-input
68
- type="number "
68
+ type="idCard "
69
69
:length="4"
70
70
v-model="value3"
71
71
/>
94
94
95
95
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
96
96
| ------------- | ---------------- | ---------------- | ---------------------- | -------- |
97
- | type | 类型 | string | password,number | password
97
+ | type | 类型 | string | password,number,idCard(身份证后4位) | password
98
98
| validateEvent | 验证 | boolean | — |true
99
99
| value | 绑定值 | string / number | — | — |
100
100
| length | 输入框长度 | number | — |6
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export default {
44
44
type: {
45
45
type: String ,
46
46
default: ' password' ,
47
- validator : (val ) => [' password' , ' number' ].includes (val)
47
+ validator : (val ) => [' password' , ' number' , ' idCard ' ].includes (val)
48
48
},
49
49
validateEvent: {
50
50
type: Boolean ,
@@ -57,7 +57,7 @@ export default {
57
57
},
58
58
data () {
59
59
return {
60
- code: this . value ,
60
+ code: ' ' ,
61
61
isFocus: false ,
62
62
}
63
63
},
@@ -71,7 +71,7 @@ export default {
71
71
},
72
72
watch: {
73
73
code (newVal , oldVal ) {
74
- if (newVal . replace ( / [ ^ \d ] / g , ' ' ) != newVal || (newVal && newVal . length > this .length )) {
74
+ if (! this .isValidateCode (newVal )) {
75
75
this .code = oldVal
76
76
return false
77
77
}
@@ -83,14 +83,27 @@ export default {
83
83
}
84
84
},
85
85
mounted () {
86
+ this .setCurrentValue (this .value )
86
87
document .addEventListener (' click' , this .handleOtherAreaClick )
87
88
},
88
89
beforeDestroy () {
89
90
document .removeEventListener (' click' , this .handleOtherAreaClick )
90
91
},
91
92
methods: {
92
93
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
94
107
},
95
108
handleFocus () {
96
109
this .isFocus = true
You can’t perform that action at this time.
0 commit comments