import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MessageService } from 'pz-unit'; import { AuthService } from 'app/core/auth.service'; @Component({ selector: 'app-login', templateUrl: './login.component.html', styleUrls: ['./login.component.scss'] }) export class LoginComponent implements OnInit { public validateForm: FormGroup; public clickTimes = 0; public constructor(private fb: FormBuilder, private aut: AuthService, private msg: MessageService ) { } public ngOnInit(): void { this.validateForm = this.fb.group({ username: [null, [Validators.required]], password: [null, [Validators.required]], remember: [true] }); } public verify(bool: boolean) { if (bool) { this.submitForm(); } else { this.msg.error('验证失败!'); } } public submitForm(): void { for (const i in this.validateForm.controls) { if (this.validateForm.controls.hasOwnProperty(i)) { this.validateForm.controls[i].markAsDirty(); this.validateForm.controls[i].updateValueAndValidity(); } } if (this.validateForm.valid) { this.aut.login(this.validateForm.value); } } public config() { this.msg.configShow(); } public click3Time() { this.clickTimes += 1; if ( this.clickTimes >= 3) { this.config(); } setTimeout(() => { this.clickTimes = 0; }, 500); } }