Browse Source

登录注册

warrior 8 months ago
parent
commit
747f8f5b7d

+ 91 - 1
projects/textbook/src/modules/login/reset-password/reset-password.component.html

@@ -1 +1,91 @@
-<p>reset-password works!</p>
+<div class="card">
+  <div class="resgister-title">找回密码</div>
+  <!--手机验证码-->
+  <div class="login-card">
+    <nz-input-group nzCompact>
+      <nz-select [ngModel]="'86'">
+        <nz-option [nzLabel]="'+86'" [nzValue]="'86'"></nz-option>
+      </nz-select>
+      <input
+        type="text"
+        nz-input
+        [(ngModel)]="mobile"
+        [nzStatus]="tbookSer.authMobile(mobile) ? '' : 'error'"
+        style="width: 230px"
+        placeholder="请填写手机号"
+      />
+    </nz-input-group>
+
+    <div class="login-input-box local-code">
+      <input
+        nz-input
+        class="code-input"
+        type="text"
+        [(ngModel)]="localCodeNum"
+        maxlength="4"
+        placeholder="验证码"
+        [nzStatus]="localCodeNum.length == 4 ? '' : 'error'"
+      />
+      <!-- <app-canvas-code
+        [canvas_id]="'canvas_reset'"
+        [(drawCode)]="drawCode"
+        #codelogin
+      ></app-canvas-code> -->
+    </div>
+    <div class="login-input-box">
+      <nz-input-group nzSearch [nzAddOnAfter]="suffixButton">
+        <input
+          type="text"
+          nz-input
+          placeholder="请填写短信验证码"
+          class="msg-code"
+          placeholder="请填写短信验证码"
+          [(ngModel)]="code"
+          maxlength="8"
+          [nzStatus]="code.length >= 4 ? '' : 'error'"
+        />
+      </nz-input-group>
+      <ng-template #suffixButton>
+        <button
+          nz-button
+          nzType="primary"
+          [value]="buttonText"
+          [disabled]="isCountingdown"
+          (click)="startCountdown()"
+        >
+          {{ buttonText }}
+        </button>
+      </ng-template>
+    </div>
+    <div class="login-input-box">
+      <nz-input-group>
+        <input
+          type="password"
+          nz-input
+          placeholder="请填写修改后的密码(至少8位数)"
+          [(ngModel)]="password"
+          [nzStatus]="password.length >= 8 ? '' : 'error'"
+        />
+      </nz-input-group>
+    </div>
+    <div class="login-submit-btn">
+      <button
+        nz-button
+        nzType="primary"
+        nzBlock
+        [nzLoading]="isConfirm"
+        (click)="onRegister()"
+      >
+        确认修改
+      </button>
+    </div>
+  </div>
+  <div class="card-fonter">
+    <a class="fonter-left" [routerLink]="['/user/login']">去登录</a>
+    <div class="fonter-right">
+      还没有账号?<a style="color: #40a9ff" [routerLink]="['/user/register']"
+        >点击注册</a
+      >
+    </div>
+  </div>
+</div>

+ 41 - 0
projects/textbook/src/modules/login/reset-password/reset-password.component.scss

@@ -0,0 +1,41 @@
+.card {
+  width: 320px;
+  margin: 10px auto;
+  box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
+  background-color: white;
+  .resgister-title {
+    text-align: center;
+    margin: 10px auto;
+    font-size: 16px;
+  }
+  .login-card {
+    padding: 0 10px;
+    .login-input-box {
+      display: flex;
+      justify-content: space-between;
+      align-items: center;
+      margin-top: 10px;
+      .phone-input {
+        flex: 1;
+      }
+      .code-input {
+        width: 100px;
+      }
+      .msg-code {
+        width: 150px;
+      }
+    }
+    .login-submit-btn {
+      margin: 50px auto 20px;
+    }
+  }
+  .card-fonter {
+    display: flex;
+    justify-content: space-between;
+    padding: 10px;
+    color: #6d6d6d;
+    .fonter-left {
+      color: #6d6d6d;
+    }
+  }
+}

+ 157 - 2
projects/textbook/src/modules/login/reset-password/reset-password.component.ts

