From ea587b58ad6fce3d6ed649b8244193cf6af9959b Mon Sep 17 00:00:00 2001 From: ZhangQ <12903047+zq-kexin@user.noreply.gitee.com> Date: Mon, 8 Sep 2025 09:37:36 +0000 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ZhangQ <12903047+zq-kexin@user.noreply.gitee.com> --- .../main/ets/pages/BackgroundColorChange.ets | 27 ++++++++----- .../src/main/ets/pages/TextBoxShowCursor.ets | 39 +++++++++++-------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/entry/src/main/ets/pages/BackgroundColorChange.ets b/entry/src/main/ets/pages/BackgroundColorChange.ets index 6ba8379..2069ab7 100644 --- a/entry/src/main/ets/pages/BackgroundColorChange.ets +++ b/entry/src/main/ets/pages/BackgroundColorChange.ets @@ -59,7 +59,9 @@ struct BackgroundColorChange { async attach() { if (this.isFirstOpenPage) { - await this.inputController.attach(true, this.textConfig); + await this.inputController.attach(true, this.textConfig).catch((err: BusinessError) => { + hilog.error(0x0000, TAG, `attach failed. code=${err.code}, message=${err.message}`); + }); this.listen(); return; } @@ -77,15 +79,20 @@ struct BackgroundColorChange { } listen() { - this.inputController.on('insertText', (text: string) => { - if (this.codeText.length >= this.verifyCodeLength || isNaN(Number(text)) || text === ' ') { - return; - } - this.codeText += text; - }) - this.inputController.on('deleteLeft', () => { - this.codeText = this.codeText.substring(0, this.codeText.length - 1); - }) + try { + this.inputController.on('insertText', (text: string) => { + if (this.codeText.length >= this.verifyCodeLength || isNaN(Number(text)) || text === ' ') { + return; + } + this.codeText += text; + }) + this.inputController.on('deleteLeft', () => { + this.codeText = this.codeText.substring(0, this.codeText.length - 1); + }) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, TAG, `listen failed. code=${err.code}, message=${err.message}`); + } } detach(): void { diff --git a/entry/src/main/ets/pages/TextBoxShowCursor.ets b/entry/src/main/ets/pages/TextBoxShowCursor.ets index dc10082..fa73c21 100644 --- a/entry/src/main/ets/pages/TextBoxShowCursor.ets +++ b/entry/src/main/ets/pages/TextBoxShowCursor.ets @@ -60,7 +60,9 @@ struct TextBoxShowCursor { */ async attach() { if (this.isFirstOpenPage) { - await this.inputController.attach(true, this.textConfig); + await this.inputController.attach(true, this.textConfig).catch((err: BusinessError) => { + hilog.error(0x0000, TAG, `attach failed. code=${err.code}, message=${err.message}`); + }); this.listen(); return; } @@ -82,21 +84,26 @@ struct TextBoxShowCursor { * the keyboard. */ listen() { - this.inputController.on('insertText', (text: string) => { - if (this.codeText.length >= this.verifyCodeLength || isNaN(Number(text)) || text === ' ') { - return; - } - this.codeText += text; - if (this.codeText.length === this.verifyCodeLength) { - this.flag = false; - } - }) - this.inputController.on('deleteLeft', () => { - this.codeText = this.codeText.substring(0, this.codeText.length - 1); - if (this.codeText.length !== this.verifyCodeLength) { - this.flag = true; - } - }) + try { + this.inputController.on('insertText', (text: string) => { + if (this.codeText.length >= this.verifyCodeLength || isNaN(Number(text)) || text === ' ') { + return; + } + this.codeText += text; + if (this.codeText.length === this.verifyCodeLength) { + this.flag = false; + } + }) + this.inputController.on('deleteLeft', () => { + this.codeText = this.codeText.substring(0, this.codeText.length - 1); + if (this.codeText.length !== this.verifyCodeLength) { + this.flag = true; + } + }) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, TAG, `listen failed. code=${err.code}, message=${err.message}`); + } } /** -- Gitee