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.
91 lines
2.3 KiB
91 lines
2.3 KiB
import {Component, OnInit} from '@angular/core';
|
|
import {AbstractControl, FormBuilder, FormGroup, ValidatorFn, Validators} from '@angular/forms';
|
|
import {Commons} from '../../commons';
|
|
import {RegisterService} from './register.service';
|
|
import {AppService} from '../../app.service';
|
|
import {Result} from '../../interface/Result';
|
|
import {Router} from '@angular/router';
|
|
import {MessageInterface, MessageUtil} from '../../message/message.service';
|
|
|
|
@Component({
|
|
selector: 'app-register',
|
|
templateUrl: './register.component.html',
|
|
styleUrls: ['./register.component.scss']
|
|
})
|
|
|
|
|
|
// 注册模块
|
|
export class RegisterComponent extends Commons implements OnInit, MessageInterface {
|
|
|
|
// 注册表单
|
|
registerForm = this.fb.group({
|
|
// 管理员名
|
|
managerName: this.fb.control('', [Validators.required]),
|
|
// 密码
|
|
password: this.fb.control('', [Validators.required]),
|
|
// 确认密码
|
|
confirmPassword: this.fb.control('', [this.checkPwd()]),
|
|
// 手机号
|
|
mobile: this.fb.control('', [this.checkMobile()]),
|
|
// 邮箱
|
|
email: this.fb.control('', [Validators.required]),
|
|
// 邮箱类型
|
|
emailType: this.fb.control('', [Validators.required])
|
|
});
|
|
|
|
|
|
/**
|
|
* 邮箱类型
|
|
*/
|
|
emailType$ = this.appService.getEmailType();
|
|
|
|
constructor(
|
|
private fb: FormBuilder,
|
|
private registerService: RegisterService,
|
|
private appService: AppService,
|
|
private router: Router,
|
|
private messageUtil: MessageUtil
|
|
) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* 检查手机
|
|
*/
|
|
checkMobile(): ValidatorFn {
|
|
return (control: AbstractControl): {} => {
|
|
if (/^1[3456789]\d{9}$/.test(control.value)) {
|
|
return null;
|
|
} else {
|
|
return {required: control.value === null || control.value.length === 0, mobile: true};
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 注册
|
|
*/
|
|
register() {
|
|
this.registerService.register(this.registerForm.value).subscribe(r => {
|
|
if (r.result === Result.OK) {
|
|
this.messageUtil.info(this.prefix(r.message));
|
|
this.router.navigateByUrl('/login');
|
|
} else {
|
|
this.messageUtil.danger(this.prefix(r.message));
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
|
|
form(): FormGroup {
|
|
return this.registerForm;
|
|
}
|
|
|
|
prefix(key: string): string {
|
|
return 'server.register.' + key;
|
|
}
|
|
}
|
|
|
|
|