@@ -191,6 +191,30 @@ export default {
191191 message: this .$t (' account_user_null' ),
192192 },
193193 ],
194+ password: [
195+ {
196+ required: true ,
197+ validator : (rule , v , callback ) => {
198+ if (
199+ this .createForm .id && // 编辑时密码选填,但填了就要校验
200+ ! v
201+ )
202+ return callback ()
203+ if (! v || ! v .trim ()) {
204+ return callback (new Error (this .$t (' user_form_password_null' )))
205+ } else if (v .length < 5 || v .length > 32 ) {
206+ return callback (new Error (this .$t (' user_form_pass_hint' )))
207+ } else if (/ [\s \u4E00 -\u9FA5 ] / .test (v)) {
208+ return callback (
209+ new Error (this .$t (' user_form_password_not_cn' )),
210+ )
211+ } else {
212+ return callback ()
213+ }
214+ },
215+ trigger: [' blur' , ' change' ],
216+ },
217+ ],
194218 email: [
195219 {
196220 required: true ,
@@ -220,6 +244,19 @@ export default {
220244 table () {
221245 return this .$refs .table
222246 },
247+ passwordStrength () {
248+ const v = this .createForm .password
249+ if (! v) return 0
250+ let score = 0
251+ if (v .length >= 5 ) score++
252+ if (v .length >= 8 ) score++
253+ if (/ [A-Z ] / .test (v)) score++
254+ if (/ \d / .test (v)) score++
255+ if (/ [^ A-Z0-9 ] / i .test (v)) score++
256+ if (score <= 1 ) return 1 // 弱
257+ if (score <= 3 ) return 2 // 中
258+ return 3 // 强
259+ },
223260 },
224261 watch: {
225262 ' $route.query ' : function () {
@@ -1092,6 +1129,28 @@ export default {
10921129 maxlength= " 32"
10931130 show- password
10941131 / >
1132+ < div v- if = " createForm.password" class = " password-strength mt-1" >
1133+ < div class = " password-strength__bars" >
1134+ < span
1135+ v- for = " i in 3"
1136+ : key= " i"
1137+ class = " password-strength__bar"
1138+ : class = " `password-strength__bar--${passwordStrength >= i ? ['weak', 'medium', 'strong'][passwordStrength - 1] : 'empty'}`"
1139+ / >
1140+ < / div>
1141+ < span
1142+ class = " password-strength__label"
1143+ : class = " `password-strength__label--${['weak', 'medium', 'strong'][passwordStrength - 1]}`"
1144+ >
1145+ {{
1146+ [
1147+ $t (' user_password_strength_weak' ),
1148+ $t (' user_password_strength_medium' ),
1149+ $t (' user_password_strength_strong' ),
1150+ ][passwordStrength - 1 ]
1151+ }}
1152+ < / span>
1153+ < / div>
10951154 < / el- form- item>
10961155
10971156 <!-- 角色 -->
@@ -1240,4 +1299,54 @@ export default {
12401299 }
12411300 }
12421301}
1302+
1303+ .password - strength {
1304+ display: flex;
1305+ align- items: center;
1306+ gap: 8px ;
1307+ width: 100 % ;
1308+ line- height: 20px ;
1309+
1310+ & __bars {
1311+ display: flex;
1312+ gap: 4px ;
1313+ flex: 1 ;
1314+ }
1315+
1316+ & __bar {
1317+ flex: 1 ;
1318+ height: 4px ;
1319+ border- radius: 2px ;
1320+ transition: background- color 0 .3s ;
1321+
1322+ & -- empty {
1323+ background- color: var (-- el- border- color);
1324+ }
1325+ & -- weak {
1326+ background- color: #f56c6c;
1327+ }
1328+ & -- medium {
1329+ background- color: #e6a23c;
1330+ }
1331+ & -- strong {
1332+ background- color: #67c23a ;
1333+ }
1334+ }
1335+
1336+ & __label {
1337+ font- size: 12px ;
1338+ min- width: 16px ;
1339+ text- align: right;
1340+
1341+ & -- weak {
1342+ color: #f56c6c;
1343+ }
1344+ & -- medium {
1345+ color: #e6a23c;
1346+ }
1347+ & -- strong {
1348+ color: #67c23a ;
1349+ }
1350+ }
1351+ }
12431352< / style>
0 commit comments