From b213d524d3000456cf62e2dfccf5e1e0158d6f5b Mon Sep 17 00:00:00 2001 From: WX1379483 Date: Thu, 29 May 2025 15:57:18 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=A0=87=E8=AF=86):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9WebApplicationJump=E4=BB=93=E5=BA=93=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/default/resources/rawfile/index.html | 45 ++++++++++++++ .../default/resources/rawfile/index1_cn.html | 30 ++++++++++ .../default/resources/rawfile/index1_en.html | 29 +++++++++ .../res/default/resources/rawfile/index2.html | 30 ++++++++++ .../res/default/resources/rawfile/index3.html | 30 ++++++++++ .../default/resources/rawfile/index_cn.html | 36 +++++++++++ .../default/resources/rawfile/index_en.html | 38 ++++++++++++ entry/src/main/ets/pages/Index.ets | 4 +- entry/src/main/ets/pages/Navigation.ets | 21 +++++++ entry/src/main/ets/pages/Navigation1.ets | 32 ++++++++++ entry/src/main/ets/pages/Navigation2.ets | 49 +++++++++++++++ entry/src/main/ets/pages/Navigation3.ets | 60 +++++++++++++++++++ entry/src/main/ets/pages/Navigation4.ets | 43 +++++++++++++ entry/src/main/module.json5 | 2 + entry/src/main/resources/rawfile/index.html | 45 ++++++++++++++ entry/src/main/resources/rawfile/index2.html | 30 ++++++++++ entry/src/main/resources/rawfile/index3.html | 30 ++++++++++ 17 files changed, 551 insertions(+), 3 deletions(-) create mode 100644 entry/build/default/intermediates/res/default/resources/rawfile/index.html create mode 100644 entry/build/default/intermediates/res/default/resources/rawfile/index1_cn.html create mode 100644 entry/build/default/intermediates/res/default/resources/rawfile/index1_en.html create mode 100644 entry/build/default/intermediates/res/default/resources/rawfile/index2.html create mode 100644 entry/build/default/intermediates/res/default/resources/rawfile/index3.html create mode 100644 entry/build/default/intermediates/res/default/resources/rawfile/index_cn.html create mode 100644 entry/build/default/intermediates/res/default/resources/rawfile/index_en.html create mode 100644 entry/src/main/ets/pages/Navigation.ets create mode 100644 entry/src/main/ets/pages/Navigation1.ets create mode 100644 entry/src/main/ets/pages/Navigation2.ets create mode 100644 entry/src/main/ets/pages/Navigation3.ets create mode 100644 entry/src/main/ets/pages/Navigation4.ets create mode 100644 entry/src/main/resources/rawfile/index.html create mode 100644 entry/src/main/resources/rawfile/index2.html create mode 100644 entry/src/main/resources/rawfile/index3.html diff --git a/entry/build/default/intermediates/res/default/resources/rawfile/index.html b/entry/build/default/intermediates/res/default/resources/rawfile/index.html new file mode 100644 index 0000000..d5f13d0 --- /dev/null +++ b/entry/build/default/intermediates/res/default/resources/rawfile/index.html @@ -0,0 +1,45 @@ + + + + + + Document + + + + +
+
+
+ +
+ + Web 页面 +
+
Hello Web
+ 跳转回Web页面 + // [Start example1] + 跳转到其他页面 + // [End example1] + // [Start origin_page] + 跳转到ArkTS页面 + // [End origin_page] + // [Start detail1] + 去应用市场下载 + 打开应用 + // [End detail1] + // [Start pull_special] + 拉起指定类型应用 + // [End pull_special] + // [Start select_photo] + 拉起系统应用 + // [End select_photo] +
+ + + diff --git a/entry/build/default/intermediates/res/default/resources/rawfile/index1_cn.html b/entry/build/default/intermediates/res/default/resources/rawfile/index1_cn.html new file mode 100644 index 0000000..b2bef50 --- /dev/null +++ b/entry/build/default/intermediates/res/default/resources/rawfile/index1_cn.html @@ -0,0 +1,30 @@ + + + + + + Document + + + + +
+
+
+ +
+ + Web 页面 +
+
Hello Web
+ 跳转回Web页面 +
+ + + diff --git a/entry/build/default/intermediates/res/default/resources/rawfile/index1_en.html b/entry/build/default/intermediates/res/default/resources/rawfile/index1_en.html new file mode 100644 index 0000000..211cdee --- /dev/null +++ b/entry/build/default/intermediates/res/default/resources/rawfile/index1_en.html @@ -0,0 +1,29 @@ + + + + + + Document + + + +
+
+
+ +
+ + Web Page +
+
Hello Web
+ Navigate back to the Web page +
+ + + diff --git a/entry/build/default/intermediates/res/default/resources/rawfile/index2.html b/entry/build/default/intermediates/res/default/resources/rawfile/index2.html new file mode 100644 index 0000000..7ff3f83 --- /dev/null +++ b/entry/build/default/intermediates/res/default/resources/rawfile/index2.html @@ -0,0 +1,30 @@ + + + + + + Document + + + + +
+
+
+ +
+ + Web 页面 +
+
Hello Web
+ 跳转回Web页面 +
+ + + diff --git a/entry/build/default/intermediates/res/default/resources/rawfile/index3.html b/entry/build/default/intermediates/res/default/resources/rawfile/index3.html new file mode 100644 index 0000000..7ff3f83 --- /dev/null +++ b/entry/build/default/intermediates/res/default/resources/rawfile/index3.html @@ -0,0 +1,30 @@ + + + + + + Document + + + + +
+
+
+ +
+ + Web 页面 +
+
Hello Web
+ 跳转回Web页面 +
+ + + diff --git a/entry/build/default/intermediates/res/default/resources/rawfile/index_cn.html b/entry/build/default/intermediates/res/default/resources/rawfile/index_cn.html new file mode 100644 index 0000000..f72d09c --- /dev/null +++ b/entry/build/default/intermediates/res/default/resources/rawfile/index_cn.html @@ -0,0 +1,36 @@ + + + + + + Document + + + + +
+
Web和应用的跳转与拉起
+ +
+ + + diff --git a/entry/build/default/intermediates/res/default/resources/rawfile/index_en.html b/entry/build/default/intermediates/res/default/resources/rawfile/index_en.html new file mode 100644 index 0000000..cd0bccf --- /dev/null +++ b/entry/build/default/intermediates/res/default/resources/rawfile/index_en.html @@ -0,0 +1,38 @@ + + + + + + Document + + + + +
+
web and application jump and pull up
+ +
+ + + diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index be9dc3a..7068246 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -133,7 +133,6 @@ struct Index { } build() { - // [Start navigation] Navigation(this.navPathStack) { Column() { Web({ @@ -149,9 +148,8 @@ struct Index { }) } } - // [End navigation] .hideTitleBar(true) .navDestination(this.PageMap) .mode(NavigationMode.Stack) } -} \ No newline at end of file +} diff --git a/entry/src/main/ets/pages/Navigation.ets b/entry/src/main/ets/pages/Navigation.ets new file mode 100644 index 0000000..805e170 --- /dev/null +++ b/entry/src/main/ets/pages/Navigation.ets @@ -0,0 +1,21 @@ +@Component +export struct Navigation1 { + @Consume('navPathStack') navPathStack: NavPathStack; + + build() { + // [Start navigation] + NavDestination() { + Column() { + Button($r('app.string.back_to_web_page')) + .width('100%') + .height(40) + .onClick(() => { + this.navPathStack.pushPath({ name: 'WebPage' }); + }) + } + // ... + } + .title('ArkTS页面') + // [End navigation] + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Navigation1.ets b/entry/src/main/ets/pages/Navigation1.ets new file mode 100644 index 0000000..348fe0d --- /dev/null +++ b/entry/src/main/ets/pages/Navigation1.ets @@ -0,0 +1,32 @@ +class PathStack{ + pop(){ + return + } +} +@Component +export struct Navigation2 { + private controller:ESObject; + private navPathStack=new PathStack() +build() { + // [Start navigation1] + NavDestination() { + Column() { + Web({ + src: $rawfile('index.html'), + controller: this.controller + }) + .zoomAccess(false) + .onLoadIntercept((event) => { + const url: string = event.data.getRequestUrl(); + if (url === 'arkts://pages/toOriginPage') { + this.navPathStack.pop(); + } + // [StartExclude navigation1] + return false; + // [EndExclude navigation1] + }) + } + } + // [End navigation1] + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Navigation2.ets b/entry/src/main/ets/pages/Navigation2.ets new file mode 100644 index 0000000..c83bc3f --- /dev/null +++ b/entry/src/main/ets/pages/Navigation2.ets @@ -0,0 +1,49 @@ +import { bundleManager, OpenLinkOptions } from "@kit.AbilityKit"; +import { BusinessError } from "@kit.BasicServicesKit"; +// [Start link1] +const link: string = "appScheme://www.test.com:80/path1"; +// [End link1] +@Component +export struct Navigation3 { + private controller:ESObject; + private navPathStack:ESObject + private context:ESObject; + build() { + // [Start link3] + Navigation(this.navPathStack) { + Column() { + Web({ + src: $rawfile('index2.html'), + controller: this.controller + }) + .zoomAccess(false) + .onLoadIntercept((event) => { + const url: string = event.data.getRequestUrl(); + if (url === 'third-party://pages/toThirdApp') { + const link: string = "appScheme://www.test.com:80/path1"; + // [Start link2] + if (!bundleManager.canOpenLink(link)) { + return true; + } + // [End link1] + // Configuration parameter. + const openLinkOptions: OpenLinkOptions = { + appLinkingOnly: false, + parameters: { + name: 'test' + } + }; + // Open the application using the openLink interface. + this.context.openLink(link, openLinkOptions).then(() => { + console.info('open link success.'); + }).catch((err: BusinessError) => { + console.error(`open link failed. Code is ${err.code}, message is ${err.message}`); + }) + } + return url !== 'resource://rawfile/index2.html'; + }) + } + } + // [End link3] + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Navigation3.ets b/entry/src/main/ets/pages/Navigation3.ets new file mode 100644 index 0000000..3e658f9 --- /dev/null +++ b/entry/src/main/ets/pages/Navigation3.ets @@ -0,0 +1,60 @@ +import { hilog } from "@kit.PerformanceAnalysisKit"; +import { common } from "@kit.AbilityKit"; + +class context{ + startAbilityByType(name:string,a:ESObject,b:ESObject){ + return + } +} +@Component +export struct Navigation4 { + private controller:ESObject; + private navPathStack:ESObject + private context=new context() + build() { + // [Start path_stack1] + Navigation(this.navPathStack) { + Column() { + Web({ + src: $rawfile('index.html'), + controller: this.controller + }) + .zoomAccess(false) + .onLoadIntercept((event) => { + const url: string = event.data.getRequestUrl(); + if (url === 'arkts://pullSpeciallyApp') { + const wantParam: Record = { + 'sceneType': 1, + 'destinationLatitude': 32.060844, + 'destinationLongitude': 118.78315, + 'destinationName': 'xx市xx路xx号', + 'destinationPoiIds': { + 1: '111111111111', + 2: '222222222222' + } as Record, + 'originName': 'xx市xx公园', + 'originLatitude': 31.060844, + 'originLongitude': 120.78315, + 'originPoiIds': { + 1: '333333333333', + 2: '444444444444' + } as Record, + 'vehicleType': 0 + }; + const abilityStartCallback: common.AbilityStartCallback = { + onError: (code: number, name: string, message: string) => { + hilog.error(0x0000, 'Sample', '%{public}s', 'onError code ' + code + 'name: ' + name + 'message: ' + message); + }, + onResult: (result:ESObject) => { + hilog.error(0x0000, 'Sample', '%{public}s', 'onResult result: ' + JSON.stringify(result)); + } + }; + this.context.startAbilityByType('navigation', wantParam, abilityStartCallback); + } + return url !== 'resource://rawfile/index.html'; + }) + } + } + // [End path_stack1] + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Navigation4.ets b/entry/src/main/ets/pages/Navigation4.ets new file mode 100644 index 0000000..e152231 --- /dev/null +++ b/entry/src/main/ets/pages/Navigation4.ets @@ -0,0 +1,43 @@ +import { photoAccessHelper } from "@kit.MediaLibraryKit"; +import { BusinessError } from "@kit.BasicServicesKit"; + +@Component +export struct Navigation5 { + private PageMap:ESObject; + private controller:ESObject; + private navPathStack:ESObject + build() { + // [Start path_stack2] + Navigation(this.navPathStack) { + Column() { + Web({ + src: $rawfile('index3.html'), + controller: this.controller + }) + .zoomAccess(false) + .onLoadIntercept((event) => { + const url: string = event.data.getRequestUrl(); + if (url === 'photo://pages/selectPhoto') { + const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE + photoSelectOptions.maxSelectNumber = 5; // 选择媒体文件的最大数目 + let uris: Array = []; + const photoViewPicker = new photoAccessHelper.PhotoViewPicker(); + photoViewPicker.select(photoSelectOptions) + .then((photoSelectResult: photoAccessHelper.PhotoSelectResult) => { + uris = photoSelectResult.photoUris; + console.info('photoViewPicker.select to file succeed and uris are:' + uris); + }) + .catch((err: BusinessError) => { + console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`); + }) + } + return url !== 'resource://rawfile/index3.html'; + }) + } + } + .hideTitleBar(true) + .navDestination(this.PageMap) + // [End path_stack2] + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index 82d268e..e464848 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -58,8 +58,10 @@ ], } ], + // [Start query_schemes] "querySchemes": [ "app1Scheme" ], + // [End query_schemes] } } \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/index.html b/entry/src/main/resources/rawfile/index.html new file mode 100644 index 0000000..d5f13d0 --- /dev/null +++ b/entry/src/main/resources/rawfile/index.html @@ -0,0 +1,45 @@ + + + + + + Document + + + + +
+
+
+ +
+ + Web 页面 +
+
Hello Web
+ 跳转回Web页面 + // [Start example1] + 跳转到其他页面 + // [End example1] + // [Start origin_page] + 跳转到ArkTS页面 + // [End origin_page] + // [Start detail1] + 去应用市场下载 + 打开应用 + // [End detail1] + // [Start pull_special] + 拉起指定类型应用 + // [End pull_special] + // [Start select_photo] + 拉起系统应用 + // [End select_photo] +
+ + + diff --git a/entry/src/main/resources/rawfile/index2.html b/entry/src/main/resources/rawfile/index2.html new file mode 100644 index 0000000..7ff3f83 --- /dev/null +++ b/entry/src/main/resources/rawfile/index2.html @@ -0,0 +1,30 @@ + + + + + + Document + + + + +
+
+
+ +
+ + Web 页面 +
+
Hello Web
+ 跳转回Web页面 +
+ + + diff --git a/entry/src/main/resources/rawfile/index3.html b/entry/src/main/resources/rawfile/index3.html new file mode 100644 index 0000000..7ff3f83 --- /dev/null +++ b/entry/src/main/resources/rawfile/index3.html @@ -0,0 +1,30 @@ + + + + + + Document + + + + +
+
+
+ +
+ + Web 页面 +
+
Hello Web
+ 跳转回Web页面 +
+ + + -- Gitee