配餐项目前端文件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

48 lines
1.4 KiB

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 { ApiService } from "@cdk/services";
import { appName } from "@cdk/app-settings";
@Component({
selector: "app-login",
templateUrl: "./login.component.html",
styleUrls: ["./login.component.less"],
})
export class LoginComponent {
constructor(private msg: NzMessageService, private api: ApiService, private router: Router) {}
public loginForm = new FormGroup({
uid: new FormControl("", [FormValidators.required("请输入账户")]),
pwd: new FormControl("", [FormValidators.required("请输入密码")]),
});
public loading: boolean = false;
appName = appName;
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;
})
)
);
this.msg.success(res.desc);
this.router.navigate(["/"]);
}
}
}