From 03b1569016b5ee24ad1184edc6b655518dddd6b0 Mon Sep 17 00:00:00 2001 From: liugang9704 <2745340733@qq.com> Date: Fri, 19 Sep 2025 10:37:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update:=20=E6=B7=BB=E5=8A=A0try/catch?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/entryability/EntryAbility.ets | 33 ++++++----- entry/src/main/ets/pages/AuthorizedDialog.ets | 54 +++++++++++++----- .../main/ets/loginAbility/LoginAbility.ets | 32 ++++++----- login/src/main/ets/pages/AuthorizedDialog.ets | 56 ++++++++++++++----- 4 files changed, 119 insertions(+), 56 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index e596ee9..b4aea0f 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -24,21 +24,26 @@ export default class EntryAbility extends UIAbility { private color: string = '#F5F5F5'; private updateBreakpoint(windowWidth: number): void { - let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; - let newBp: string = ''; - if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_SM) { - newBp = 'xs'; - } else if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_MD) { - newBp = 'sm' - } else if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_LG) { - newBp = 'md' - } else { - newBp = 'lg' - } - if (this.curBp !== newBp) { - this.curBp = newBp; - AppStorage.setOrCreate('currentBreakpoint', this.curBp); + try { + let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; + let newBp: string = ''; + if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_SM) { + newBp = 'xs'; + } else if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_MD) { + newBp = 'sm'; + } else if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_LG) { + newBp = 'md'; + } else { + newBp = 'lg'; + } + if (this.curBp !== newBp) { + this.curBp = newBp; + AppStorage.setOrCreate('currentBreakpoint', this.curBp); + } + } catch (error) { + hilog.error(0x0000, 'EntryAbility', `getDefaultDisplaySync failed. code=${error.code}, message=${error.message}`); } + } onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { diff --git a/entry/src/main/ets/pages/AuthorizedDialog.ets b/entry/src/main/ets/pages/AuthorizedDialog.ets index d706e34..5789539 100644 --- a/entry/src/main/ets/pages/AuthorizedDialog.ets +++ b/entry/src/main/ets/pages/AuthorizedDialog.ets @@ -13,7 +13,8 @@ * limitations under the License. */ -import { promptAction, router } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { NetJudge } from '../util/JudgeHasNet'; import { CommonConstants } from '../common/CommonConstants'; @@ -40,21 +41,36 @@ export struct AuthorizedDialog { loginVerification() { if (!this.inputContent || !this.password) { - this.getUIContext().getPromptAction().showToast({ - message: $r('app.string.input_phone_number_or_password'), - duration: 2000 - }); + try { + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.input_phone_number_or_password'), + duration: 2000 + }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `showToast failed. code=${err.code}, message=${err.message}`); + } } else if (this.inputContent && this.password && !this.allowClick) { - this.getUIContext().getPromptAction().showToast({ - message: $r('app.string.incorrect_mobile_number_format'), - duration: 2000 - }); - } else { - if (!this.isHasNetwork) { + try { this.getUIContext().getPromptAction().showToast({ - message: $r('app.string.network_error'), + message: $r('app.string.incorrect_mobile_number_format'), duration: 2000 }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `showToast failed. code=${err.code}, message=${err.message}`); + } + } else { + if (!this.isHasNetwork) { + try { + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.network_error'), + duration: 2000 + }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `showToast failed. code=${err.code}, message=${err.message}`); + } } else { if (!this.isChecked) { this.getUIContext().getPromptAction().openCustomDialog({ @@ -76,6 +92,8 @@ export struct AuthorizedDialog { backgroundColor: Color.White }).then((dialogId: number) => { this.customDialogComponentId = dialogId; + }).catch((error: BusinessError)=>{ + hilog.error(0x0000, 'AuthorizedDialog', `openCustomDialog failed. code=${error.code}, message=${error.message}`); }) } else { AppStorage.setOrCreate('isLogin', true); @@ -127,7 +145,11 @@ export struct AuthorizedDialog { .height($r('app.float.customDialog_bottom_row_height')) .lineHeight($r('app.float.line_height')) .onClick(() => { - this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId) + try { + this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId) + } catch (error) { + hilog.error(0x0000, 'AuthorizedDialog', `closeCustomDialog failed. code=${error.code}, message=${error.message}`); + } }) Text($r('app.string.confirm_login')) @@ -143,7 +165,11 @@ export struct AuthorizedDialog { this.getUIContext().getRouter().pushUrl({ url: 'pages/Index' }); - this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId); + try { + this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId); + } catch (error) { + hilog.error(0x0000, 'AuthorizedDialog', `closeCustomDialog failed. code=${error.code}, message=${error.message}`); + } }) } .height($r('app.float.customDialog_bottom_row_height')) diff --git a/login/src/main/ets/loginAbility/LoginAbility.ets b/login/src/main/ets/loginAbility/LoginAbility.ets index a7320e0..955d2af 100644 --- a/login/src/main/ets/loginAbility/LoginAbility.ets +++ b/login/src/main/ets/loginAbility/LoginAbility.ets @@ -24,20 +24,24 @@ export default class LoginAbility extends UIAbility { private color: string = '#F5F5F5'; private updateBreakpoint(windowWidth: number): void { - let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; - let newBp: string = ''; - if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_SM) { - newBp = 'xs'; - } else if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_MD) { - newBp = 'sm'; - } else if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_LG) { - newBp = 'md'; - } else { - newBp = 'lg'; - } - if (this.curBp !== newBp) { - this.curBp = newBp; - AppStorage.setOrCreate('currentBreakpoint', this.curBp); + try { + let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; + let newBp: string = ''; + if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_SM) { + newBp = 'xs'; + } else if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_MD) { + newBp = 'sm'; + } else if (windowWidthVp < CommonConstants.WINDOW_WIDTH_VP_LG) { + newBp = 'md'; + } else { + newBp = 'lg'; + } + if (this.curBp !== newBp) { + this.curBp = newBp; + AppStorage.setOrCreate('currentBreakpoint', this.curBp); + } + } catch (error) { + hilog.error(0x0000, 'LoginAbility', `getDefaultDisplaySync failed. code=${error.code}, message=${error.message}`); } } diff --git a/login/src/main/ets/pages/AuthorizedDialog.ets b/login/src/main/ets/pages/AuthorizedDialog.ets index 6d16c52..a7f2399 100644 --- a/login/src/main/ets/pages/AuthorizedDialog.ets +++ b/login/src/main/ets/pages/AuthorizedDialog.ets @@ -14,7 +14,8 @@ */ import { CommonConstants } from '../common/CommonConstants'; -import { promptAction } from '@kit.ArkUI'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; import { NetJudge } from '../util/JudgeHasNet'; @Component @@ -40,21 +41,36 @@ export struct AuthorizedDialog { loginVerification() { if (!this.inputContent || !this.password) { - this.getUIContext().getPromptAction().showToast({ - message: $r('app.string.input_phone_number_or_password'), - duration: 2000 - }); + try { + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.input_phone_number_or_password'), + duration: 2000 + }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `showToast failed. code=${err.code}, message=${err.message}`); + } } else if (this.inputContent && this.password && !this.allowClick) { - this.getUIContext().getPromptAction().showToast({ - message: $r('app.string.incorrect_mobile_number_format'), - duration: 2000 - }); - } else { - if (!this.isHasNetwork) { + try { this.getUIContext().getPromptAction().showToast({ - message: $r('app.string.network_error'), + message: $r('app.string.incorrect_mobile_number_format'), duration: 2000 }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `showToast failed. code=${err.code}, message=${err.message}`); + } + } else { + if (!this.isHasNetwork) { + try { + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.network_error'), + duration: 2000 + }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `showToast failed. code=${err.code}, message=${err.message}`); + } } else { if (!this.isChecked) { this.getUIContext().getPromptAction().openCustomDialog({ @@ -76,6 +92,8 @@ export struct AuthorizedDialog { backgroundColor: Color.White }).then((dialogId: number) => { this.customDialogComponentId = dialogId; + }).catch((error: BusinessError)=>{ + hilog.error(0x0000, 'AuthorizedDialog', `openCustomDialog failed. code=${error.code}, message=${error.message}`); }) } else { AppStorage.setOrCreate('isModalLogin', true); @@ -127,7 +145,12 @@ export struct AuthorizedDialog { .height($r('app.float.customDialog_bottom_row_height')) .lineHeight($r('app.float.line_height')) .onClick(() => { - this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId) + try { + this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `closeCustomDialog failed. code=${err.code}, message=${err.message}`); + } }) Text($r('app.string.confirm_login')) @@ -143,7 +166,12 @@ export struct AuthorizedDialog { this.getUIContext().getRouter().pushUrl({ url: 'pages/Index' }); - this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId); + try { + this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `closeCustomDialog failed. code=${err.code}, message=${err.message}`); + } this.isLoginShowSheet = false; }) } -- Gitee From a85855a823e83b1430ccf1e6edff6c87fc9d1122 Mon Sep 17 00:00:00 2001 From: liugang9704 <2745340733@qq.com> Date: Fri, 19 Sep 2025 11:14:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update:=20=E6=B7=BB=E5=8A=A0try/catch?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/AuthorizedDialog.ets | 10 ++++++++-- login/src/main/ets/pages/AuthorizedDialog.ets | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/entry/src/main/ets/pages/AuthorizedDialog.ets b/entry/src/main/ets/pages/AuthorizedDialog.ets index 5789539..1b249c0 100644 --- a/entry/src/main/ets/pages/AuthorizedDialog.ets +++ b/entry/src/main/ets/pages/AuthorizedDialog.ets @@ -99,6 +99,8 @@ export struct AuthorizedDialog { AppStorage.setOrCreate('isLogin', true); this.getUIContext().getRouter().pushUrl({ url: 'pages/Index' + }).catch((error: BusinessError) => { + hilog.error(0x0000, 'AuthorizedDialog', `pushUrl failed. code=${error.code}, message=${error.message}`); }); } } @@ -148,7 +150,8 @@ export struct AuthorizedDialog { try { this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId) } catch (error) { - hilog.error(0x0000, 'AuthorizedDialog', `closeCustomDialog failed. code=${error.code}, message=${error.message}`); + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `closeCustomDialog failed. code=${err.code}, message=${err.message}`); } }) @@ -164,11 +167,14 @@ export struct AuthorizedDialog { AppStorage.setOrCreate('isLogin', true); this.getUIContext().getRouter().pushUrl({ url: 'pages/Index' + }).catch((error: BusinessError) => { + hilog.error(0x0000, 'AuthorizedDialog', `pushUrl failed. code=${error.code}, message=${error.message}`); }); try { this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId); } catch (error) { - hilog.error(0x0000, 'AuthorizedDialog', `closeCustomDialog failed. code=${error.code}, message=${error.message}`); + let err = error as BusinessError; + hilog.error(0x0000, 'AuthorizedDialog', `closeCustomDialog failed. code=${err.code}, message=${err.message}`); } }) } diff --git a/login/src/main/ets/pages/AuthorizedDialog.ets b/login/src/main/ets/pages/AuthorizedDialog.ets index a7f2399..f302ba4 100644 --- a/login/src/main/ets/pages/AuthorizedDialog.ets +++ b/login/src/main/ets/pages/AuthorizedDialog.ets @@ -99,6 +99,8 @@ export struct AuthorizedDialog { AppStorage.setOrCreate('isModalLogin', true); this.getUIContext().getRouter().pushUrl({ url: 'pages/Index' + }).catch((error: BusinessError) => { + hilog.error(0x0000, 'AuthorizedDialog', `pushUrl failed. code=${error.code}, message=${error.message}`); }); } } @@ -165,6 +167,8 @@ export struct AuthorizedDialog { AppStorage.setOrCreate('isModalLogin', true); this.getUIContext().getRouter().pushUrl({ url: 'pages/Index' + }).catch((error: BusinessError) => { + hilog.error(0x0000, 'AuthorizedDialog', `pushUrl failed. code=${error.code}, message=${error.message}`); }); try { this.getUIContext().getPromptAction().closeCustomDialog(this.customDialogComponentId); -- Gitee