|
@@ -1,98 +1,147 @@
|
|
|
-import { Component } from '@angular/core';
|
|
|
+import { Component, ViewChild } from '@angular/core';
|
|
|
import { ReactiveFormsModule } from '@angular/forms';
|
|
|
+import { HttpClient } from "@angular/common/http";
|
|
|
import { Router } from '@angular/router';
|
|
|
+import { catchError } from "rxjs/operators";
|
|
|
import {
|
|
|
FormControl,
|
|
|
FormGroup,
|
|
|
NonNullableFormBuilder,
|
|
|
Validators,
|
|
|
+ ValidatorFn,
|
|
|
+ AbstractControl,
|
|
|
} from '@angular/forms';
|
|
|
import { CommonCompModule } from '../common.modules';
|
|
|
import { textbookServer } from '../../../services/textbook';
|
|
|
import { AuthServr } from '../../../services/auth.service';
|
|
|
+import { CaptchaComponent } from '../../../app/captcha/captcha.component';
|
|
|
import Parse from "parse";
|
|
|
-
|
|
|
+import { NzMessageService } from 'ng-zorro-antd/message';
|
|
|
@Component({
|
|
|
selector: 'app-login',
|
|
|
standalone: true,
|
|
|
- imports: [ReactiveFormsModule, CommonCompModule],
|
|
|
+ imports: [ReactiveFormsModule, CommonCompModule,CaptchaComponent],
|
|
|
templateUrl: './login.component.html',
|
|
|
styleUrl: './login.component.scss',
|
|
|
})
|
|
|
export class LoginComponent {
|
|
|
+ @ViewChild("codelogin") codelogin: any;
|
|
|
+ @ViewChild("codeloginSign") codeloginSign: any;
|
|
|
+
|
|
|
+ code:string = '' //本地生成验证码
|
|
|
+
|
|
|
+ active:number = 0
|
|
|
validateForm: FormGroup<{
|
|
|
userName: FormControl<string>;
|
|
|
password: FormControl<string>;
|
|
|
code: FormControl<string>;
|
|
|
- remember: FormControl<boolean>;
|
|
|
+ checked: FormControl<boolean>;
|
|
|
}> = this.fb.group({
|
|
|
userName: ['', [Validators.required]],
|
|
|
password: ['', [Validators.required]],
|
|
|
code: ['', [Validators.required]],
|
|
|
- remember: [true],
|
|
|
+ checked: [false]
|
|
|
+ });
|
|
|
+ //校验手机号
|
|
|
+ confirmationValidator: ValidatorFn = (control: AbstractControl): { [s: string]: boolean } => {
|
|
|
+ let a = /^1[3456789]\d{9}$/;
|
|
|
+ if (!control.value || !String(control.value).match(a)) {
|
|
|
+ return { required: true };
|
|
|
+ }
|
|
|
+ return {};
|
|
|
+ };
|
|
|
+
|
|
|
+ validateFormPhone: FormGroup<{
|
|
|
+ phoneNumber: FormControl<string>;
|
|
|
+ code: FormControl<string>;
|
|
|
+ checkCode:FormControl<string>;
|
|
|
+ checked: FormControl<boolean>;
|
|
|
+ }> = this.fb.group({
|
|
|
+ phoneNumber: ['', [Validators.required, this.confirmationValidator]],
|
|
|
+ code: ['', [Validators.required]],
|
|
|
+ checkCode: ['', [Validators.required]],
|
|
|
+ checked: [false]
|
|
|
});
|
|
|
- selector: Array<any> = [
|
|
|
- {
|
|
|
- name: '国家级管理员',
|
|
|
- type: 1,
|
|
|
- route: '/nav-admin',
|
|
|
- },
|
|
|
- {
|
|
|
- name: '省级教育行政部门',
|
|
|
- type: 2,
|
|
|
- route: '/nav-province-submit',
|
|
|
- },
|
|
|
- {
|
|
|
- name: '流程管理员登录',
|
|
|
- type: 3,
|
|
|
- route: '/nav-province-contact',
|
|
|
- },
|
|
|
- {
|
|
|
- name: '省属高校联系人',
|
|
|
- type: 4,
|
|
|
- route: '/nav-province-school-contact',
|
|
|
- },
|
|
|
- {
|
|
|
- name: '教材评审组成员',
|
|
|
- type: 5,
|
|
|
- route: '/nav-review',
|
|
|
- },
|
|
|
- {
|
|
|
- name: '作者/教师/主编',
|
|
|
- type: 6,
|
|
|
- route:'/nav-author/manage/space'
|
|
|
- },
|
|
|
- ];
|
|
|
- currentProfile: any = this.selector[0];
|
|
|
+
|
|
|
constructor(
|
|
|
public tbookSer: textbookServer,
|
|
|
private fb: NonNullableFormBuilder,
|
|
|
public router: Router,
|
|
|
- private authServr: AuthServr
|
|
|
+ private authServr: AuthServr,
|
|
|
+ private message: NzMessageService,
|
|
|
+ private http: HttpClient,
|
|
|
) {
|
|
|
Parse?.User?.logOut()
|
|
|
}
|
|
|
- submitForm(): void {
|
|
|
- if (this.validateForm.valid) {
|
|
|
- let {userName, password, code } = this.validateForm.value
|
|
|
- console.log(userName, password,);
|
|
|
- localStorage.setItem('profile', JSON.stringify(this.currentProfile));
|
|
|
- this.tbookSer.profile = this.currentProfile;
|
|
|
- this.authServr.login(userName, password, this.tbookSer.company).then(() => {
|
|
|
- this.router.navigate([this.currentProfile.route]);
|
|
|
- });
|
|
|
- } else {
|
|
|
- Object.values(this.validateForm.controls).forEach((control) => {
|
|
|
- if (control.invalid) {
|
|
|
- control.markAsDirty();
|
|
|
- control.updateValueAndValidity({ onlySelf: true });
|
|
|
+
|
|
|
+
|
|
|
+ onChangeCode(e:any){
|
|
|
+ let { code } = e
|
|
|
+ this.code = code
|
|
|
+ }
|
|
|
+
|
|
|
+ submitForm(type:string): void {
|
|
|
+ console.log(this.code);
|
|
|
+ if(type == 'account'){//登录
|
|
|
+ if (this.validateForm.valid) {
|
|
|
+ let {userName, password, code, checked } = this.validateForm.value
|
|
|
+ console.log(userName, password, code);
|
|
|
+ if(this.code.toLowerCase() != code?.toLowerCase()){
|
|
|
+ this.message.warning('验证码错误')
|
|
|
+ return
|
|
|
+ }else if(!checked){
|
|
|
+ this.message.warning('请勾选隐私协议与服务条款')
|
|
|
+ return
|
|
|
}
|
|
|
- });
|
|
|
+ this.authServr.login(userName, password, this.tbookSer.company).catch(data=>{
|
|
|
+ console.log(data);
|
|
|
+ })
|
|
|
+ this.codelogin.updateDrawCode();
|
|
|
+ } else {
|
|
|
+ this.message.warning('填写信息不正确')
|
|
|
+ Object.values(this.validateForm.controls).forEach((control) => {
|
|
|
+ if (control.invalid) {
|
|
|
+ control.markAsDirty();
|
|
|
+ control.updateValueAndValidity({ onlySelf: true });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }else{//手机号登录/注册
|
|
|
+ console.log(this.validateFormPhone.value);
|
|
|
+ if (this.validateFormPhone.valid) {
|
|
|
+ this.codeloginSign.updateDrawCode();
|
|
|
+ let {phoneNumber, code } = this.validateFormPhone.value
|
|
|
+ this.router.navigate(['/user/account_info']);
|
|
|
+
|
|
|
+ if(this.code.toLowerCase() != code?.toLowerCase()){
|
|
|
+ this.message.warning('验证码错误')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(phoneNumber, code);
|
|
|
+
|
|
|
+ // this.authServr.login(userName, password, this.tbookSer.company).then(() => {
|
|
|
+ // this.router.navigate(['/user/account_info']);
|
|
|
+ // });
|
|
|
+ } else {
|
|
|
+ this.message.warning('填写信息不正确')
|
|
|
+ Object.values(this.validateFormPhone.controls).forEach((control) => {
|
|
|
+ if (control.invalid) {
|
|
|
+ control.markAsDirty();
|
|
|
+ control.updateValueAndValidity({ onlySelf: true });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- onChange(e: string) {
|
|
|
- this.currentProfile = e;
|
|
|
+ onChange(e: any) {
|
|
|
+ console.log(e);
|
|
|
+ this.active = e.index
|
|
|
+ this.validateForm.reset()
|
|
|
+ this.validateFormPhone.reset()
|
|
|
+ this.codelogin.updateDrawCode();
|
|
|
+ this.codeloginSign.updateDrawCode();
|
|
|
}
|
|
|
|
|
|
goUrl(path: string) {
|
|
@@ -103,4 +152,68 @@ export class LoginComponent {
|
|
|
},
|
|
|
]);
|
|
|
}
|
|
|
+
|
|
|
+ buttonText = "获取验证码";
|
|
|
+ //添加倒计时开始和结束的判断
|
|
|
+ isCountingdown = false;
|
|
|
+ /* 获取验证码 */
|
|
|
+ codeDown: boolean = false;
|
|
|
+ startCountdown() {
|
|
|
+ let a = /^1[3456789]\d{9}$/;
|
|
|
+ let { phoneNumber, code } = this.validateFormPhone.value
|
|
|
+ console.log(phoneNumber);
|
|
|
+ if (!String(phoneNumber).match(a)) {
|
|
|
+ this.message.error("请填写正确手机号");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (code?.toLowerCase() != this.code.toLowerCase()) {
|
|
|
+ this.message.error("验证码不正确");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.codeDown || this.isCountingdown) return;
|
|
|
+ this.codeDown = true;
|
|
|
+ let host =
|
|
|
+ (Parse as any).serverURL?.split("parse")?.[0] ||
|
|
|
+ "https://server.fmode.cn/";
|
|
|
+
|
|
|
+ this.http
|
|
|
+ .post(host + "api/apig/message", {
|
|
|
+ company: this.tbookSer.company,
|
|
|
+ mobile: phoneNumber,
|
|
|
+ })
|
|
|
+ .pipe(
|
|
|
+ catchError(async (e) => {
|
|
|
+ // 显示报错
|
|
|
+ console.log(e);
|
|
|
+ this.message.create("error", e.error.mess || "验证码获取失败");
|
|
|
+ this.codeDown = false;
|
|
|
+ this.isCountingdown = false;
|
|
|
+ return;
|
|
|
+ })
|
|
|
+ )
|
|
|
+ .subscribe((res: any) => {
|
|
|
+ console.log(res);
|
|
|
+ if(res){
|
|
|
+ this.message.success("发送成功");
|
|
|
+ this.isCountingdown = true;
|
|
|
+ this.time();
|
|
|
+ }
|
|
|
+ this.codeloginSign.updateDrawCode();
|
|
|
+ this.codeDown = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /* 倒计时 */
|
|
|
+ time() {
|
|
|
+ this.isCountingdown = true;
|
|
|
+ this.buttonText = `${this.authServr.countdown}秒`;
|
|
|
+ const timer = setInterval(() => {
|
|
|
+ this.authServr.countdown--;
|
|
|
+ this.buttonText = `${this.authServr.countdown}秒`;
|
|
|
+ if (this.authServr.countdown === 0) {
|
|
|
+ clearInterval(timer);
|
|
|
+ this.buttonText = "重新发送";
|
|
|
+ this.isCountingdown = false;
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
}
|