Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
xugenyuan
2024-07-23 11:17:06 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8e9b2d6e9cff9f41aa8381795e4599fc3a8759de
8e9b2d6e
1 parent
1f5d905b
ref |> 处理AppLinking跳转问题
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
285 additions
and
18 deletions
sight_harmony/commons/wdRouter/Index.ets
sight_harmony/commons/wdRouter/src/main/ets/utils/AppInnerLinkGenerator.ets
sight_harmony/commons/wdRouter/src/main/ets/utils/AppLinkingManager.ets
sight_harmony/products/phone/src/main/ets/startupmanager/StartupManager.ets
sight_harmony/products/phone/src/main/module.json5
sight_harmony/commons/wdRouter/Index.ets
View file @
8e9b2d6
...
...
@@ -19,3 +19,5 @@ export { AppInnerLink } from './src/main/ets/utils/AppInnerLink'
export { ContentType } from './src/main/ets/common/ContentType'
export { AppInnerLinkGenerator } from "./src/main/ets/utils/AppInnerLinkGenerator"
export { AppLinkingManager } from "./src/main/ets/utils/AppLinkingManager"
\ No newline at end of file
...
...
sight_harmony/commons/wdRouter/src/main/ets/utils/AppInnerLinkGenerator.ets
View file @
8e9b2d6
...
...
@@ -19,10 +19,10 @@ export class AppInnerLinkGenerator {
return AppInnerLinkGenerator.generate(Number(content.newsType), content.newsId +'', content.newsRelId + '', content.linkUrl)
}
private
static generate(contentType: number, contentId?: string, relId?: string, link?: string): string {
static generate(contentType: number, contentId?: string, relId?: string, link?: string): string {
let deeplink = AppInnerLinkGenerator.DEEP_LINK_PREFIX
let pubParam = `&contentId=${contentId
}&relId=${relId
}&skipType=1`
let pubParam = `&contentId=${contentId
?? ""}&relId=${relId ?? ""
}&skipType=1`
let type: ContentType = Number(contentType)
switch (type) {
...
...
@@ -64,5 +64,17 @@ export class AppInnerLinkGenerator {
return deeplink
}
static generateCreatorPage(creatorId: string): string {
let deeplink = AppInnerLinkGenerator.DEEP_LINK_PREFIX
deeplink += `?type=owner_page&creatorId=${creatorId}&skipType=1`
return deeplink
}
static generateH5Topic(pageId:string, url:string) {
// rmrbapp://rmrb.app/openwith?type=topic&subType=h5&pageId=124&relId=23&url=https%3A%2F%2Fbaidu.com&skipType=1
let deeplink = AppInnerLinkGenerator.DEEP_LINK_PREFIX
deeplink += `?type=topic&subType=h5&pageId=${pageId}&relId=&url=${encodeURIComponent(url)}&skipType=1`
return deeplink
}
}
\ No newline at end of file
...
...
sight_harmony/commons/wdRouter/src/main/ets/utils/AppLinkingManager.ets
0 → 100644
View file @
8e9b2d6
import { Logger } from 'wdKit'
import { Want } from '@kit.AbilityKit'
import { url } from '@kit.ArkTS'
import { AppInnerLinkGenerator } from './AppInnerLinkGenerator'
import { ContentType } from '../common/ContentType'
import { AppInnerLink } from './AppInnerLink'
import { HttpBizUtil, HttpUrlUtils, ResponseDTO } from 'wdNetwork'
import { ContentDetailDTO } from 'wdBean'
const TAG = "AppLinkingManager"
// 系统AppLinking拉起管理类
export class AppLinkingManager {
static readonly TEST_HOST = "pd-people-uat.pdnews.cn"
static readonly PRODUCT_HOST = "www.peopleapp.com"
private hasEnterMain = false
private lastUrlObj?: url.URL
private static manager: AppLinkingManager
private constructor() {
}
public static sharedInstance() {
if (!AppLinkingManager.manager) {
AppLinkingManager.manager = new AppLinkingManager()
}
return AppLinkingManager.manager
}
onWant(want: Want) {
this.onNewWant(want, true)
}
onNewWant(want: Want, startup: boolean = false) {
Logger.debug(TAG, "want: " + JSON.stringify(want))
let uri = want?.uri
if (!uri) {
return
}
let urlObject = url.URL.parseURL(want?.uri);
if (urlObject.protocol != "https:") {
return
}
if (urlObject.host != AppLinkingManager.PRODUCT_HOST && urlObject.host != AppLinkingManager.TEST_HOST) {
return
}
this.lastUrlObj = urlObject
if (this.hasEnterMain) {
this.comsumeLastUriContent()
}
}
// 首次进入主页,即可解析跳转推送
onReachMainPage() {
this.hasEnterMain = true
this.comsumeLastUriContent()
}
comsumeLastUriContent() {
Logger.debug(TAG, "尝试消费拉起链接: " + this.lastUrlObj?.toString())
if (!this.lastUrlObj) {
return
}
let path = this.lastUrlObj?.pathname ?? ""
if (this.dealWithRMHArticle()
|| this.dealWithNormalArticle()
|| this.dealWithCreator()
|| this.dealWithTopic()) {
this.lastUrlObj = undefined
return
}
Logger.debug(TAG, "未处理path: " + path)
this.lastUrlObj = undefined
}
dealWithRMHArticle() {
let path = this.lastUrlObj?.pathname ?? ""
if (path.startsWith("/rmharticle")) {
let contentId = path.split("/").pop()
let innerLink = AppInnerLinkGenerator.generate(ContentType.ImageText, contentId, undefined, undefined)
this.jumpInnerLink(innerLink)
return true
}
if (path.startsWith("/rmhphotos")) {
let contentId = path.split("/").pop()
let innerLink = AppInnerLinkGenerator.generate(ContentType.Pictures, contentId, undefined, undefined)
this.jumpInnerLink(innerLink)
return true
}
if (path.startsWith("/rmhmoments")) {
let contentId = path.split("/").pop()
let innerLink = AppInnerLinkGenerator.generate(ContentType.DynamicImageText, contentId, undefined, undefined)
this.jumpInnerLink(innerLink)
return true
}
if (path.startsWith("/rmhvideo")) {
let contentId = path.split("/").pop()
let innerLink = AppInnerLinkGenerator.generate(ContentType.Video, contentId, undefined, undefined)
this.jumpInnerLink(innerLink)
return true
}
if (path.startsWith("/column")) {
let contentId = path.split("/").pop()
if (!contentId || contentId.includes("-")) {
return false
}
let innerLink = AppInnerLinkGenerator.generate(ContentType.Live, contentId, undefined, undefined)
this.jumpInnerLink(innerLink)
return true
}
return false
}
dealWithCreator() {
let path = this.lastUrlObj?.pathname ?? ""
if (path.startsWith("/author")) {
let creatorId = path.split("/").pop()
let innerLink = AppInnerLinkGenerator.generateCreatorPage(creatorId ?? "")
this.jumpInnerLink(innerLink)
return true
}
return false
}
dealWithTopic() {
let path = this.lastUrlObj?.pathname ?? ""
let idArray = path.split("/").pop()?.split("-")
if (idArray?.length != 2) {
return false
}
let pageId = idArray[0]
let topicId = idArray[1]
let url = `${this.lastUrlObj!.protocol}//${this.lastUrlObj!.host}/h${path}`
if (path.startsWith("/votetopic")) {
let innerLink = AppInnerLinkGenerator.generateH5Topic(pageId, url)
this.jumpInnerLink(innerLink)
return true
}
if (path.startsWith("/articletopic")) {
let innerLink = AppInnerLinkGenerator.generateH5Topic(pageId, url)
this.jumpInnerLink(innerLink)
}
if (path.startsWith("/livetopic")) {
let innerLink = AppInnerLinkGenerator.generateH5Topic(pageId, url)
this.jumpInnerLink(innerLink)
}
if (path.startsWith("/timelinetopic")) {
let innerLink = AppInnerLinkGenerator.generateH5Topic(pageId, url)
this.jumpInnerLink(innerLink)
}
return false
}
dealWithNormalArticle() {
let path = this.lastUrlObj?.pathname ?? ""
if (!path.startsWith("/column")) {
return false
}
let idArray = path.split("/").pop()?.split("-")
if (idArray?.length != 2) {
return false
}
let contentId = idArray[0]
let relId = idArray[1]
let url = HttpUrlUtils.getHost() + HttpUrlUtils.DETAIL_PATH
url = url + "?&contentId=" + contentId + "&relId=" + relId // + "&relType=" + relType
HttpBizUtil.get<ResponseDTO<ContentDetailDTO[]>>(url).then((data: ResponseDTO<ContentDetailDTO[]>) => {
if (data.code != 0) {
Logger.warn(TAG, "error " + JSON.stringify(data))
return
}
if (!data.data || data.data.length == 0) {
Logger.warn(TAG, "empty data!!!")
return
}
let innerLink = AppInnerLinkGenerator.generateDeepLinkWithConent(data.data[0])
this.jumpInnerLink(innerLink)
}, (error: Error) => {
Logger.warn(TAG, "error " + JSON.stringify(error))
})
return true
}
jumpInnerLink(innerLink: string) {
Logger.debug(TAG, "即将跳转链接: " + innerLink)
AppInnerLink.jumpWithLink(innerLink)
}
}
\ No newline at end of file
...
...
sight_harmony/products/phone/src/main/ets/startupmanager/StartupManager.ets
View file @
8e9b2d6
...
...
@@ -12,7 +12,7 @@ import { DeviceUtil,
UmengStats } from 'wdKit/Index'
import { LoginModule } from 'wdLogin/Index'
import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index'
import { AppInnerLink, registerRouter } from 'wdRouter/Index'
import { AppInnerLink,
AppLinkingManager,
registerRouter } from 'wdRouter/Index'
import { TrackingModule } from 'wdTracking/Index'
import { JSON } from '@kit.ArkTS'
import app from '@system.app'
...
...
@@ -78,6 +78,10 @@ export class StartupManager {
// 通知栏点击后启动
GetuiPush.sharedInstance().onWant(want)
// AppLinking拉起
AppLinkingManager.sharedInstance().onWant(want)
Logger.debug(TAG, "App onCreate: finised")
this.lastStartupWant = want
...
...
@@ -86,6 +90,9 @@ export class StartupManager {
appOnNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) {
GetuiPush.sharedInstance().onNewWant(want)
// AppLinking拉起
AppLinkingManager.sharedInstance().onNewWant(want)
this.dealWithDeepLink(want)
}
...
...
@@ -134,6 +141,9 @@ export class StartupManager {
GetuiPush.sharedInstance().onReachMainPage()
// AppLinking拉起
AppLinkingManager.sharedInstance().onReachMainPage()
//TODO:
// 提前初始化webview
webview.WebviewController.initializeWebEngine()
...
...
sight_harmony/products/phone/src/main/module.json5
View file @
8e9b2d6
...
...
@@ -39,17 +39,67 @@
"com.test.pushaction"
,
"ohos.want.action.viewData"
],
//
"uris"
:
[{
//
//
之前的
推送配置
"uris"
:
[
//
{
//
之前的
推送配置
//
"scheme"
:
'rmrbapp'
,
//
"host"
:
'rmrb.app'
,
//
'port'
:
'
8080
'
,
//
"path"
:
'openwith'
//
}]
//
"path"
:
'openwith'
}
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"rmharticle"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"rmhphotos"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"rmhmoments"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"rmhvideo"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"author"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"column"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"votetopic"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"articletopic"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"livetopic"
},
{
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"timelinetopic"
},
]
},
{
"uris"
:
[
{
//
配置
-
(播控中心
用)
{
//
推送配置
-
(播控中心共
用)
"scheme"
:
'rmrbapp'
,
"host"
:
'rmrb.app'
,
'port'
:
'
8080
'
,
...
...
@@ -60,16 +110,16 @@
"host"
:
"rmrb.app"
,
"path"
:
"openwith"
},
{
//
分享用
-
正式环境地址
"scheme"
:
"https"
,
"host"
:
"www.peopleapp.com"
,
"pathStartWith"
:
"column"
},
{
//
分享用
-
测试环境地址
"scheme"
:
"https"
,
"host"
:
"pd-people-uat.pdnews.cn"
,
"pathStartWith"
:
"column"
}
//
{
//
分享用
-
正式环境地址
//
"scheme"
:
"https"
,
//
"host"
:
"www.peopleapp.com"
,
//
"pathStartWith"
:
"column"
//
},
//
{
//
分享用
-
测试环境地址
//
"scheme"
:
"https"
,
//
"host"
:
"pd-people-uat.pdnews.cn"
,
////
"pathStartWith"
:
"column"
//
}
],
"domainVerify"
:
true
}
...
...
Please
register
or
login
to post a comment