From b3133b1ce2d3eeee1a796d98127a7e940358aaf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E6=96=8C?= Date: Wed, 9 Apr 2025 19:18:13 +0800 Subject: [PATCH] =?UTF-8?q?sample=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 4 +++- README.md | 4 +++- .../{BreakpointSystem.ets => BreakpointType.ets} | 0 entry/src/main/ets/common/Constants.ets | 2 +- entry/src/main/ets/common/ResourceUtil.ets | 4 +++- entry/src/main/ets/entryability/EntryAbility.ets | 13 ++++++------- entry/src/main/ets/pages/Index.ets | 2 +- entry/src/main/ets/pages/WebPage.ets | 9 +++++---- 8 files changed, 22 insertions(+), 16 deletions(-) rename entry/src/main/ets/common/{BreakpointSystem.ets => BreakpointType.ets} (100%) diff --git a/README.en.md b/README.en.md index 2c5ea32..cd5d037 100644 --- a/README.en.md +++ b/README.en.md @@ -15,7 +15,9 @@ Instructions: ``` ├──entry/src/main/ets/ │ ├──common -│ │ └──Constants.ets // Common constant class +│ │ ├──BreakpointType.ets +│ │ ├──Constants.ets // Common constant class +│ │ └──ResourceUtil.ets │ ├──entryability │ │ └──EntryAbility.ets // Entry ability │ └──pages diff --git a/README.md b/README.md index a6c233b..33f006b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ ``` ├──entry/src/main/ets/ │ ├──common -│ │ └──Constants.ets // 公共常量类 +│ │ ├──BreakpointType.ets +│ │ ├──Constants.ets // 公共常量类 +│ │ └──ResourceUtil.ets │ ├──entryability │ │ └──EntryAbility.ets // 程序入口类 │ └──pages diff --git a/entry/src/main/ets/common/BreakpointSystem.ets b/entry/src/main/ets/common/BreakpointType.ets similarity index 100% rename from entry/src/main/ets/common/BreakpointSystem.ets rename to entry/src/main/ets/common/BreakpointType.ets diff --git a/entry/src/main/ets/common/Constants.ets b/entry/src/main/ets/common/Constants.ets index 49c8670..23dc95e 100644 --- a/entry/src/main/ets/common/Constants.ets +++ b/entry/src/main/ets/common/Constants.ets @@ -43,5 +43,5 @@ export class Constants { * Set the url whitelist of the current web */ public static readonly URL_TRUST: string = - '{\"UrlPermissionList\": [{\"scheme\": \"https\",\"host\": \"developer.huawei.com/consumer/cn/next\"}]}'; + '{\"UrlPermissionList\": [{\"scheme\": \"https\",\"host\": \"developer.huawei.com\"}]}'; } \ No newline at end of file diff --git a/entry/src/main/ets/common/ResourceUtil.ets b/entry/src/main/ets/common/ResourceUtil.ets index 9709127..f26f38e 100644 --- a/entry/src/main/ets/common/ResourceUtil.ets +++ b/entry/src/main/ets/common/ResourceUtil.ets @@ -15,6 +15,7 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { JSON, util } from '@kit.ArkTS'; +import { BusinessError } from '@kit.BasicServicesKit'; export class ResourceUtil { /** @@ -30,7 +31,8 @@ export class ResourceUtil { try { resourceString = context.resourceManager.getStringSync(resource.id); } catch (error) { - hilog.error(0x0000, 'WebviewController', '%{public}s', `error: ${error}`); + hilog.error(0x0000, 'WebviewController', '%{public}s', + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); } return resourceString; } diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 4f3cf04..0c556f4 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -22,7 +22,6 @@ import { createNWeb } from '../pages/WebPage'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; export default class EntryAbility extends UIAbility { - private windowObj?: window.Window; private curBp: string = ''; private updateBreakpoint(windowWidth: number): void { @@ -41,7 +40,8 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('currentBreakpoint', this.curBp); } } catch (error) { - hilog.error(0x0000, 'updateBreakpoint', '%{public}s', `updateBreakpoint fail, err: ${JSON.stringify(error)}`); + hilog.error(0x0000, 'updateBreakpoint', '%{public}s', + `updateBreakpoint fail, ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); } } @@ -74,7 +74,6 @@ export default class EntryAbility extends UIAbility { avoidArea = windowObj.getWindowAvoidArea(type); let topRectHeight = avoidArea.topRect.height; AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.windowObj = windowObj; this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); windowObj.on('windowSizeChange', (windowSize) => { this.updateBreakpoint(windowSize.width); @@ -89,17 +88,17 @@ export default class EntryAbility extends UIAbility { createNWeb(ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, ConfigMapKey.GALLERY_URL), windowStage.getMainWindowSync().getUIContext()); if (err.code) { - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + hilog.error(0x0000, 'testTag', 'Failed to load the content.'); return; } - hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.', JSON.stringify(data) ?? ''); let windowClass: window.Window = windowStage.getMainWindowSync(); let isLayoutFullScreen = true; windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { hilog.info(0x0000, 'testTag', '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { + }).catch(() => { hilog.error(0x0000, 'testTag', '%{public}s', - `Failed to set the window layout to full-screen mode. Cause:${err}`); + 'Failed to set the window layout to full-screen mode.'); }); }); } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index d336974..af52f75 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -15,7 +15,7 @@ import { common } from '@kit.AbilityKit'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; -import { BreakpointType } from '../common/BreakpointSystem'; +import { BreakpointType } from '../common/BreakpointType'; import { Constants } from '../common/Constants'; import { getNWeb } from './WebPage'; diff --git a/entry/src/main/ets/pages/WebPage.ets b/entry/src/main/ets/pages/WebPage.ets index fe0baaa..4a4cb80 100644 --- a/entry/src/main/ets/pages/WebPage.ets +++ b/entry/src/main/ets/pages/WebPage.ets @@ -13,12 +13,13 @@ * limitations under the License. */ -import { UIContext, NodeController, BuilderNode, FrameNode } from '@kit.ArkUI'; +import { BuilderNode, FrameNode, NodeController, UIContext } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; import { webview } from '@kit.ArkWeb'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; import { Constants } from '../common/Constants'; +import { BusinessError } from '@kit.BasicServicesKit'; class Data { public url: string = @@ -36,12 +37,12 @@ function webBuilder(data: Data) { // Set the whitelist to allow access to only the trust web page. data.controller.setUrlTrustList(Constants.URL_TRUST); } catch (error) { - hilog.error(0x0000, 'WebviewController', '%{public}s', `error: ${error}`); + hilog.error(0x0000, 'WebviewController', '%{public}s', + `ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); } }) .onSslErrorEventReceive((event) => { - hilog.info(0x0000, 'onSslErrorEventReceive', '%{public}s', - `ssl check failed, error is :${event.error.toString()}`); + hilog.info(0x0000, 'onSslErrorEventReceive', '%{public}s', 'ssl check failed'); event.handler.handleCancel(); }) .width($r('app.string.full_height_width')) -- Gitee