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.
66 lines
2.2 KiB
66 lines
2.2 KiB
import { Component, OnInit } from '@angular/core';
|
|
import {LocalStorageService} from '../../../services/local-storage.service';
|
|
import {LoginService} from '../../../services/login.service';
|
|
import {ADMIN_INFO_OBJECT, INIT_FLAG, ROLE_TYPE, TOKEN} from '../../../services/local-storage.namespace';
|
|
import {UntypedFormBuilder, UntypedFormGroup, Validators} from '@angular/forms';
|
|
import {Router} from '@angular/router';
|
|
import {HttpClient} from '@angular/common/http';
|
|
import {NzModalService} from 'ng-zorro-antd';
|
|
|
|
@Component({
|
|
selector: 'app-admin-login',
|
|
templateUrl: './admin-login.component.html',
|
|
styleUrls: ['./admin-login.component.scss']
|
|
})
|
|
export class AdminLoginComponent implements OnInit {
|
|
|
|
loginForm: UntypedFormGroup; // 登录表单
|
|
|
|
constructor(private store: LocalStorageService, // 数据请求
|
|
private router: Router, // 路由
|
|
private form: UntypedFormBuilder, // 表单校验
|
|
private http: HttpClient, // http请求
|
|
private loginService: LoginService,
|
|
private modal: NzModalService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.loginForm = this.form.group({
|
|
loginName: [null, [Validators.required]],
|
|
password: [null, [Validators.required]],
|
|
type: [0],
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 登录
|
|
*/
|
|
submitLogin() {
|
|
// tslint:disable-next-line:forin
|
|
for (const i in this.loginForm.controls) {
|
|
this.loginForm.controls[i].markAsDirty();
|
|
this.loginForm.controls[i].updateValueAndValidity();
|
|
}
|
|
if (this.loginForm.status == null || this.loginForm.status !== 'VALID') {
|
|
this.modal.warning({
|
|
nzTitle: '提示',
|
|
nzContent: '请填写用户和密码',
|
|
});
|
|
return;
|
|
}
|
|
this.loginService.userLogin(this.loginForm.value, data => {
|
|
if (data['return_code'] === '000000') {
|
|
this.store.set(ADMIN_INFO_OBJECT, data['return_data']['object']);
|
|
this.store.set(TOKEN, data['return_data']['uniqueCode']);
|
|
this.store.set(INIT_FLAG, true);
|
|
this.store.set(ROLE_TYPE, data['return_data']['type']);
|
|
this.router.navigateByUrl('/admin/index').then();
|
|
} else {
|
|
this.modal.warning({
|
|
nzTitle: '提示',
|
|
nzContent: data['return_msg']
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|