setPassword.vue
2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<template>
<v-layout id="Password" column justify-center align-center>
<v-flex>
<Stepper :step="stepper" />
<div class="PasswordInputBlock">
<input class="PasswordInput" id="PasswordInput-0" ref="0" maxlength="1" type="password" v-model="inputValue[0]" @input="passwordInput">
<input class="PasswordInput" id="PasswordInput-1" ref="1" maxlength="1" type="password" v-model="inputValue[1]" @input="passwordInput">
<input class="PasswordInput" id="PasswordInput-2" ref="2" maxlength="1" type="password" v-model="inputValue[2]" @input="passwordInput">
<input class="PasswordInput" id="PasswordInput-3" ref="3" maxlength="1" type="password" v-model="inputValue[3]" @input="passwordInput">
<input class="PasswordInput" id="PasswordInput-4" ref="4" maxlength="1" type="password" v-model="inputValue[4]" @input="passwordInput">
</div>
<div class="ConfirmButtonBlock" v-if="stepper === 2">
<v-btn depressed id="ConfirmButton">确 认</v-btn>
</div>
</v-flex>
</v-layout>
</template>
<script>
import Stepper from '@/components/Stepper'
export default {
layout: 'lightColor',
data: () => ({
stepper: 1,
password: '',
passwordConfirm: '',
inputValue: {
0: '',
1: '',
2: '',
3: '',
4: '',
}
}),
components: {
Stepper
},
methods: {
passwordInput(e) {
let id = e.target.id
let index = parseInt(id.split('-')[1])
if (index < 4) {
index++
let next = this.$refs[index.toString()]
next.focus()
} else {
if (this.stepper === 1) {
this.password = this.passwordConnect()
if (this.password !== false) {
this.stepper++
this.inputValue = {
0: '',
1: '',
2: '',
3: '',
4: '',
}
this.$refs['0'].focus()
}
} else {
this.passwordConfirm = this.passwordConnect()
}
}
},
passwordConnect() {
let result = ''
for (let i = 0; i < 5; i++) {
let code = this.inputValue[i]
if (code) {
result += code
} else {
return false
}
}
console.log(result)
return result
}
}
}
</script>
<style lang="scss" scoped>
#Password {
.PasswordInputBlock {
margin-top: 2.9rem;
text-align: center;
.PasswordInput {
width: 2.5rem;
height: 2.5rem;
line-height: 2.5rem;
background-color: #fff;
border: 1px solid $gold;
outline: none;
text-align: center;
font-size: 1.5rem;
margin: 0 0.75rem;
}
}
.ConfirmButtonBlock {
width: 100%;
margin-top: 3.5rem;
text-align: center;
#ConfirmButton {
color: #484646;
background-image: linear-gradient(-213deg, #DAB269 0%, #E7C78C 92%);
border-radius: 2px;
width: 18.5rem;
height: 2.8rem;
margin: auto;
}
}
}
</style>