|
|
|
import { Component } from "@angular/core";
|
|
|
|
import { FormControl, FormGroup } from "@angular/forms";
|
|
|
|
import { Router } from "@angular/router";
|
|
|
|
import { NzMessageService } from "ng-zorro-antd/message";
|
|
|
|
import { FormValidators } from "projects/cdk/src/public-api";
|
|
|
|
import { Utils } from "projects/cdk/src/utils";
|
|
|
|
import { finalize, lastValueFrom } from "rxjs";
|
|
|
|
import { MD5 } from "crypto-js";
|
|
|
|
import { ClientApiService } from "../../services";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-login",
|
|
|
|
templateUrl: "./login.component.html",
|
|
|
|
styleUrls: ["./login.component.less"],
|
|
|
|
})
|
|
|
|
export class LoginComponent {
|
|
|
|
constructor(private msg: NzMessageService, private api: ClientApiService, private router: Router) {}
|
|
|
|
|
|
|
|
public loginForm = new FormGroup({
|
|
|
|
uid: new FormControl("", [FormValidators.required("请输入账户")]),
|
|
|
|
pwd: new FormControl("", [FormValidators.required("请输入密码")]),
|
|
|
|
});
|
|
|
|
|
|
|
|
public loading: boolean = false;
|
|
|
|
|
|
|
|
ngOnInit(): void {}
|
|
|
|
|
|
|
|
async onLogin() {
|
|
|
|
if (Utils.validateFormGroup(this.loginForm)) {
|
|
|
|
const { value } = this.loginForm;
|
|
|
|
const pwd = value.pwd as string;
|
|
|
|
value["pwd"] = MD5(pwd).toString().slice(-16).toUpperCase();
|
|
|
|
this.loading = true;
|
|
|
|
const res = await lastValueFrom(
|
|
|
|
this.api.login(value).pipe(
|
|
|
|
finalize(() => {
|
|
|
|
this.loading = false;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
localStorage.setItem(this.api.accountKey, JSON.stringify(res.body));
|
|
|
|
this.msg.success(res.desc);
|
|
|
|
this.router.navigate(["/"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|