Skip to content

Commit 49bc55d

Browse files
tank0317dolymood
authored andcommitted
Feat input reverse (#180)
* [add]{input.vue} reverse prop for input * [update]{input.vue} pwdVisible and eyeClass logic * [update] {input.vue} eye logic * [update] {input.vue} input example * [update] input.vue
1 parent e1f2e00 commit 49bc55d

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

example/pages/input.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
@update:value="updatePwd"></switch-option>
3535
<switch-option class="item" name="show eye" :value="showEye"
3636
@update:value="updateShowEye" v-if="isPwd"></switch-option>
37+
<switch-option class="item" name="reverse" :value="reverse"
38+
@update:value="updateReverse" v-if="isPwd && showEye"></switch-option>
3739
<switch-option class="item" name="password visible" :value="pwdVisible"
3840
@update:value="updatePwdVisible" v-if="isPwd && showEye"></switch-option>
3941
</div>
@@ -57,14 +59,16 @@
5759
readonly: false,
5860
isPwd: true,
5961
showEye: true,
60-
pwdVisible: true
62+
pwdVisible: true,
63+
reverse: false
6164
}
6265
},
6366
computed: {
6467
eye() {
6568
if (this.isPwd && this.showEye) {
6669
return {
67-
open: this.pwdVisible
70+
open: this.pwdVisible,
71+
reverse: this.reverse
6872
}
6973
} else {
7074
return false
@@ -90,6 +94,9 @@
9094
},
9195
updatePwdVisible(val) {
9296
this.pwdVisible = val
97+
},
98+
updateReverse(val) {
99+
this.reverse = val
93100
}
94101
},
95102
components: {

src/components/input/input.vue

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@
8484
return {
8585
inputValue: this.value,
8686
isFocus: false,
87-
pwdVisible: false
87+
formatedEye: {
88+
open: false,
89+
reverse: false
90+
}
8891
}
8992
},
9093
computed: {
9194
_type() {
9295
const type = this.type
93-
if (type === 'password' && this.pwdVisible) {
96+
if (type === 'password' && this.formatedEye.open) {
9497
return 'text'
9598
}
9699
return type
@@ -102,7 +105,12 @@
102105
return this.type === 'password' && this.eye && !this.disabled
103106
},
104107
eyeClass() {
105-
return this.pwdVisible ? 'cubeic-eye-invisible' : 'cubeic-eye-visible'
108+
const eye = this.formatedEye
109+
let shouleBeVisible = !eye.open
110+
if (eye.reverse) {
111+
shouleBeVisible = !shouleBeVisible
112+
}
113+
return shouleBeVisible ? 'cubeic-eye-visible' : 'cubeic-eye-invisible'
106114
}
107115
},
108116
watch: {
@@ -112,22 +120,22 @@
112120
inputValue(newValue) {
113121
this.$emit(EVENT_INPUT, newValue)
114122
},
115-
eye() {
116-
this._computedPwdVisible()
123+
eye: {
124+
handler() {
125+
this.formateEye()
126+
},
127+
immediate: true
117128
}
118129
},
119-
created() {
120-
this._computedPwdVisible()
121-
},
122130
methods: {
123131
changeHander(e) {
124132
this.$emit(EVENT_CHANGE, e)
125133
},
126-
_computedPwdVisible() {
134+
formateEye() {
127135
if (typeof this.eye === 'boolean') {
128-
this.pwdVisible = this.eye
136+
this.formatedEye.open = this.eye
129137
} else {
130-
this.pwdVisible = this.eye.open
138+
Object.assign(this.formatedEye, this.eye)
131139
}
132140
},
133141
handleFocus(e) {
@@ -143,7 +151,7 @@
143151
this.$refs.input.focus()
144152
},
145153
handlePwdEye() {
146-
this.pwdVisible = !this.pwdVisible
154+
this.formatedEye.open = !this.formatedEye.open
147155
}
148156
}
149157
}

0 commit comments

Comments
 (0)