shishuangxi

修复验证码bug

... ... @@ -3,7 +3,6 @@ import { LoginInputComponent } from './LoginInputComponent'
import { LoginViewModel } from './LoginViewModel'
import router from '@ohos.router'
import promptAction from '@ohos.promptAction'
import { Params } from '../../../../../../../commons/wdRouter/oh_modules/wdBean/Index'
import { WDRouterRule, WDRouterPage } from 'wdRouter';
import { SettingPasswordParams } from './SettingPasswordLayout'
import { Router } from '@ohos.arkui.UIContext'
... ... @@ -26,6 +25,7 @@ struct ForgetPasswordPage {
@State @Watch('onCodeSend') isCodeSend: boolean = false //验证码点击发送事件
pageType:number = (router.getParams() as Record<string, number>)['pageType']; //0、登录->忘记密码 1、设置->重置密码 2、设置->更换手机号页面1 3、设置->更换手机号页面2
@State pageTitle:string = '找回密码';
@State codeStateSuccess:boolean=false
onCodeSend() {
if (this.isCodeSend) {
this.sendVerifyCode()
... ... @@ -47,7 +47,8 @@ struct ForgetPasswordPage {
codeContent: $codeContent,
isSubmit: $isSubmit,
isCodeSend: $isCodeSend,
pageType:this.pageType
pageType:this.pageType,
codeStateSuccess:$codeStateSuccess
})
Row() {
Text("确认")
... ... @@ -99,16 +100,26 @@ struct ForgetPasswordPage {
if(this.pageType == 1){
this.loginViewModel.sendVerifyCodeByToken().then(()=>{
promptAction.showToast({ message: "验证码已发送成功" })
promptAction.showToast({ message: "已发送" })
this.codeStateSuccess=true
this.isCodeSend=false
}).catch((message: string)=>{
promptAction.showToast({ message: message })
this.codeStateSuccess=false
this.isCodeSend=false
})
return
}
this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => {
promptAction.showToast({ message: "验证码已发送成功" })
promptAction.showToast({ message: "已发送" })
this.codeStateSuccess=true
this.isCodeSend=false
Logger.debug(TAG, "sendVerifyCode: " + verifyCode)
}).catch((message: string)=>{
promptAction.showToast({ message: message })
this.codeStateSuccess=false
this.isCodeSend=false
})
}
... ... @@ -146,7 +157,7 @@ struct ForgetPasswordPage {
codeContent:this.codeContent,
pageType:this.pageType
}
WDRouterRule.jumpWithPage(WDRouterPage.settingPasswordPage, params)
WDRouterRule.jumpWithReplacePage(WDRouterPage.settingPasswordPage, params)
promptAction.showToast({message:"校验成功,准备跳转设置页面"})
Logger.debug(TAG,"校验成功")
... ...
import { SpConstants } from 'wdConstant/Index'
import { Logger, SPHelper } from 'wdKit'
import { DateTimeUtils, Logger, SPHelper } from 'wdKit'
@Component
export struct LoginInputComponent {
... ... @@ -11,6 +11,8 @@ export struct LoginInputComponent {
@Link isSubmit: boolean //是否可以提交
isFirst:boolean=true//是否第一次获取验证码
pageType?:number; //0、登录->忘记密码 1、设置->重置密码 2、设置->更换手机号页面1 3、设置->更换手机号页面2
lastTime: number = 0
@Link @Watch('startCount') codeStateSuccess: boolean //验证码获取成功与否回调 成功显示倒计时
build() {
Column() {
this.addCodeLayout()
... ... @@ -81,28 +83,24 @@ export struct LoginInputComponent {
this.isSubmit = (this.phoneContent.length >= 11 && this.codeContent.length >= 4)
})
Text(this.isCodeSend ? this.timeCount + "s" : this.isFirst?"发送验证码":'重新发送')
Text(this.codeStateSuccess ? this.timeCount + "s" : this.isFirst?"发送验证码":'重新获取')
.fontColor(this.codeBtnState?'#ED2800':'#80ED2800')
.width(110)
.fontSize(14)
.fontWeight( FontWeight.Bold)
.height(48)
.textAlign(TextAlign.Center)
.enabled(this.codeStateSuccess?false:true)
.onClick(() => {
if (this.phoneContent.length < 11) {
return
}
this.isCodeSend = true
this.isFirst=false
let time = setInterval(() => {
Logger.debug("倒计时:" + this.timeCount)
this.timeCount--
if (this.timeCount < 1) {
this.isCodeSend = false
this.timeCount = 60
clearInterval(time)
let currentTime = DateTimeUtils.getTimeStamp()
if (currentTime - this.lastTime < 500) {
return
}
}, 1000)
this.lastTime = currentTime;
this.isCodeSend = true
})
... ... @@ -122,4 +120,17 @@ export struct LoginInputComponent {
securityNum = phoneNum.replace(needSecurityString,'****')
return securityNum;
}
startCount() {
this.isFirst = false
let time = setInterval(() => {
Logger.debug("倒计时:" + this.timeCount)
this.timeCount--
if (this.timeCount < 1) {
this.codeStateSuccess = false
this.timeCount = 60
clearInterval(time)
}
}, 1000)
}
}
\ No newline at end of file
... ...
... ... @@ -46,6 +46,7 @@ struct LoginPage {
@State passwordSwitch: boolean = true //密码显示
// @State isPasswordSubmit: boolean = false //账户密码状态 是否出发登录
lastTime: number = 0
@State codeStateSuccess:boolean=false
dialogController: CustomDialogController = new CustomDialogController({
builder: CustomProtocolDialog({
... ... @@ -93,7 +94,8 @@ struct LoginPage {
phoneContent: $phoneContent,
codeContent: $codeContent,
isSubmit: $isSubmit,
isCodeSend: $isCodeSend
isCodeSend: $isCodeSend,
codeStateSuccess:$codeStateSuccess
})
} else {
this.addPassword()
... ... @@ -314,9 +316,14 @@ struct LoginPage {
//发送验证码
sendVerifyCode() {
this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => {
promptAction.showToast({ message: "验证码已发送成功" })
promptAction.showToast({ message: "已发送" })
Logger.debug(TAG, "sendVerifyCode: " + verifyCode)
this.codeStateSuccess=true
this.isCodeSend=false
}).catch((message:string)=>{
promptAction.showToast({ message: message })
this.codeStateSuccess=false
this.isCodeSend=false
Logger.debug(TAG, "sendVerifyCode: " + message)
})
}
... ...