From 0136272b22f24917b1abb8ab9530210326f21f3f Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Wed, 11 Jun 2025 14:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=85=89=E6=A0=87=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E3=80=91=E5=92=8C=E3=80=90=E8=83=8C=E6=99=AF=E6=94=B9=E5=8F=98?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC=E3=80=91pc=E9=80=82=E9=85=8D=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/Constants.ets | 6 +++++ .../main/ets/pages/BackgroundColorChange.ets | 21 ++++++++++++++-- .../src/main/ets/pages/TextBoxShowCursor.ets | 24 +++++++++++++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/entry/src/main/ets/common/Constants.ets b/entry/src/main/ets/common/Constants.ets index eb2ae53..7449e9d 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 dd844c2..b202cc3 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 d4d1a48..2eab653 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() { -- Gitee