import {Component, OnInit} from '@angular/core'; import {PublicService} from '../../../PublicService'; import {LoadingController, NavController} from '@ionic/angular'; import {Constants} from '../../../Constant'; import {ActivatedRoute} from '@angular/router'; @Component({ selector: 'app-change-gesture', templateUrl: './change-gesture.page.html', styleUrls: ['./change-gesture.page.scss'], }) export class ChangeGesturePage implements OnInit { private firstPwd; pr private title = '请输入手势密码'; private isFromLogin = false; private user = this.publicService.getCurrentUser(); private userInfo = this.user.userInfo; private userConfig = this.user.userConfig; private tel = this.user.userInfo.tel; private interval = null; private verificationCodeBtnText = '获取验证码'; private waitingTime = 59; private isWaiting = false; private nextStep = false; private telCode = ''; constructor(private readonly navController: NavController, private readonly loadingCtrl: LoadingController, private readonly route: ActivatedRoute, private readonly publicService: PublicService) { } ngOnInit() { const params = this.route.snapshot.queryParams; if (params.from){ this.isFromLogin = true; this.title = '重置手势密码'; } } getTelCode(){ if (this.isWaiting) { return; } this.publicService.getTelCode(this.tel, this.userInfo.realName).then( res => { if (res.code === Constants.SUCCESS){ this.interval = setInterval(() => { if (this.waitingTime === 0) { this.verificationCodeBtnText = '获取验证码'; this.waitingTime = 59; this.isWaiting = false; return clearInterval(this.interval); } this.verificationCodeBtnText = `(${this.waitingTime}s)重新获取`; this.waitingTime -= 1; }, 1000); this.isWaiting = true; }else{ this.publicService.presentToast(res.msg); } }); } toNextStep(){ this.publicService.checkPhoneCode(this.telCode, this.tel, this.userInfo.realName).then(res => { if (res.code === Constants.SUCCESS){ this.nextStep = true; }else{ this.publicService.presentToast(res.msg); } }); } async receiveVal(pwd) { if (!this.firstPwd) { this.firstPwd = pwd; this.title = '请再次输入手势密码'; } else { if (pwd !== this.firstPwd) { this.publicService.presentToast('手势密码不一致'); } else { const load = await this.publicService.showLoading(this.loadingCtrl, '手势密码设置中...'); this.userConfig.gesturePsw = pwd; this.publicService.updateUserConfig(this.userConfig).then(res => { if (res.code === Constants.SUCCESS) { this.publicService.presentToast('设置手势密码成功'); this.publicService.setCurrentUser(this.user); this.navController.navigateRoot('/tabs/mine'); } else { this.publicService.presentToast(res.msg); } load.dismiss(); }, err => { this.publicService.checkNetworkToast(err); load.dismiss(); }); } } } back(){ this.navController.back(); } }