From c027ac9087edeff25a542124832c8bcafbbc638a Mon Sep 17 00:00:00 2001 From: DevWiki Date: Tue, 30 Apr 2024 15:37:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0scheme=20=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/ets/pages/Index.ets | 8 ++++++++ app/src/main/ets/pages/system/SchemePage.ets | 19 +++++++++++++++++++ app/src/main/ets/pages/web/WebPage.ets | 8 ++++++++ .../resources/base/profile/main_pages.json | 3 ++- .../src/main/ets/component/web/WebView.ets | 19 ++++++++++++++++++- 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 app/src/main/ets/pages/system/SchemePage.ets diff --git a/app/src/main/ets/pages/Index.ets b/app/src/main/ets/pages/Index.ets index 3657b24..ee8d2b0 100644 --- a/app/src/main/ets/pages/Index.ets +++ b/app/src/main/ets/pages/Index.ets @@ -7,6 +7,7 @@ import { BusinessError } from '@ohos.base'; import { Log } from '@devwiki/base'; import { BaseLocalStorage, ScreenUtil } from '@devwiki/base'; import { HomeItem, HomeItemGroup } from '../model/Home'; +import { common, Want } from '@kit.AbilityKit'; @Entry @@ -43,6 +44,13 @@ struct Index { items: [ { name: 'AVPlayer', page: 'pages/media/AVPlayerPage' }, ] + }, + //系统能力 + { + name: 'System', + items: [ + {name: "Scheme", page: 'pages/system/SchemePage'} + ] } ]; diff --git a/app/src/main/ets/pages/system/SchemePage.ets b/app/src/main/ets/pages/system/SchemePage.ets new file mode 100644 index 0000000..1617635 --- /dev/null +++ b/app/src/main/ets/pages/system/SchemePage.ets @@ -0,0 +1,19 @@ +import { common, Want } from '@kit.AbilityKit'; + +@Component +@Entry +export struct SchemePage { + + + + build() { + } + + openHttp() { + let context = getContext(this) as common.UIAbilityContext; + let wantInfo: Want = { + uri: 'https://devwiki.net' + } + context.startAbility(wantInfo); + } +} \ No newline at end of file diff --git a/app/src/main/ets/pages/web/WebPage.ets b/app/src/main/ets/pages/web/WebPage.ets index 220d7c4..e258923 100644 --- a/app/src/main/ets/pages/web/WebPage.ets +++ b/app/src/main/ets/pages/web/WebPage.ets @@ -18,6 +18,14 @@ export struct WebPage { onTitleBarRightClick(event: ClickEvent) { this.webViewController?.refresh(); } + + onBackPress(): boolean | void { + if (this.webViewController?.accessBackward()) { + this.webViewController?.backward(); + return false; + } + return true; + } build() { Column() { diff --git a/app/src/main/resources/base/profile/main_pages.json b/app/src/main/resources/base/profile/main_pages.json index bd15215..213525a 100644 --- a/app/src/main/resources/base/profile/main_pages.json +++ b/app/src/main/resources/base/profile/main_pages.json @@ -6,6 +6,7 @@ "pages/layout/LinearLayoutPage", "pages/layout/RelativeContainerPage", "pages/animation/CompTransitionPage", - "pages/media/AVPlayerPage" + "pages/media/AVPlayerPage", + "pages/system/SchemePage" ] } diff --git a/common_ui/src/main/ets/component/web/WebView.ets b/common_ui/src/main/ets/component/web/WebView.ets index 892a0ee..b9587eb 100644 --- a/common_ui/src/main/ets/component/web/WebView.ets +++ b/common_ui/src/main/ets/component/web/WebView.ets @@ -13,7 +13,8 @@ export struct WebView { @Prop @Watch("onParamChanged")param: WebViewParam = new WebViewParam(); onParamChanged() { - if (this.param.webUrl != this.webviewController.getUrl()) { + if (this.webviewController.getUrl() && this.param.webUrl != this.webviewController.getUrl()) { + let a = this.webviewController.getUrl(); this.controller.loadUrl(this.param.webUrl); } } @@ -60,6 +61,22 @@ export class WebViewController implements WebScriptCallback, WebScriptFunction, this.webviewController?.refresh(); } + accessBackward(): boolean { + return this.webviewController?.accessBackward() ?? false; + } + + backward() { + return this.webviewController?.backward(); + } + + accessForward(): boolean { + return this.webviewController?.accessForward() ?? false; + } + + forward() { + return this.webviewController?.forward(); + } + getCurrentUrl(): string { return this.webviewController?.getUrl() ?? ""; }