yangchenggong1_wd

fix:bug[16825] 手机验证码登录,输入手机号,验证码,点击2次切换按钮,预期手机号和验证码还在输入框,实际会清空手机号和验证码

@@ -125,6 +125,37 @@ export class StringUtils { @@ -125,6 +125,37 @@ export class StringUtils {
125 static isScore(text: string): boolean { 125 static isScore(text: string): boolean {
126 return StringUtils.SCORE_REG_EXP.test(text); 126 return StringUtils.SCORE_REG_EXP.test(text);
127 } 127 }
  128 +
  129 + //手机号校验
  130 + static photoMatch(phone:string) : boolean {
  131 + /**
  132 + * 移动号段正则表达式
  133 + */
  134 + let CM_NUM = "^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
  135 + /**
  136 + * 联通号段正则表达式
  137 + */
  138 + let CU_NUM = "^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
  139 + /**
  140 + * 电信号段正则表达式
  141 + */
  142 + let CT_NUM = "^((133)|(153)|(177)|(18[0,1,9]))\\d{8}$";
  143 + /**
  144 + * 官网正则
  145 + */
  146 + let GW_NUM = "^1(3|4|5|6|7|8|9)\\d{9}$";
  147 +
  148 + let CM_NUM_reg : RegExp = new RegExp(CM_NUM);
  149 + let CU_NUM_reg : RegExp = new RegExp(CU_NUM);
  150 + let CT_NUM_reg : RegExp = new RegExp(CT_NUM);
  151 + let GW_NUM_reg : RegExp = new RegExp(GW_NUM);
  152 +
  153 + if (CM_NUM_reg.test(phone) || CU_NUM_reg.test(phone) || CT_NUM_reg.test(phone) || GW_NUM_reg.test(phone)) {
  154 + return true;
  155 + }
  156 + console.log('请输入正确的手机号')
  157 + return false;
  158 + }
128 } 159 }
129 160
130 // export default new StringUtils(); 161 // export default new StringUtils();
@@ -22,7 +22,6 @@ export struct LoginInputComponent { @@ -22,7 +22,6 @@ export struct LoginInputComponent {
22 async aboutToAppear(){ 22 async aboutToAppear(){
23 if (this.pageType == 1) { 23 if (this.pageType == 1) {
24 this.phoneContent = await SPHelper.default.get(SpConstants.USER_PHONE,"") as string; 24 this.phoneContent = await SPHelper.default.get(SpConstants.USER_PHONE,"") as string;
25 - Logger.debug("ddd")  
26 } 25 }
27 } 26 }
28 @Builder 27 @Builder
@@ -48,7 +47,7 @@ export struct LoginInputComponent { @@ -48,7 +47,7 @@ export struct LoginInputComponent {
48 } 47 }
49 }) 48 })
50 }else{ 49 }else{
51 - TextInput({ placeholder: "请输入手机号" }) 50 + TextInput({text: this.phoneContent, placeholder: "请输入手机号" })
52 .fontSize(16) 51 .fontSize(16)
53 .height(48) 52 .height(48)
54 .placeholderColor("#CCCCCC") 53 .placeholderColor("#CCCCCC")
@@ -70,7 +69,7 @@ export struct LoginInputComponent { @@ -70,7 +69,7 @@ export struct LoginInputComponent {
70 69
71 70
72 Row() { 71 Row() {
73 - TextInput({ placeholder: "验证码" }) 72 + TextInput({ text: this.codeContent,placeholder: "验证码" })
74 .placeholderColor("#CCCCCC") 73 .placeholderColor("#CCCCCC")
75 .layoutWeight(1) 74 .layoutWeight(1)
76 .fontSize(16) 75 .fontSize(16)
1 -import { Logger, EmitterEventId, EmitterUtils, DateTimeUtils,CustomToast } from 'wdKit' 1 +import { Logger, EmitterEventId, EmitterUtils, DateTimeUtils,CustomToast, StringUtils } from 'wdKit'
2 import { CustomProtocolDialog } from './CustomProtocolDialog' 2 import { CustomProtocolDialog } from './CustomProtocolDialog'
3 import router from '@ohos.router' 3 import router from '@ohos.router'
4 import { LoginViewModel } from './LoginViewModel' 4 import { LoginViewModel } from './LoginViewModel'
@@ -38,8 +38,8 @@ struct LoginPage { @@ -38,8 +38,8 @@ struct LoginPage {
38 @State phoneContent: string = "" //手机号 38 @State phoneContent: string = "" //手机号
39 @State codeContent: string = "" //验证码 39 @State codeContent: string = "" //验证码
40 @State protocolState: boolean = false //协议勾选状态 40 @State protocolState: boolean = false //协议勾选状态
41 - accountContent = '' //账号  
42 - passwordContent = '' 41 + @State accountContent: string = '' //账号
  42 + @State passwordContent: string = ''
43 @State isSubmit: boolean = false 43 @State isSubmit: boolean = false
44 @State checkCodePage: boolean = true //判断是否是验证码页面 默认验证码登录 44 @State checkCodePage: boolean = true //判断是否是验证码页面 默认验证码登录
45 @State passwordSwitch: boolean = true //密码显示 45 @State passwordSwitch: boolean = true //密码显示
@@ -213,7 +213,7 @@ struct LoginPage { @@ -213,7 +213,7 @@ struct LoginPage {
213 @Builder 213 @Builder
214 addPassword() { 214 addPassword() {
215 Column() { 215 Column() {
216 - TextInput({ placeholder: "请输入账号", controller: this.phoneController }) 216 + TextInput({ text: this.accountContent,placeholder: "请输入账号", controller: this.phoneController })
217 .fontSize(16) 217 .fontSize(16)
218 .placeholderColor("#CCCCCC") 218 .placeholderColor("#CCCCCC")
219 .height(48) 219 .height(48)
@@ -312,8 +312,8 @@ struct LoginPage { @@ -312,8 +312,8 @@ struct LoginPage {
312 .size({ width: 20, height: 20 }) 312 .size({ width: 20, height: 20 })
313 }.backgroundImage($r('app.media.login_other_right'), ImageRepeat.NoRepeat) 313 }.backgroundImage($r('app.media.login_other_right'), ImageRepeat.NoRepeat)
314 .otherStyle().onClick(() => { 314 .otherStyle().onClick(() => {
  315 + this.updateAccount()
315 this.checkCodePage = !this.checkCodePage; 316 this.checkCodePage = !this.checkCodePage;
316 - this.passwordContent = ''  
317 this.passwordSwitch = true 317 this.passwordSwitch = true
318 this.isSubmit = false 318 this.isSubmit = false
319 }) 319 })
@@ -326,6 +326,20 @@ struct LoginPage { @@ -326,6 +326,20 @@ struct LoginPage {
326 }.width('100%').margin({ bottom: 40 }) 326 }.width('100%').margin({ bottom: 40 })
327 } 327 }
328 328
  329 + updateAccount(){
  330 + if(this.checkCodePage){
  331 + //验证码切换 密码
  332 + if(StringUtils.photoMatch(this.phoneContent)){
  333 + this.accountContent = this.phoneContent
  334 + }
  335 + }else{
  336 + //密码切换 验证码
  337 + if(StringUtils.photoMatch(this.accountContent)){
  338 + this.phoneContent = this.accountContent
  339 + }
  340 + }
  341 + }
  342 +
329 //发送验证码 343 //发送验证码
330 sendVerifyCode() { 344 sendVerifyCode() {
331 this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => { 345 this.loginViewModel.sendVerifyCode(this.phoneContent).then((verifyCode) => {