// 201811190001 @auth:hz @Description: 删除关于表单检验的代码 import { environment } from '@env/environment'; import { Component, OnInit, OnDestroy, Inject, ChangeDetectionStrategy, ViewChild, forwardRef } from '@angular/core'; import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms'; import { AuthService, ValidateService } from '@services'; import { User, Auth } from '@domain'; import { LoginTypeComponent } from './login-type.component'; // ViewChild // import { FormUtil } from 'app/util/form.util'; // import * as fromRoot from 'app/reducers'; import { AccessBuilder } from 'app/passport/util/access'; import { Store } from '@ngrx/store'; import * as authAction from 'app/actions/auth.action'; import * as fromRoot from 'app/reducers'; @Component({ selector: 'passport-login', templateUrl: './login.component.html', styleUrls: ['./login.component.less'], providers: [], changeDetection: ChangeDetectionStrategy.OnPush, }) /** * -执行 * 1.InitializeFormBuild(表单控件构建), * 2.submit(数据校验及提交) * 2.1.this.loginTypeComponent.setParentForm(); 设置LoginType{userName: ,mobile:} * // 2.2.formUpdate 数据校验 FormUtil.validateForm is no need; just isValid * 2.3 store$.dispatch(access) * * -被调用 * 无 * * -Input: * loginType,verifyInfo * -Output: * //{loginType: ,verify: } * {userName: ,mobile: , password: , SMS: } */ export class UserLoginComponent implements OnInit { @ViewChild(forwardRef(() => LoginTypeComponent)) loginTypeComponent: LoginTypeComponent; form: FormGroup; error = ''; loading = false; constructor( private fb: FormBuilder, private store$: Store, private authSrv: AuthService, // TODO ValidateService // private valiSrv: ValidateService, ) { } // noinspection JSUnusedGlobalSymbols ngOnInit() { this.InitialFormBuild(); } InitialFormBuild() { this.form = this.fb.group({ loginType: [], captcha: [null, Validators.required], password: [null, Validators.required], remember: [true], }); } public get loginType() { return this.form.controls.loginType; } public get password() { return this.form.controls.password; } public get captcha() { return this.form.controls.captcha; } // noinspection JSUnusedGlobalSymbols /** * 检查及检验登录信息,发出登陆请求 */ submit() { // 对this.form.loginType 值设置=> 获取登陆方式 this.loginTypeComponent.setParentForm(); // html不会触发 // 更新及存在性检查 // 建立AccessJSON=> 建立登陆参数信息对象 const json = this.CreateAccessJSON(); // TODO: 发起登陆请求 this.store$.dispatch(new authAction.Login(json)); // const data = this.authSrv.getData(json); // if (!environment.production ) console.log(data); // if (!environment.production ) console.log('submit ok'); // just a check } CreateAccessJSON() { const ps = {password: this.password.value}; return new AccessBuilder().setAccess(this.loginType.value, ps).toJSON(); } }