diff --git a/entry/src/main/ets/common/Constants.ets b/entry/src/main/ets/common/Constants.ets index eb2ae53dc96cfadb72034a37d404d419380cde38..7449e9dcd9cb0f38b33dfa76afa87d11f8aa612a 100644 --- a/entry/src/main/ets/common/Constants.ets +++ b/entry/src/main/ets/common/Constants.ets @@ -260,9 +260,15 @@ export default class Constants { * Destination. */ public static readonly NAV_DESTINATION_DATA: NavDestinationItem[] = [ + { + name: 'TextBoxShowCursor', detail: $r('app.string.word') + }, { name: 'BottomWithBar', detail: $r('app.string.bottom') }, + { + name: 'BackgroundColorChange', detail: $r('app.string.background') + }, { name: 'VerificationCode', detail: $r('app.string.select_verification_code') }, diff --git a/entry/src/main/ets/pages/BackgroundColorChange.ets b/entry/src/main/ets/pages/BackgroundColorChange.ets index dd844c291fbac0b12a47ed3b05abd0304cb711c5..b202cc30dd02a0bf028ca3273e2b5ecfc1e8c48b 100644 --- a/entry/src/main/ets/pages/BackgroundColorChange.ets +++ b/entry/src/main/ets/pages/BackgroundColorChange.ets @@ -41,8 +41,7 @@ struct BackgroundColorChange { @State codeText: string = ''; @Consume('pathInfos') pathInfos: NavPathStack; @StorageProp('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; - @StorageProp('topRectHeight') - topRectHeight: number = 0; + @StorageProp('topRectHeight') topRectHeight: number = 0; private inputController: inputMethod.InputMethodController = inputMethod.getController(); private arrArea: number[] = [0.0, 1, 0]; private verifyCodeLength: number = 6; @@ -116,6 +115,14 @@ struct BackgroundColorChange { } } + private unicodeToDigit(unicodeValue: number): number { + // Check for half-width digits('0'to'9') + if (unicodeValue >= 48 && unicodeValue <= 57) { + return unicodeValue - 48; + } + return 0; + } + @Builder buildVerifyCodeComponent() { Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { @@ -141,6 +148,16 @@ struct BackgroundColorChange { .onClick(() => { this.inputController.attach(true, this.textConfig); }) + .onKeyPreIme((key: KeyEvent) => { + if (key.type === KeyType.Up && key.unicode && (key.unicode >= 48 && key.unicode <= 57)) { + if (this.codeText.length >= this.verifyCodeLength) { + return; + } + this.codeText += this.unicodeToDigit(key.unicode); + return true; + } + return false; + }) } build() { diff --git a/entry/src/main/ets/pages/TextBoxShowCursor.ets b/entry/src/main/ets/pages/TextBoxShowCursor.ets index d4d1a48fd0ad1c820ba9cdc945a083b19a15ac2d..2eab653161e0204a5db67108b1d7b3a099286926 100644 --- a/entry/src/main/ets/pages/TextBoxShowCursor.ets +++ b/entry/src/main/ets/pages/TextBoxShowCursor.ets @@ -40,8 +40,7 @@ const TAG = 'TextBoxShowCursor'; struct TextBoxShowCursor { @Consume('pathInfos') pathInfos: NavPathStack; @StorageProp('currentBreakpoint') curBp: string = Constants.BREAK_POINT_SM; - @StorageProp('topRectHeight') - topRectHeight: number = 0; + @StorageProp('topRectHeight') topRectHeight: number = 0; @State codeText: string = ''; @State opacityColumn: number = 0; @State flag: boolean = true; @@ -154,6 +153,14 @@ struct TextBoxShowCursor { Constants.FIFTY_NINE) : Constants.SIXTY)) } + private unicodeToDigit(unicodeValue: number): number { + // Check for half-width digits('0'to'9') + if (unicodeValue >= 48 && unicodeValue <= 57) { + return unicodeValue - 48; + } + return 0; + } + /** * In some verification code scenarios, the functions of selecting and copying entered verification codes must be * disabled. @@ -200,6 +207,19 @@ struct TextBoxShowCursor { } }) .width(this.curBp === 'sm' ? Constants.FULL_WIDTH : $r('app.float.context_area')) + .onKeyPreIme((key: KeyEvent) => { + if (key.type === KeyType.Up && key.unicode && (key.unicode >= 48 && key.unicode <= 57)) { + if (this.codeText.length >= this.verifyCodeLength) { + return; + } + this.codeText += this.unicodeToDigit(key.unicode); + if (this.codeText.length === this.verifyCodeLength) { + this.flag = false; + } + return true; + } + return false; + }) Row() { Column() {