|
|
|
@ -17,6 +17,7 @@ import {
|
|
|
|
|
SlideRef
|
|
|
|
|
} from "go-captcha-angular";
|
|
|
|
|
import {CaptchaModalComponent} from "../component/captcha-modal/captcha-modal.component";
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-login',
|
|
|
|
|
templateUrl: './login.page.html',
|
|
|
|
@ -24,7 +25,7 @@ import {CaptchaModalComponent} from "../component/captcha-modal/captcha-modal.co
|
|
|
|
|
standalone: false,
|
|
|
|
|
})
|
|
|
|
|
export class LoginPage implements OnInit, OnDestroy,AfterViewInit {
|
|
|
|
|
loginForm: FormGroup ;
|
|
|
|
|
loginForm: FormGroup;
|
|
|
|
|
loginType: 'sms' | 'password' = 'sms';
|
|
|
|
|
canSendSms = true;
|
|
|
|
|
smsButtonText = '发送验证码';
|
|
|
|
@ -32,6 +33,7 @@ export class LoginPage implements OnInit, OnDestroy,AfterViewInit {
|
|
|
|
|
private countdown = 60;
|
|
|
|
|
private timer: any;
|
|
|
|
|
private verifyToken: string | null = null;
|
|
|
|
|
private returnUrl: string | null = null;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private fb: FormBuilder,
|
|
|
|
@ -47,6 +49,12 @@ export class LoginPage implements OnInit, OnDestroy,AfterViewInit {
|
|
|
|
|
password: [''],
|
|
|
|
|
smsCode: ['']
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 获取返回路径
|
|
|
|
|
const navigation = this.router.getCurrentNavigation();
|
|
|
|
|
if (navigation?.extras?.state?.['returnUrl']) {
|
|
|
|
|
this.returnUrl = navigation.extras.state['returnUrl'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
@ -59,8 +67,6 @@ export class LoginPage implements OnInit, OnDestroy,AfterViewInit {
|
|
|
|
|
this.stopCountdown() ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private createForm() {
|
|
|
|
|
// 根据登录类型动态设置验证器
|
|
|
|
|
this.loginForm.get('password')?.setValidators(
|
|
|
|
@ -73,7 +79,6 @@ export class LoginPage implements OnInit, OnDestroy,AfterViewInit {
|
|
|
|
|
|
|
|
|
|
// 显示滑动验证码
|
|
|
|
|
showSlideVerify(type: 'sms' | 'password') {
|
|
|
|
|
|
|
|
|
|
const phone = this.loginForm.get('phone')?.value;
|
|
|
|
|
|
|
|
|
|
if (!phone || !this.loginForm.get('phone')?.valid) {
|
|
|
|
@ -103,7 +108,6 @@ export class LoginPage implements OnInit, OnDestroy,AfterViewInit {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -155,8 +159,13 @@ export class LoginPage implements OnInit, OnDestroy,AfterViewInit {
|
|
|
|
|
loginRequest.subscribe({
|
|
|
|
|
next: (response) => {
|
|
|
|
|
this.showToast('登录成功');
|
|
|
|
|
localStorage.setItem("token",response)
|
|
|
|
|
this.navCtrl.back()
|
|
|
|
|
localStorage.setItem("token",response);
|
|
|
|
|
// 如果有返回路径,则导航到该路径
|
|
|
|
|
if (this.returnUrl) {
|
|
|
|
|
this.router.navigateByUrl(this.returnUrl);
|
|
|
|
|
} else {
|
|
|
|
|
this.navCtrl.back();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: (error) => {
|
|
|
|
|
let errorMessage = '登录失败,请重试';
|
|
|
|
|