Browse Source

修改密码功能

seimin 2 years ago
parent
commit
52e564c87b
4 changed files with 59 additions and 16 deletions
  1. 1 1
      proxy.conf.json
  2. 12 13
      src/app/views/main/main.component.html
  3. 45 1
      src/app/views/main/main.component.ts
  4. 1 1
      src/main.ts

+ 1 - 1
proxy.conf.json

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "/service": {
3
-    "target": "http://192.168.4.190",
3
+    "target": "http://192.168.3.108",
4 4
     "logLevel": "debug",
5 5
     "changeOrigin": true,
6 6
     "pathRewrite": {

+ 12 - 13
src/app/views/main/main.component.html

@@ -91,11 +91,11 @@
91 91
 </ng-template>
92 92
 <!-- 修改密码 -->
93 93
 <nz-modal [(nzVisible)]="isPwdVisible" nzTitle="修改密码" (nzOnCancel)="pwdHandleCancel()" (nzOnOk)="pwdHandleOk()"
94
-  [nzOkLoading]="pwdIsOkLoading">
94
+  [nzOkLoading]="pwdIsOkLoading" (nzAfterOpen)="pwdAfterOpen()">
95 95
   <div>
96 96
     <label>原始密码:
97 97
       <nz-input-group [nzSuffix]="suffixTemplate">
98
-        <input maxlength="16" minlength="6" [type]="passwordVisible ? 'text' : 'password'" nz-input placeholder="原始密码"
98
+        <input minlength="9" [type]="passwordVisible ? 'text' : 'password'" nz-input placeholder="原始密码"
99 99
           [(ngModel)]="upModalData.pwdOld" />
100 100
       </nz-input-group>
101 101
       <ng-template #suffixTemplate>
@@ -104,24 +104,23 @@
104 104
       </ng-template>
105 105
     </label>
106 106
     <label>新密码:
107
-      <!-- <div style="display: flex;"> -->
107
+      <div style="display: flex;">
108 108
         <nz-input-group [nzSuffix]="suffixTemplate">
109
-          <input maxlength="16" minlength="6" [type]="passwordVisible ? 'text' : 'password'" nz-input placeholder="新密码"
110
-            [(ngModel)]="upModalData.newPwd" />
109
+          <input minlength="9" [type]="passwordVisible ? 'text' : 'password'" nz-input placeholder="新密码"
110
+            [(ngModel)]="upModalData.newPwd" (ngModelChange)="blurNewPwd()" />
111 111
         </nz-input-group>
112 112
         <ng-template #suffixTemplate>
113
-          <i nz-icon [nzType]="passwordVisible ? 'eye-invisible' : 'eye'"
114
-            (click)="passwordVisible = !passwordVisible"></i>
113
+          <i nz-icon [nzType]="passwordVisible ? 'eye-invisible' : 'eye'" (click)="passwordVisible = !passwordVisible"></i>
115 114
         </ng-template>
116
-        <!-- <div class="red" style="display: flex;justify-content: center;align-items: center;padding-left: 5px;">弱</div>
117
-        <div style="display: flex;justify-content: center;align-items: center;padding-left: 5px;">中</div>
118
-        <div class="green" style="display: flex;justify-content: center;align-items: center;padding-left: 5px;">强</div> -->
119
-      <!-- </div> -->
115
+        <div class="red" style="display: flex;justify-content: center;align-items: center;padding-left: 5px;" *ngIf="enoughRegFlag">弱</div>
116
+        <div style="display: flex;justify-content: center;align-items: center;padding-left: 5px;" *ngIf="mediumRegFlag">中</div>
117
+        <div class="green" style="display: flex;justify-content: center;align-items: center;padding-left: 5px;" *ngIf="strongRegFlag">强</div>
118
+      </div>
120 119
     </label>
121
-    <!-- <div class="red">强密码需包含大小写字母、数字、特殊字符,长度必须超过8个字符</div> -->
120
+    <div class="red">强密码需包含大小写字母、数字、特殊字符,长度至少9个字符</div>
122 121
     <label>确认新密码:
123 122
       <nz-input-group [nzSuffix]="suffixTemplate">
124
-        <input maxlength="16" minlength="6" [type]="passwordVisible ? 'text' : 'password'" nz-input placeholder="确认新密码"
123
+        <input minlength="9" [type]="passwordVisible ? 'text' : 'password'" nz-input placeholder="确认新密码"
125 124
           [(ngModel)]="upModalData.newPwd2" />
126 125
       </nz-input-group>
127 126
       <ng-template #suffixTemplate>

+ 45 - 1
src/app/views/main/main.component.ts

@@ -145,6 +145,19 @@ export class MainComponent implements OnInit {
145 145
     }
146 146
   }
147 147
 
148
+  // 新密码失去焦点
149
+  enoughRegFlag = true; //弱
150
+  mediumRegFlag = false; //中
151
+  strongRegFlag = false; //强
152
+  blurNewPwd(){
153
+    let enoughReg = /^.{0,6}$/;//密码强度-弱
154
+    let strongReg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\!\@\#\$\%\^\&\*])[a-zA-Z\d\!\@\#\$\%\^\&\*]{9,}$/;//密码强度-强
155
+    this.enoughRegFlag = enoughReg.test(this.upModalData.newPwd);
156
+    this.strongRegFlag = strongReg.test(this.upModalData.newPwd);
157
+    this.mediumRegFlag = !this.enoughRegFlag && !this.strongRegFlag;
158
+    console.log(this.enoughRegFlag,this.mediumRegFlag,this.strongRegFlag);
159
+  }
160
+
148 161
   // 跳转页面
149 162
   menuLabel: string; //当前菜单名称
150 163
   indexFlag = localStorage.getItem("index") === "true" ? true : false; //首页高亮
@@ -310,6 +323,18 @@ export class MainComponent implements OnInit {
310 323
     });
