Showing
3 changed files
with
48 additions
and
19 deletions
| @@ -3,7 +3,6 @@ import { LoginInputComponent } from './LoginInputComponent' | @@ -3,7 +3,6 @@ import { LoginInputComponent } from './LoginInputComponent' | ||
| 3 | import { LoginViewModel } from './LoginViewModel' | 3 | import { LoginViewModel } from './LoginViewModel' |
| 4 | import router from '@ohos.router' | 4 | import router from '@ohos.router' |
| 5 | import promptAction from '@ohos.promptAction' | 5 | import promptAction from '@ohos.promptAction' |
| 6 | -import { Params } from '../../../../../../../commons/wdRouter/oh_modules/wdBean/Index' | ||
| 7 | import { WDRouterRule, WDRouterPage } from 'wdRouter'; | 6 | import { WDRouterRule, WDRouterPage } from 'wdRouter'; |
| 8 | import { SettingPasswordParams } from './SettingPasswordLayout' | 7 | import { SettingPasswordParams } from './SettingPasswordLayout' |
| 9 | import { Router } from '@ohos.arkui.UIContext' | 8 | import { Router } from '@ohos.arkui.UIContext' |
| @@ -26,6 +25,7 @@ struct ForgetPasswordPage { | @@ -26,6 +25,7 @@ struct ForgetPasswordPage { | ||
| 26 | @State @Watch('onCodeSend') isCodeSend: boolean = false //验证码点击发送事件 | 25 | @State @Watch('onCodeSend') isCodeSend: boolean = false //验证码点击发送事件 |
| 27 | pageType:number = (router.getParams() as Record<string, number>)['pageType']; //0、登录->忘记密码 1、设置->重置密码 2、设置->更换手机号页面1 3、设置->更换手机号页面2 | 26 | pageType:number = (router.getParams() as Record<string, number>)['pageType']; //0、登录->忘记密码 1、设置->重置密码 2、设置->更换手机号页面1 3、设置->更换手机号页面2 |
| 28 | @State pageTitle:string = '找回密码'; | 27 | @State pageTitle:string = '找回密码'; |
| 28 | + @State codeStateSuccess:boolean=false | ||
| 29 | onCodeSend() { | 29 | onCodeSend() { |
| 30 | if (this.isCodeSend) { | 30 | if (this.isCodeSend) { |
| 31 | this.sendVerifyCode() | 31 | this.sendVerifyCode() |
| @@ -47,7 +47,8 @@ struct ForgetPasswordPage { | @@ -47,7 +47,8 @@ struct ForgetPasswordPage { | ||
| 47 | codeContent: $codeContent, | 47 | codeContent: $codeContent, |
| 48 | isSubmit: $isSubmit, | 48 | isSubmit: $isSubmit, |
| 49 | isCodeSend: $isCodeSend, | 49 | isCodeSend: $isCodeSend, |
| 50 | - pageType:this.pageType | 50 | + pageType:this.pageType, |
| 51 | + codeStateSuccess:$codeStateSuccess | ||
| 51 | }) | 52 | }) |
| 52 | Row() { | 53 | Row() { |
| 53 | Text("确认") | 54 | Text("确认") |
| @@ -99,16 +100,26 @@ struct ForgetPasswordPage { | @@ -99,16 +100,26 @@ struct ForgetPasswordPage { | ||
| 99 | 100 | ||
| 100 | if(this.pageType == 1){ | 101 | if(this.pageType == 1){ |
| 101 | this.loginViewModel.sendVerifyCodeByToken().then(()=>{ | 102 | this.loginViewModel.sendVerifyCodeByToken().then(()=>{ |
| 102 | - promptAction.showToast({ message: "验证码已发送成功" }) | 103 | + promptAction.showToast({ message: "已发送" }) |
| 104 | + this.codeStateSuccess=true | ||
| 105 | + this.isCodeSend=false | ||
| 103 | }).catch((message: string)=>{ | 106 | }).catch((message: string)=>{ |
| 104 | promptAction.showToast({ message: message }) | 107 | promptAction.showToast({ message: message }) |
| 108 | + this.codeStateSuccess=false | ||
| 109 | + this.isCodeSend=false | ||
| 105 | }) | 110 | }) |
| 106 | return | 111 | return |
| 107 | } | 112 | } |
| 108 | 113 | ||
| 109 | this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => { | 114 | this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => { |
| 110 | - promptAction.showToast({ message: "验证码已发送成功" }) | 115 | + promptAction.showToast({ message: "已发送" }) |
| 116 | + this.codeStateSuccess=true | ||
| 117 | + this.isCodeSend=false | ||
| 111 | Logger.debug(TAG, "sendVerifyCode: " + verifyCode) | 118 | Logger.debug(TAG, "sendVerifyCode: " + verifyCode) |
| 119 | + }).catch((message: string)=>{ | ||
| 120 | + promptAction.showToast({ message: message }) | ||
| 121 | + this.codeStateSuccess=false | ||
| 122 | + this.isCodeSend=false | ||
| 112 | }) | 123 | }) |
| 113 | 124 | ||
| 114 | } | 125 | } |
| @@ -146,7 +157,7 @@ struct ForgetPasswordPage { | @@ -146,7 +157,7 @@ struct ForgetPasswordPage { | ||
| 146 | codeContent:this.codeContent, | 157 | codeContent:this.codeContent, |
| 147 | pageType:this.pageType | 158 | pageType:this.pageType |
| 148 | } | 159 | } |
| 149 | - WDRouterRule.jumpWithPage(WDRouterPage.settingPasswordPage, params) | 160 | + WDRouterRule.jumpWithReplacePage(WDRouterPage.settingPasswordPage, params) |
| 150 | 161 | ||
| 151 | promptAction.showToast({message:"校验成功,准备跳转设置页面"}) | 162 | promptAction.showToast({message:"校验成功,准备跳转设置页面"}) |
| 152 | Logger.debug(TAG,"校验成功") | 163 | Logger.debug(TAG,"校验成功") |
| 1 | import { SpConstants } from 'wdConstant/Index' | 1 | import { SpConstants } from 'wdConstant/Index' |
| 2 | -import { Logger, SPHelper } from 'wdKit' | 2 | +import { DateTimeUtils, Logger, SPHelper } from 'wdKit' |
| 3 | 3 | ||
| 4 | @Component | 4 | @Component |
| 5 | export struct LoginInputComponent { | 5 | export struct LoginInputComponent { |
| @@ -11,6 +11,8 @@ export struct LoginInputComponent { | @@ -11,6 +11,8 @@ export struct LoginInputComponent { | ||
| 11 | @Link isSubmit: boolean //是否可以提交 | 11 | @Link isSubmit: boolean //是否可以提交 |
| 12 | isFirst:boolean=true//是否第一次获取验证码 | 12 | isFirst:boolean=true//是否第一次获取验证码 |
| 13 | pageType?:number; //0、登录->忘记密码 1、设置->重置密码 2、设置->更换手机号页面1 3、设置->更换手机号页面2 | 13 | pageType?:number; //0、登录->忘记密码 1、设置->重置密码 2、设置->更换手机号页面1 3、设置->更换手机号页面2 |
| 14 | + lastTime: number = 0 | ||
| 15 | + @Link @Watch('startCount') codeStateSuccess: boolean //验证码获取成功与否回调 成功显示倒计时 | ||
| 14 | build() { | 16 | build() { |
| 15 | Column() { | 17 | Column() { |
| 16 | this.addCodeLayout() | 18 | this.addCodeLayout() |
| @@ -81,28 +83,24 @@ export struct LoginInputComponent { | @@ -81,28 +83,24 @@ export struct LoginInputComponent { | ||
| 81 | this.isSubmit = (this.phoneContent.length >= 11 && this.codeContent.length >= 4) | 83 | this.isSubmit = (this.phoneContent.length >= 11 && this.codeContent.length >= 4) |
| 82 | }) | 84 | }) |
| 83 | 85 | ||
| 84 | - Text(this.isCodeSend ? this.timeCount + "s" : this.isFirst?"发送验证码":'重新发送') | 86 | + Text(this.codeStateSuccess ? this.timeCount + "s" : this.isFirst?"发送验证码":'重新获取') |
| 85 | .fontColor(this.codeBtnState?'#ED2800':'#80ED2800') | 87 | .fontColor(this.codeBtnState?'#ED2800':'#80ED2800') |
| 86 | .width(110) | 88 | .width(110) |
| 87 | .fontSize(14) | 89 | .fontSize(14) |
| 88 | .fontWeight( FontWeight.Bold) | 90 | .fontWeight( FontWeight.Bold) |
| 89 | .height(48) | 91 | .height(48) |
| 90 | .textAlign(TextAlign.Center) | 92 | .textAlign(TextAlign.Center) |
| 93 | + .enabled(this.codeStateSuccess?false:true) | ||
| 91 | .onClick(() => { | 94 | .onClick(() => { |
| 92 | if (this.phoneContent.length < 11) { | 95 | if (this.phoneContent.length < 11) { |
| 93 | return | 96 | return |
| 94 | } | 97 | } |
| 98 | + let currentTime = DateTimeUtils.getTimeStamp() | ||
| 99 | + if (currentTime - this.lastTime < 500) { | ||
| 100 | + return | ||
| 101 | + } | ||
| 102 | + this.lastTime = currentTime; | ||
| 95 | this.isCodeSend = true | 103 | this.isCodeSend = true |
| 96 | - this.isFirst=false | ||
| 97 | - let time = setInterval(() => { | ||
| 98 | - Logger.debug("倒计时:" + this.timeCount) | ||
| 99 | - this.timeCount-- | ||
| 100 | - if (this.timeCount < 1) { | ||
| 101 | - this.isCodeSend = false | ||
| 102 | - this.timeCount = 60 | ||
| 103 | - clearInterval(time) | ||
| 104 | - } | ||
| 105 | - }, 1000) | ||
| 106 | 104 | ||
| 107 | }) | 105 | }) |
| 108 | 106 | ||
| @@ -122,4 +120,17 @@ export struct LoginInputComponent { | @@ -122,4 +120,17 @@ export struct LoginInputComponent { | ||
| 122 | securityNum = phoneNum.replace(needSecurityString,'****') | 120 | securityNum = phoneNum.replace(needSecurityString,'****') |
| 123 | return securityNum; | 121 | return securityNum; |
| 124 | } | 122 | } |
| 123 | + | ||
| 124 | + startCount() { | ||
| 125 | + this.isFirst = false | ||
| 126 | + let time = setInterval(() => { | ||
| 127 | + Logger.debug("倒计时:" + this.timeCount) | ||
| 128 | + this.timeCount-- | ||
| 129 | + if (this.timeCount < 1) { | ||
| 130 | + this.codeStateSuccess = false | ||
| 131 | + this.timeCount = 60 | ||
| 132 | + clearInterval(time) | ||
| 133 | + } | ||
| 134 | + }, 1000) | ||
| 135 | + } | ||
| 125 | } | 136 | } |
| @@ -46,6 +46,7 @@ struct LoginPage { | @@ -46,6 +46,7 @@ struct LoginPage { | ||
| 46 | @State passwordSwitch: boolean = true //密码显示 | 46 | @State passwordSwitch: boolean = true //密码显示 |
| 47 | // @State isPasswordSubmit: boolean = false //账户密码状态 是否出发登录 | 47 | // @State isPasswordSubmit: boolean = false //账户密码状态 是否出发登录 |
| 48 | lastTime: number = 0 | 48 | lastTime: number = 0 |
| 49 | + @State codeStateSuccess:boolean=false | ||
| 49 | 50 | ||
| 50 | dialogController: CustomDialogController = new CustomDialogController({ | 51 | dialogController: CustomDialogController = new CustomDialogController({ |
| 51 | builder: CustomProtocolDialog({ | 52 | builder: CustomProtocolDialog({ |
| @@ -93,7 +94,8 @@ struct LoginPage { | @@ -93,7 +94,8 @@ struct LoginPage { | ||
| 93 | phoneContent: $phoneContent, | 94 | phoneContent: $phoneContent, |
| 94 | codeContent: $codeContent, | 95 | codeContent: $codeContent, |
| 95 | isSubmit: $isSubmit, | 96 | isSubmit: $isSubmit, |
| 96 | - isCodeSend: $isCodeSend | 97 | + isCodeSend: $isCodeSend, |
| 98 | + codeStateSuccess:$codeStateSuccess | ||
| 97 | }) | 99 | }) |
| 98 | } else { | 100 | } else { |
| 99 | this.addPassword() | 101 | this.addPassword() |
| @@ -314,9 +316,14 @@ struct LoginPage { | @@ -314,9 +316,14 @@ struct LoginPage { | ||
| 314 | //发送验证码 | 316 | //发送验证码 |
| 315 | sendVerifyCode() { | 317 | sendVerifyCode() { |
| 316 | this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => { | 318 | this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => { |
| 317 | - promptAction.showToast({ message: "验证码已发送成功" }) | 319 | + promptAction.showToast({ message: "已发送" }) |
| 318 | Logger.debug(TAG, "sendVerifyCode: " + verifyCode) | 320 | Logger.debug(TAG, "sendVerifyCode: " + verifyCode) |
| 321 | + this.codeStateSuccess=true | ||
| 322 | + this.isCodeSend=false | ||
| 319 | }).catch((message:string)=>{ | 323 | }).catch((message:string)=>{ |
| 324 | + promptAction.showToast({ message: message }) | ||
| 325 | + this.codeStateSuccess=false | ||
| 326 | + this.isCodeSend=false | ||
| 320 | Logger.debug(TAG, "sendVerifyCode: " + message) | 327 | Logger.debug(TAG, "sendVerifyCode: " + message) |
| 321 | }) | 328 | }) |
| 322 | } | 329 | } |
-
Please register or login to post a comment