Skip to content

Commit e10ce37

Browse files
msgill2017sendya
authored andcommitted
refactor Register page
1 parent 5055e56 commit e10ce37

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

src/locales/lang/en-US/user.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export default {
3131
'user.email.wrong-format': 'The email address is in the wrong format!',
3232
'user.userName.required': 'Please enter account name or email address',
3333
'user.password.required': 'Please enter your password!',
34-
'user.password.twice': 'The passwords entered twice do not match!',
35-
'user.strength.msg':
36-
"Please enter at least 6 characters and don't use passwords that are easy to guess.",
37-
'user.strength.strong': 'Strength: strong',
38-
'user.strength.medium': 'Strength: medium',
39-
'user.strength.short': 'Strength: too short',
34+
'user.password.twice.msg': 'The passwords entered twice do not match!',
35+
'user.password.strength.msg':
36+
'The password is not strong enough',
37+
'user.password.strength.strong': 'Strength: strong',
38+
'user.password.strength.medium': 'Strength: medium',
39+
'user.password.strength.short': 'Strength: too short',
4040
'user.confirm-password.required': 'Please confirm your password!',
4141
'user.phone-number.required': 'Please enter your phone number!',
4242
'user.phone-number.wrong-format': 'Please enter a valid phone number',

src/locales/lang/zh-CN/user.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export default {
3030
'user.email.wrong-format': '邮箱地址格式错误!',
3131
'user.userName.required': '请输入帐户名或邮箱地址',
3232
'user.password.required': '请输入密码!',
33-
'user.password.twice': '两次输入的密码不匹配!',
34-
'user.strength.msg': '请至少输入 6 个字符。请不要使用容易被猜到的密码。',
35-
'user.strength.strong': '强度:强',
36-
'user.strength.medium': '强度:中',
37-
'user.strength.short': '强度:太短',
33+
'user.password.twice.msg': '两次输入的密码不匹配!',
34+
'user.password.strength.msg': '密码强度不够 ',
35+
'user.password.strength.strong': '强度:强',
36+
'user.password.strength.medium': '强度:中',
37+
'user.password.strength.short': '强度:太短',
3838
'user.confirm-password.required': '请确认密码!',
3939
'user.phone-number.required': '请输入正确的手机号',
4040
'user.phone-number.wrong-format': '手机号格式错误!',

src/views/user/Register.vue

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
size="large"
3232
@click="handlePasswordInputClick"
3333
:placeholder="$t('user.register.password.placeholder')"
34-
v-decorator="['password', {rules: [{ required: true, message: $t('user.password.required')}, { validator: this.handlePasswordLevel }], validateTrigger: ['change', 'blur']}]"
34+
v-decorator="['password', {rules: [{ required: true, message: $t('user.password.required') }, { validator: this.handlePasswordLevel }], validateTrigger: ['change', 'blur']}]"
3535
></a-input-password>
3636
</a-form-item>
3737
</a-popover>
@@ -128,6 +128,7 @@ export default {
128128
129129
state: {
130130
time: 60,
131+
level: 0,
131132
smsSendBtn: false,
132133
passwordLevel: 0,
133134
passwordLevelChecked: false,
@@ -150,43 +151,47 @@ export default {
150151
},
151152
methods: {
152153
handlePasswordLevel (rule, value, callback) {
153-
let level = 0
154-
154+
console.log('value form handlePassword level', value)
155+
if (value === '') {
156+
callback()
157+
} else {
158+
console.log('level inside else form handlePassword level', this.state.level)
155159
// 判断这个字符串中有没有数字
156160
if (/[0-9]/.test(value)) {
157-
level++
161+
this.state.level++
158162
}
159163
// 判断字符串中有没有字母
160164
if (/[a-zA-Z]/.test(value)) {
161-
level++
165+
this.state.level++
162166
}
163167
// 判断字符串中有没有特殊符号
164168
if (/[^0-9a-zA-Z_]/.test(value)) {
165-
level++
169+
this.state.level++
166170
}
167-
this.state.passwordLevel = level
168-
this.state.percent = level * 30
169-
if (level >= 2) {
170-
if (level >= 3) {
171+
this.state.passwordLevel = this.state.level
172+
this.state.percent = this.state.level * 30
173+
if (this.state.level >= 2) {
174+
if (this.state.level >= 3) {
171175
this.state.percent = 100
172176
}
173177
callback()
174178
} else {
175-
if (level === 0) {
179+
if (this.state.level === 0) {
176180
this.state.percent = 10
177181
}
178-
callback(new Error('密码强度不够'))
182+
callback(new Error(this.$t('user.password.strength.msg')))
183+
}
179184
}
180185
},
181186
182187
handlePasswordCheck (rule, value, callback) {
183188
const password = this.form.getFieldValue('password')
184-
console.log('value', value)
189+
// console.log('value', value)
185190
if (value === undefined) {
186-
callback(new Error('请输入密码'))
191+
callback(new Error(this.$t('user.password.required')))
187192
}
188193
if (value && password && value.trim() !== password.trim()) {
189-
callback(new Error('两次密码不一致'))
194+
callback(new Error(this.$t('user.password.twice.msg')))
190195
}
191196
callback()
192197
},

0 commit comments

Comments
 (0)