AppInnerLink.ets
2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { url } from '@kit.ArkTS'
import App from '@system.app'
import { Logger } from 'wdKit/Index'
const TAG = "AppInnerLink"
export class AppInnerLink {
static readonly INNER_LINK_PROTCOL = "rmrbapp:"
static readonly INNER_LINK_HOSTNAME = "rmrb.app"
static readonly INNER_LINK_PATHNAME = "openwith"
// 内链跳转
// 内链地址例如:rmrbapp://rmrb.app/openwith?type=article&subType=h5_template_article&contentId=30000762651&relId=500000038702&skipType=1&relType=1
static jumpWithLink(innerLink: string) {
let params = AppInnerLink.parseParams(innerLink)
if (!params) {
Logger.info(TAG, "跳转无效的链接地址 " + innerLink)
return
}
switch (params.skipType) {
case 1: {
AppInnerLink.jumpParams(params)
break
}
case 2: {
AppInnerLink.jumpNoParams(params)
break
}
case 3: {
AppInnerLink.jumpAppH5(params)
break
}
case 4: {
AppInnerLink.jumpOutH5(params)
break
}
case 5: {
AppInnerLink.jumpThirdApp(params)
break
}
default: {
Logger.info(TAG, "跳转无效的链接地址 " + innerLink)
}
}
}
private static jumpParams(params: InnerLinkParam) {
}
private static jumpNoParams(params: InnerLinkParam) {
}
private static jumpAppH5(params: InnerLinkParam) {
}
private static jumpOutH5(params: InnerLinkParam) {
}
private static jumpThirdApp(params: InnerLinkParam) {
}
static parseParams(link: string) : InnerLinkParam | undefined {
const that = url.URL.parseURL(link)
if (that.protocol !== AppInnerLink.INNER_LINK_PROTCOL) {
return
}
if (that.hostname !== AppInnerLink.INNER_LINK_HOSTNAME) {
return
}
if (that.pathname !== AppInnerLink.INNER_LINK_PATHNAME) {
return
}
let obj = {} as InnerLinkParam
const params = that.params
obj.type = params.get("type") as string
obj.subType = params.get("subType") as string
obj.contentId = params.get("contentId") as string
obj.relId = params.get("relId") as string
obj.relType = params.get("relType") as string
obj.pageId = params.get("pageId") as string
obj.url = params.get("url") as string
obj.activityId = params.get("activityId") as string
obj.activityType = params.get("activityType") as string
obj.creatorId = params.get("creatorId") as string
obj.firstChannelId = params.get("firstChannelId") as string
obj.skipType = Number(params.get("skipType"))
obj.isLogin = params.get("isLogin") as string
return obj
}
}
interface InnerLinkParam {
type?: string,
subType?: string,
contentId?: string,
relId?: string,
relType?: string
pageId?: string,
url?: string,
activityId?: string,
activityType?: string,
creatorId?: string,
firstChannelId?: string,
skipType: number,
isLogin?: string,
}