AppInnerLink.ets
6.3 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import { url } from '@kit.ArkTS'
import { RetryHolderManager } from '@ohos/imageknife/src/main/ets/components/imageknife/holder/RetryHolderManager'
import App from '@system.app'
import { Action, Params } from 'wdBean/Index'
import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO'
import { Logger } from 'wdKit/Index'
import { ContentType } from '../common/ContentType'
import { WDRouterRule } from '../router/WDRouterRule'
import { ProcessUtils } from './ProcessUtils'
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) : boolean {
let params = AppInnerLink.parseParams(innerLink)
if (!params) {
Logger.info(TAG, "跳转无效的链接地址 " + innerLink)
return false
}
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)
return false
}
}
return true
}
private static jumpParams(params: InnerLinkParam) {
if (!AppInnerLink.validTypes(params.type)) {
return
}
const contentType = AppInnerLink.contentTypeWithType(params.type)
if (params.type == "article") {
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
contentID: params.contentId,
pageID: 'IMAGE_TEXT_DETAIL',
extra: {
relType: params.relType,
relId: params.relId,
sourcePage: '5', // ???
} as ExtraDTO
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
return
}
if (params.type == "video"
|| params.type == "dynamic"
|| params.type == "live"
|| params.type == "audio"
|| params.type == "picture") {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: contentType,
contentID: params.contentId,
extra: {
relType: params.relType,
relId: params.relId,
} as ExtraDTO
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
return
}
if (params.type == "owner_page" && params.creatorId) {
ProcessUtils.gotoPeopleShipHomePage(params.creatorId)
return
}
if (params.type == "topic" && params.subType == "h5") {
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
contentID: params.pageId,
url: params.url,
pageID: 'SPACIAL_TOPIC_PAGE',
backVisibility: true,
extra: {
relType: params.relType,
relId: params.relId,
pageId: params.pageId
} as ExtraDTO,
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
if (params.type == "channel") {
}
}
private static contentTypeWithType(type?: string) : number | undefined {
switch (type) {
case "video": return ContentType.Video
case "dynamic": return ContentType.DynamicImageText
case "live": return ContentType.Live
case "audio": return ContentType.Audio
case "picture": return ContentType.Pictures
case "article": return ContentType.ImageText
case "ask": return ContentType.Ask
}
return
}
private static validTypes(type?: string) : boolean {
if (!type) {
return false
}
let typeArray = ["article", "dynamic", "live", "video", "topic", "audio", "ask", "picture", "owner_page", "topic", "channel"]
return typeArray.indexOf(type) != -1
}
private static jumpNoParams(params: InnerLinkParam) {
if (!params.type || params.type != "app" || !params.subType) {
return
}
if (params.subType == "login") {
ProcessUtils.gotoLoginPage();
} else if (params.subType == "search") {
} else if (params.subType == "home") {
} else if (params.subType == "mine") {
}
}
private static jumpAppH5(params: InnerLinkParam) {
if (params.type && params.type == "h5" && params.url) {
ProcessUtils.gotoDefaultWebPage(params.url);
}
}
private static jumpOutH5(params: InnerLinkParam) {
if (params.type && params.type == "h5" && params.url) {
ProcessUtils.jumpExternalWebPage(params.url);
}
}
private static jumpThirdApp(params: InnerLinkParam) {
//TODO:
}
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,
}