|
18 | 18 | v-model="state.passwordLevelChecked">
|
19 | 19 | <template slot="content">
|
20 | 20 | <div :style="{ width: '240px' }" >
|
21 |
| - <div :class="['user-register', passwordLevelClass]">强度:<span>{{ passwordLevelName }}</span></div> |
| 21 | + <div :class="['user-register', passwordLevelClass]">{{ $t(passwordLevelName) }}</div> |
22 | 22 | <a-progress :percent="state.percent" :showInfo="false" :strokeColor=" passwordLevelColor " />
|
23 | 23 | <div style="margin-top: 10px;">
|
24 | 24 | <span>{{ $t('user.register.password.popover-message') }}
|
|
98 | 98 | <script>
|
99 | 99 | import { getSmsCaptcha } from '@/api/login'
|
100 | 100 | import { deviceMixin } from '@/store/device-mixin'
|
| 101 | +import { scorePassword } from '@/utils/util' |
101 | 102 |
|
102 | 103 | const levelNames = {
|
103 |
| - 0: '低', |
104 |
| - 1: '低', |
105 |
| - 2: '中', |
106 |
| - 3: '强' |
| 104 | + 0: 'user.password.strength.short', |
| 105 | + 1: 'user.password.strength.low', |
| 106 | + 2: 'user.password.strength.medium', |
| 107 | + 3: 'user.password.strength.strong' |
107 | 108 | }
|
108 | 109 | const levelClass = {
|
109 | 110 | 0: 'error',
|
@@ -151,37 +152,26 @@ export default {
|
151 | 152 | },
|
152 | 153 | methods: {
|
153 | 154 | handlePasswordLevel (rule, value, callback) {
|
154 |
| - console.log('value form handlePassword level', value) |
155 | 155 | if (value === '') {
|
156 |
| - callback() |
157 |
| - } else { |
158 |
| - console.log('level inside else form handlePassword level', this.state.level) |
159 |
| - // 判断这个字符串中有没有数字 |
160 |
| - if (/[0-9]/.test(value)) { |
161 |
| - this.state.level++ |
162 |
| - } |
163 |
| - // 判断字符串中有没有字母 |
164 |
| - if (/[a-zA-Z]/.test(value)) { |
165 |
| - this.state.level++ |
166 |
| - } |
167 |
| - // 判断字符串中有没有特殊符号 |
168 |
| - if (/[^0-9a-zA-Z_]/.test(value)) { |
169 |
| - this.state.level++ |
| 156 | + return callback() |
170 | 157 | }
|
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) { |
175 |
| - this.state.percent = 100 |
| 158 | + console.log('scorePassword ; ', scorePassword(value)) |
| 159 | + if (value.length >= 6) { |
| 160 | + if (scorePassword(value) >= 30) { |
| 161 | + this.state.level = 1 |
176 | 162 | }
|
177 |
| - callback() |
178 |
| - } else { |
179 |
| - if (this.state.level === 0) { |
180 |
| - this.state.percent = 10 |
| 163 | + if (scorePassword(value) >= 60) { |
| 164 | + this.state.level = 2 |
181 | 165 | }
|
| 166 | + if (scorePassword(value) >= 80) { |
| 167 | + this.state.level = 3 |
| 168 | + } |
| 169 | + } else { |
| 170 | + this.state.level = 0 |
182 | 171 | callback(new Error(this.$t('user.password.strength.msg')))
|
183 | 172 | }
|
184 |
| - } |
| 173 | + this.state.passwordLevel = this.state.level |
| 174 | + this.state.percent = this.state.level * 33 |
185 | 175 | },
|
186 | 176 |
|
187 | 177 | handlePasswordCheck (rule, value, callback) {
|
|
0 commit comments