@@ -1,12 +1,167 @@
-import { Component } from '@angular/core';
+import { Component, OnInit, ViewChild } from "@angular/core";
+import { HttpClient } from "@angular/common/http";
+import { NzMessageService } from "ng-zorro-antd/message";
+import { NzModalService } from "ng-zorro-antd/modal";
+import { Router, RouterModule } from "@angular/router";
+import { catchError } from "rxjs/operators";
+import { textbookServer } from "../../../services/textbook";
+import { AuthServr } from "../../../services/auth.service";
+import Parse from "parse";
+import { CommonCompModule } from '../common.modules'
 
 @Component({
   selector: 'app-reset-password',
   standalone: true,
-  imports: [],
+  imports: [CommonCompModule,RouterModule],
   templateUrl: './reset-password.component.html',
   styleUrl: './reset-password.component.scss'
 })
 export class ResetPasswordComponent {
+  @ViewChild("codelogin") codelogin: any; //本地校验码绘画
+  company: string = "";
 
+  mobile: string = "";
+  password: string = "";
+  code: string = ""; //验证码
+  localCodeNum: string = ""; //用户填写验证码
+  drawCode: Array<string> = []; //本地生成验证码(短信验证码登录)
+
+  passwordVisible: boolean = false;
+  buttonText = "获取验证码";
+  isConfirm: boolean = false; //点击注册
+
+  constructor(
+    private http: HttpClient,
+    private msg: NzMessageService,
+    private modal: NzModalService,
+    private router: Router,
+    private loginServr: AuthServr,
+    public tbookSer: textbookServer
+  ) {
+    this.company = this.tbookSer.company;
+    console.log(this.company);
+    console.log(this.router.url);
+  }
+
+  
+  ngOnInit() {}
+
+  codeDown: boolean = false;
+  //添加倒计时开始和结束的判断
+  isCountingdown = false;
+  startCountdown() {
+    let a = /^1[3456789]\d{9}$/;
+    if (!String(this.mobile).match(a)) {
+      this.msg.error("请填写正确手机号");
+      return;
+    }
+    let str = this.drawCode.join("");
+    if (this.localCodeNum.toLowerCase() != str.toLowerCase()) {
+      this.msg.error("验证码不正确");
+      return;
+    }
+    if (this.codeDown) return;
+    this.codeDown = true;
+    let host =
+      (Parse as any).serverURL?.split("parse")?.[0] ||
+      "https://server.fmode.cn/";
+
+    this.http
+      .post(host + "api/apig/message", {
+        company: this.company,
+        mobile: this.mobile,
+      })
+      .pipe(
+        catchError(async (e) => {
+          // 显示报错
+          console.log(e);
+          this.msg.create("error", e.error.mess || "验证码获取失败");
+          this.codeDown = false;
+          return;
+        })
+      )
+      .subscribe((res: any) => {
+        console.log(res);
+        this.codelogin.updateDrawCode();
+        if(res){
+          this.msg.success("发送成功");
+          this.isCountingdown = true;
+          this.time();
+        }
+        this.codeDown = false;
+      });
+  }
+  /* 倒计时 */
+  time() {
+    this.isCountingdown = true;
+    this.buttonText = `${this.loginServr.resetcountdown}秒`;
+    const timer = setInterval(() => {
+      this.loginServr.resetcountdown--;
+      this.buttonText = `${this.loginServr.resetcountdown}秒`;
+      if (this.loginServr.resetcountdown === 0) {
+        clearInterval(timer);
+        this.buttonText = "重新发送";
+        this.isCountingdown = false;
+      }
+    }, 1000);
+  }
+  onRegister() {
+    if (!this.tbookSer.authMobile(this.mobile)) {
+      this.msg.error("请填写正确的手机号");
+      return;
+    }
+    if (!this.code.trim()) {
+      this.msg.error("请填写短信验证码");
+      return;
+    }
+    if (this.password.trim().length < 8) {
+      this.msg.error("请填写正确的密码");
+      return;
+    }
+    if (this.isConfirm) return;
+    this.isConfirm;
+    let host =
+      (Parse as any).serverURL?.split("parse")?.[0] ||
+      "https://server.fmode.cn/";
+
+    this.http
+      .post(host + "/api/auth/reset_password", {
+        company: this.company,
+        mobile: this.mobile,
+        code: this.code,
+        password: this.password,
+      })
+      .pipe(
+        catchError(async (e) => {
+          // 显示报错
+          console.log(e);
+          this.msg.create("error", "修改失败:" + e.error?.mess);
+          this.isConfirm = false;
+          return;
+        })
+      )
+      .subscribe((res: any) => {
+        console.log(res);
+        this.isConfirm = false;
+        if (res) {
+          this.modal.success({
+            nzTitle: "密码重置成功",
+            nzContent: "密码已重置,直接登录?",
+            nzCancelText: "取消",
+            nzOnOk: () => {
+              this.loginServr
+                .login(this.mobile, this.password, this.company)
+                .then((data) => {
+                  console.log(data);
+                  this.router.navigate(["developer/app-list"]);
+                })
+                .catch((err) => {
+                  console.log(err);
+                  this.msg.error(err.message);
+                });
+            },
+          });
+        }
+      });
+  }
 }