311 324
   }
312 325
 
326
+  //打开修改密码弹窗
327
+  pwdAfterOpen(){
328
+    this.passwordVisible = false;
329
+    this.pwdIsOkLoading = false;
330
+    this.upModalData = {
331
+      userid: "",
332
+      pwdOld: "",
333
+      newPwd: "",
334
+      newPwd2: "",
335
+    };
336
+  }
337
+
313 338
   // 修改密码
314 339
   passwordVisible = false;
315 340
   password?: string;
@@ -323,6 +348,26 @@ export class MainComponent implements OnInit {
323 348
     newPwd2: "",
324 349
   };
325 350
   upPwd(): void {
351
+    if(this.upModalData.newPwd.trim() === ''){
352
+      this.msg.error('请填写原始密码!', {
353
+        nzDuration: 5000,
354
+      });
355
+      return;
356
+    }
357
+    if(!this.strongRegFlag){
358
+      this.msg.error('新密码不符合要求!', {
359
+        nzDuration: 5000,
360
+      });
361
+      return;
362
+    }
363
+    if(this.upModalData.newPwd !== this.upModalData.newPwd2){
364
+      this.msg.error('新密码与确认新密码不一致!', {
365
+        nzDuration: 5000,
366
+      });
367
+      return;
368
+    }
369
+
370
+    this.pwdIsOkLoading = true;
326 371
     let userid = JSON.parse(localStorage.getItem("user")).user.id;
327 372
     this.upModalData.userid = userid;
328 373
     this.mainService.upPwd(this.upModalData).subscribe((data) => {
@@ -345,7 +390,6 @@ export class MainComponent implements OnInit {
345 390
   }
346 391
 
347 392
   pwdHandleOk(): void {
348
-    this.pwdIsOkLoading = true;
349 393
     this.upPwd();
350 394
   }
351 395
 

+ 1 - 1
src/main.ts

@@ -8,7 +8,7 @@ if (environment.production) {
8 8
   enableProdMode();
9 9
   if (window) {
10 10
     window.console.log = function () { };
11
-    console.info('v2.4.20');
11
+    console.info('v2.4.21');
12 12
   }
13 13
 }
14 14
 platformBrowserDynamic().bootstrapModule(AppModule)