yangchenggong1_wd

desc:抽离 更换手机号为单独page

@@ -68,6 +68,7 @@ export class WDRouterPage { @@ -68,6 +68,7 @@ export class WDRouterPage {
68 static loginPage = new WDRouterPage("wdLogin", "ets/pages/login/LoginPage"); 68 static loginPage = new WDRouterPage("wdLogin", "ets/pages/login/LoginPage");
69 static oneKeyLoginPage = new WDRouterPage("wdLogin", "ets/pages/login/OneKeyLoginPage"); 69 static oneKeyLoginPage = new WDRouterPage("wdLogin", "ets/pages/login/OneKeyLoginPage");
70 static forgetPasswordPage = new WDRouterPage("wdLogin", "ets/pages/login/ForgetPasswordPage"); 70 static forgetPasswordPage = new WDRouterPage("wdLogin", "ets/pages/login/ForgetPasswordPage");
  71 + static changeBindPhonePage = new WDRouterPage("wdLogin", "ets/pages/login/ChangeBindPhonePage");
71 static modifyPasswordPage = new WDRouterPage("wdLogin", "ets/pages/login/ModifyPasswordPage"); 72 static modifyPasswordPage = new WDRouterPage("wdLogin", "ets/pages/login/ModifyPasswordPage");
72 //我的 预约 73 //我的 预约
73 static appointmentListPage = new WDRouterPage("wdComponent", "ets/components/page/AppointmentListPage"); 74 static appointmentListPage = new WDRouterPage("wdComponent", "ets/components/page/AppointmentListPage");
@@ -175,9 +175,7 @@ export struct AccountAndSecurityLayout { @@ -175,9 +175,7 @@ export struct AccountAndSecurityLayout {
175 .onClick(() => { 175 .onClick(() => {
176 console.log(index + "") 176 console.log(index + "")
177 if (index == 0){ 177 if (index == 0){
178 - trackButtonClick("accountManagementPageChangePhoneNumber")  
179 - let pageType = {'pageType': 2} as Record<string, number>;  
180 - WDRouterRule.jumpWithPage(WDRouterPage.forgetPasswordPage, pageType) 178 + WDRouterRule.jumpWithPage(WDRouterPage.changeBindPhonePage)
181 }else if (index == 1) { 179 }else if (index == 1) {
182 trackButtonClick("accountManagementPageAccountManagementPassword") 180 trackButtonClick("accountManagementPageAccountManagementPassword")
183 if (this.ifSetPassword) { 181 if (this.ifSetPassword) {
  1 +import { SpConstants } from 'wdConstant/Index'
  2 +import { CustomToast, Logger, NetworkUtil, ToastUtils, SPHelper, EmitterEventId,
  3 + DateTimeUtils } from 'wdKit/Index'
  4 +import { LoginViewModel } from './LoginViewModel'
  5 +import { router } from '@kit.ArkUI'
  6 +import { emitter } from '@kit.BasicServicesKit'
  7 +
  8 +const TAG = 'ChangeBindPhonePage'
  9 +/*更换手机号页面*/
  10 +@Entry
  11 +@Component
  12 +struct ChangeBindPhonePage {
  13 + @State phoneContent: string = ''
  14 + @State codeContent: string = ''
  15 + @State isSubmit: boolean = false //是否可以提交 默认不可以
  16 + loginViewModel: LoginViewModel = new LoginViewModel()
  17 + @State @Watch('onCodeSend') isCodeSend: boolean = false //验证码点击发送事件
  18 + @State pageTitle:string = '更换手机号';
  19 + @State @Watch('startCount') codeStateSuccess:boolean=false
  20 + @State codeBtnState: boolean = false
  21 + @State timeCount: number = 60
  22 + isFirst:boolean=true//是否第一次获取验证码
  23 + lastTime: number = 0
  24 +
  25 +
  26 + onCodeSend() {
  27 + if (this.isCodeSend) {
  28 + this.sendVerifyCode()
  29 + }
  30 + }
  31 +
  32 + @State toastText:string = ""
  33 + dialogToast: CustomDialogController = new CustomDialogController({
  34 + builder: CustomToast({
  35 + msg: this.toastText,
  36 + }),
  37 + autoCancel: false,
  38 + alignment: DialogAlignment.Center,
  39 + customStyle: true,
  40 + maskColor:"#00000000"
  41 + })
  42 +
  43 +
  44 +
  45 + build() {
  46 + Column() {
  47 + Image($r('app.media.login_back_icon')).width(24).height(24).margin({ left: 15, top: 10 }).onClick(() => {
  48 + router.back()
  49 + })
  50 +
  51 + Text(this.pageTitle).fontSize(22).fontColor('#333333').fontWeight(FontWeight.Bold).margin({ left: 25, top: 112 })
  52 +
  53 + Column(){
  54 + TextInput({text: this.phoneContent, placeholder: "请输入手机号" })
  55 + .fontSize(16)
  56 + .height(48)
  57 + .placeholderColor("#CCCCCC")
  58 + .maxLength(11)
  59 + .margin({ top: 36 })
  60 + .backgroundColor("#F5F5F5")
  61 + .borderRadius(4)
  62 + .type(InputType.Number)
  63 + .onChange((content) => {
  64 + this.phoneContent = content
  65 + this.isSubmit = (this.phoneContent.length >= 11 && this.codeContent.length >= 4)
  66 +
  67 + if (content.length >= 11 ) {
  68 + this.codeBtnState = true
  69 + } else {
  70 + this.codeBtnState = false
  71 + }
  72 + })
  73 +
  74 +
  75 + Row() {
  76 + TextInput({ text: this.codeContent,placeholder: "验证码" })
  77 + .placeholderColor("#CCCCCC")
  78 + .layoutWeight(1)
  79 + .fontSize(16)
  80 + .height(48)
  81 + .type(InputType.Number)
  82 + .fontColor("#222222")
  83 + .backgroundColor("#00000000")
  84 + .borderRadius({ topLeft: 4, bottomLeft: 4 })
  85 + .onChange((value) => {
  86 + this.codeContent = value
  87 + this.isSubmit = (this.phoneContent.length >= 11 && this.codeContent.length >= 4)
  88 + })
  89 +
  90 + Text(this.codeStateSuccess ? this.timeCount + "s" : this.isFirst?"发送验证码":'重新获取')
  91 + .fontColor(this.codeBtnState?'#ED2800':'#80ED2800')
  92 + .width(110)
  93 + .fontSize(14)
  94 + .fontWeight( FontWeight.Bold)
  95 + .height(48)
  96 + .textAlign(TextAlign.Center)
  97 + .enabled(this.codeStateSuccess?false:true)
  98 + .onClick(() => {
  99 + if (this.phoneContent.length < 11) {
  100 + return
  101 + }
  102 +
  103 + let currentTime = DateTimeUtils.getTimeStamp()
  104 + if (currentTime - this.lastTime < 500) {
  105 + return
  106 + }
  107 + this.lastTime = currentTime;
  108 + this.isCodeSend = true
  109 +
  110 + })
  111 +
  112 +
  113 + }.margin({ top: 12 })
  114 + .height(48)
  115 + .alignItems(VerticalAlign.Center)
  116 + .justifyContent(FlexAlign.Start)
  117 + .backgroundImage($r('app.media.code_login_bg'))
  118 + .backgroundImageSize({width:'100%',height:48})
  119 + }.width('100%')
  120 + .padding({ left: 25, right: 25 })
  121 +
  122 +
  123 + Row() {
  124 + Text("确认")
  125 + .layoutWeight(1)
  126 + .fontColor(this.isSubmit ?"#FFFFFFFF":"#66FFFFFF")
  127 + .borderRadius(4)
  128 + .fontSize(18)
  129 + .textAlign(TextAlign.Center)
  130 + .fontWeight(FontWeight.Medium)
  131 + .margin({ top: 26 })
  132 + .height(44)
  133 + .backgroundColor(this.isSubmit ?"#ED2800":"#99ED2800")
  134 + .enabled(this.isSubmit ? true : false)
  135 + .onClick(() => {
  136 + this.changeBindPhone()
  137 + })
  138 + }.width('100%')
  139 + .padding({ left: 25, right: 25 })
  140 +
  141 + }.width('100%').height('100%').alignItems(HorizontalAlign.Start)
  142 + }
  143 +
  144 + //发送验证码
  145 + sendVerifyCode() {
  146 + if (this.isEmpty(this.phoneContent)) {
  147 + return
  148 + }
  149 +
  150 + this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => {
  151 + this.showToastTip("已发送")
  152 + this.codeStateSuccess=true
  153 + this.isCodeSend=false
  154 + Logger.debug(TAG, "sendVerifyCode: " + verifyCode)
  155 + }).catch((message: string)=>{
  156 + let netStatus = NetworkUtil.isNetConnected()
  157 + if (netStatus) {
  158 + this.showToastTip(message)
  159 + } else {
  160 + this.showToastTip("验证码获取失败,请重新尝试")
  161 + }
  162 + this.codeStateSuccess=false
  163 + this.isCodeSend=false
  164 + })
  165 + }
  166 +
  167 + isEmpty(obj: undefined|null|string): boolean {
  168 + return (obj == undefined || obj == null || obj == '');
  169 + }
  170 +
  171 + changeBindPhone(){
  172 + if (!this.isSubmit) {
  173 + return
  174 + }
  175 + if (this.isEmpty(this.phoneContent)) {
  176 + return
  177 + }
  178 + if (this.isEmpty(this.codeContent)) {
  179 + return
  180 + }
  181 + this.loginViewModel.changeBindPhone(this.phoneContent,this.codeContent).then(()=>{
  182 + ToastUtils.shortToast('绑定成功')
  183 + this.querySecurity()
  184 + }).catch((message: string) => {
  185 + if (message != '') {
  186 + ToastUtils.shortToast(message)
  187 + }
  188 + })
  189 + }
  190 +
  191 + querySecurity(){
  192 + this.loginViewModel.querySecurity().then(()=>{
  193 + SPHelper.default.save(SpConstants.USER_PHONE,this.phoneContent)
  194 + this.sendEmitEvent()
  195 + router.back()
  196 + }).catch(()=>{
  197 +
  198 + })
  199 + }
  200 +
  201 + sendEmitEvent(){
  202 + // 定义一个eventId为1的事件,事件优先级为Low
  203 + let event: emitter.InnerEvent = {
  204 + eventId: EmitterEventId.PHONE_CHANGE_SUCCESS,
  205 + priority: emitter.EventPriority.LOW
  206 + };
  207 +
  208 + let eventData: emitter.EventData = {
  209 + data: {
  210 + content: this.phoneContent,
  211 + }
  212 + };
  213 +
  214 + // 发送eventId为1的事件,事件内容为eventData
  215 + emitter.emit(event, eventData);
  216 + }
  217 +
  218 + showToastTip(msg:string){
  219 + this.toastText = msg
  220 + this.dialogToast.open()
  221 + }
  222 +
  223 + startCount() {
  224 + this.isFirst = false
  225 + let time = setInterval(() => {
  226 + Logger.debug("倒计时:" + this.timeCount)
  227 + this.timeCount--
  228 + if (this.timeCount < 1) {
  229 + this.codeStateSuccess = false
  230 + this.timeCount = 60
  231 + clearInterval(time)
  232 + }
  233 + }, 1000)
  234 + }
  235 +}
@@ -22,7 +22,7 @@ struct ForgetPasswordPage { @@ -22,7 +22,7 @@ struct ForgetPasswordPage {
22 @State isSubmit: boolean = false //是否可以提交 默认不可以 22 @State isSubmit: boolean = false //是否可以提交 默认不可以
23 loginViewModel: LoginViewModel = new LoginViewModel() 23 loginViewModel: LoginViewModel = new LoginViewModel()
24 @State @Watch('onCodeSend') isCodeSend: boolean = false //验证码点击发送事件 24 @State @Watch('onCodeSend') isCodeSend: boolean = false //验证码点击发送事件
25 - pageType:number = (router.getParams() as Record<string, number>)['pageType']; //0、登录->忘记密码 1、设置->重置密码 2、设置->更换手机号页面1 3、设置->更换手机号页面2 25 + pageType:number = (router.getParams() as Record<string, number>)['pageType']; //0、登录->忘记密码 1、设置->重置密码 3、设置->更换手机号页面2(不知道是啥)
26 phone:string = (router.getParams() as Record<string, number>)['phone'] + ""; //登录 密码登录 填写手机号 点击忘记密码 带过来手机号 26 phone:string = (router.getParams() as Record<string, number>)['phone'] + ""; //登录 密码登录 填写手机号 点击忘记密码 带过来手机号
27 @State pageTitle:string = '找回密码'; 27 @State pageTitle:string = '找回密码';
28 @State codeStateSuccess:boolean=false 28 @State codeStateSuccess:boolean=false
@@ -51,7 +51,6 @@ struct ForgetPasswordPage { @@ -51,7 +51,6 @@ struct ForgetPasswordPage {
51 router.back() 51 router.back()
52 }) 52 })
53 53
54 -  
55 Text(this.pageTitle).fontSize(22).fontColor('#333333').fontWeight(FontWeight.Bold).margin({ left: 25, top: 112 }) 54 Text(this.pageTitle).fontSize(22).fontColor('#333333').fontWeight(FontWeight.Bold).margin({ left: 25, top: 112 })
56 LoginInputComponent({ 55 LoginInputComponent({
57 phoneContent: $phoneContent, 56 phoneContent: $phoneContent,
@@ -74,11 +73,7 @@ struct ForgetPasswordPage { @@ -74,11 +73,7 @@ struct ForgetPasswordPage {
74 .backgroundColor(this.isSubmit ?"#ED2800":"#99ED2800") 73 .backgroundColor(this.isSubmit ?"#ED2800":"#99ED2800")
75 .enabled(this.isSubmit ? true : false) 74 .enabled(this.isSubmit ? true : false)
76 .onClick(() => { 75 .onClick(() => {
77 - if(this.pageType==2){  
78 - this.changeBindPhone()  
79 - }else {  
80 - this.checkVerifyCode()  
81 - } 76 + this.checkVerifyCode()
82 }) 77 })
83 }.padding({ left: 25, right: 25 }).width('100%') 78 }.padding({ left: 25, right: 25 }).width('100%')
84 79
@@ -98,8 +93,6 @@ struct ForgetPasswordPage { @@ -98,8 +93,6 @@ struct ForgetPasswordPage {
98 } 93 }
99 }else if (this.pageType == 1){ 94 }else if (this.pageType == 1){
100 this.pageTitle = '验证当前手机号' 95 this.pageTitle = '验证当前手机号'
101 - }else if (this.pageType == 2){  
102 - this.pageTitle = '更换手机号'  
103 } 96 }
104 if (this.isCodeSend) { 97 if (this.isCodeSend) {
105 this.sendVerifyCode() 98 this.sendVerifyCode()
@@ -10,7 +10,7 @@ export struct LoginInputComponent { @@ -10,7 +10,7 @@ export struct LoginInputComponent {
10 @Link isCodeSend: boolean //验证码控件是否点击 默认没有 发送接口 10 @Link isCodeSend: boolean //验证码控件是否点击 默认没有 发送接口
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、设置->重置密码 3、设置->更换手机号页面2
14 lastTime: number = 0 14 lastTime: number = 0
15 @Link @Watch('startCount') codeStateSuccess: boolean //验证码获取成功与否回调 成功显示倒计时 15 @Link @Watch('startCount') codeStateSuccess: boolean //验证码获取成功与否回调 成功显示倒计时
16 @Watch('onCheckChange') @Prop protocolState: boolean = false //协议勾选状态 16 @Watch('onCheckChange') @Prop protocolState: boolean = false //协议勾选状态
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 "pages/login/SettingPasswordLayout", 8 "pages/login/SettingPasswordLayout",
9 "pages/guide/GuidePages", 9 "pages/guide/GuidePages",
10 "pages/login/OneKeyLoginPage", 10 "pages/login/OneKeyLoginPage",
11 - "pages/login/ModifyPasswordPage" 11 + "pages/login/ModifyPasswordPage",
  12 + "pages/login/ChangeBindPhonePage"
12 ] 13 ]
13 } 14 }