配餐项目前端文件
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.

49 lines
1.4 KiB

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