ProcessUtils.ets
18.8 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
import { Action, ContentDTO, Params, PhotoListBean, commentInfo, CompDTO } from 'wdBean';
import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO';
import { Logger, NetworkUtil, SPHelper, ToastUtils } from 'wdKit';
import { StringUtils } from 'wdKit/src/main/ets/utils/StringUtils';
import { WDRouterRule, WDRouterPage } from '../../../../Index';
import { ContentConstants, SpConstants } from 'wdConstant';
import { common, Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { CompAdvMatInfoBean } from 'wdBean/src/main/ets/bean/adv/CompAdvInfoBean';
import { AdvertsBean } from 'wdBean/src/main/ets/bean/adv/AdvertsBean';
import HomeChannelUtils from './HomeChannelUtils';
const TAG = 'ProcessUtils';
/**
* 页面跳转业务封装
*/
export class ProcessUtils {
/**
* 广告中心的业务广告跳转方法( 现用在挂角广告、信息流页面广告)
* @param advContent
*/
static openAdvDetail(matInfo: CompAdvMatInfoBean) {
if (matInfo == null) {
return;
}
// 优先openType,再取linkType
let type: string;
if (!StringUtils.isEmpty(matInfo.openType)) {
type = matInfo.openType;
} else {
type = matInfo.linkType;
}
if ('0' == type) {
// 0 :无链接
return;
}
let linkUrl: string = matInfo.linkUrl;
if (StringUtils.isEmpty(linkUrl)) {
return;
}
if ('1' == type) {
// 内链
let content: ContentDTO = new ContentDTO();
content.linkUrl = linkUrl;
ProcessUtils.gotoWeb(content);
} else if ('2' == type) {
// 外链
ProcessUtils.jumpExternalWebPage(linkUrl);
}
}
/**
* 展现中心的广告跳转 ( 现用在挂角广告)
* @param advert 展现中心的展现广告
*/
static advJumpMainPage(advert: AdvertsBean) {
let content: ContentDTO = new ContentDTO()
content.linkUrl = advert.linkUrl;
content.pageId = advert.pageId;
content.objectId = advert.objectId;
content.objectType = advert.objectType.toString();
content.relId = advert.relId;
content.bottomNavId = advert.bottomNavId;
ProcessUtils.processPage(content);
}
//更多
static compJumpPage(bean:CompDTO){
let contentBean = ProcessUtils.compBeanToContentBean(bean)
if(contentBean == null){
return
}
if(ProcessUtils.checkMoreJumpPage(bean)){
ProcessUtils.processPage(contentBean)
}else{
ProcessUtils.moreTojumpLivePage(contentBean);
}
}
static moreTojumpLivePage(contentBean:ContentDTO){
if(!StringUtils.isEmpty(contentBean.dataSourceType)){
if(contentBean.dataSourceType == 'LIVE_HORIZONTAL_CARD') {
//直播中
WDRouterRule.jumpWithPage(WDRouterPage.liveMorePage)
}else if(contentBean.dataSourceType == 'LIVE_RESERVATION'){
//预约列表
WDRouterRule.jumpWithPage(WDRouterPage.reserveMorePage)
}else if(contentBean.dataSourceType == 'LIVE_MONTHLY_RANKING'){
contentBean.objectType = '6'
ProcessUtils.processPage(contentBean)
}
}
}
static checkMoreJumpPage(content:CompDTO){
let loacalJump = true
if(content.dataSourceType == 'LIVE_HORIZONTAL_CARD'){
loacalJump = false
}else if(content.dataSourceType == 'LIVE_RESERVATION'){
loacalJump = false
}else if(content.dataSourceType == 'LIVE_MONTHLY_RANKING'){
loacalJump = false
}
return loacalJump
}
static compBeanToContentBean(compDTO:CompDTO){
if(compDTO == null){
return
}
let content = new ContentDTO()
content.objectType = compDTO.objectType||'0'
content.objectLevel = compDTO.objectLevel
content.objectId = compDTO.objectId
content.pageId = compDTO.pageId||''
content.newsTitle = compDTO.objectTitle
content.newsSummary = compDTO.objectSummary
// compContentBean.setTopicInfoBean(getTopicInfoBean());
// compContentBean.setChannelInfoBean(getChannelInfoBean());
content.bottomNavId = compDTO.bottomNavId
content.sourceInterfaceVal = compDTO.sourceInterfaceVal
content.dataSourceType = compDTO.dataSourceType
content.compId = compDTO.id+''
content.linkUrl = compDTO.linkUrl
content.appStyle = compDTO.appStyle
content.recommend = compDTO.recommend
content.expIds = compDTO.expIds
content.relId = compDTO.relId
content.relType = compDTO.relType
content.itemId = compDTO.itemId
content.itemType = compDTO.itemType
content.sceneId = compDTO.sceneId
content.traceId = compDTO.traceId
content.traceInfo = compDTO.traceInfo
return content
}
static commentBeanToContentBean(comment:commentInfo){
if(comment == null){
return
}
let content = new ContentDTO()
content.objectType = comment.objectType||'0'
content.objectLevel = comment.objectLevel
content.objectId = comment.newsId
content.pageId = comment.pageId||''
content.newsTitle = comment.newsTitle
content.linkUrl = comment.linkUrl
content.relId = comment.relId
content.relType = comment.relType
content.commentInfo = comment
content.customParamTargetLayout = "comment"
return content
}
/**
* 页面跳转
*/
static processPage(content: ContentDTO) {
if (content == null) {
Logger.error(TAG, "processPage, content is null");
return;
}
if (StringUtils.isEmpty(content.objectType)) {
Logger.error(TAG, "processPage, objectType is empty");
return;
}
// 网络出小差了,请检查网络后重试
// let netStatus = NetworkUtil.isNetConnected()
// if(!netStatus){
// ToastUtils.shortToast('网络出小差了,请检查网络后重试')
// return
// }
let type = content.objectType;
if (typeof type == "number") {
type = `${type}`
}
console.log(TAG, 'objectType', `${JSON.stringify(content)}`);
switch (type) {
case ContentConstants.TYPE_NONE:
Logger.debug(TAG, "processPage, do nothing");
break;
case ContentConstants.TYPE_VOD:
Logger.debug(TAG, "processPage, nonsupport!!!");
ProcessUtils.gotoVod(content)
break;
case ContentConstants.TYPE_LIVE:
ProcessUtils.gotoLive(content)
break
case ContentConstants.TYPE_FOUR:
ProcessUtils.gotoDefaultWeb(content);
break
case ContentConstants.TYPE_AUDIO:
ProcessUtils.gotoAudio(content)
break;
case ContentConstants.TYPE_TELETEXT:
ProcessUtils.gotoWeb(content);
break;
case ContentConstants.TYPE_Activity:
// 图文详情,跳转h5
if (content?.linkUrl) { //有 linkUrl 走专题页展示逻辑
ProcessUtils.gotoSpecialTopic(content, true)
} else {
ProcessUtils.gotoWeb(content);
}
break;
case ContentConstants.TYPE_LINK:
content.openType = "1"
ProcessUtils.gotoDefaultWeb(content);
break;
//图集详情页
case ContentConstants.TYPE_NINE:
ProcessUtils.gotoAtlasDetailPage(content);
break;
case ContentConstants.TYPE_SPECIAL_TOPIC:
// 专题详情,跳转h5
ProcessUtils.gotoSpecialTopic(content);
break;
case ContentConstants.TYPE_CHANNEL:
// 频道跳转
HomeChannelUtils.jumpChannelTab(content.objectId, content.pageId, content.newsTitle)
break;
//动态详情页(动态图文)
case ContentConstants.TYPE_FOURTEEN:
ProcessUtils.gotoDynamicDetailPage(content);
break;
//动态详情页(动态视频)
case ContentConstants.TYPE_FIFTEEN:
ProcessUtils.gotoDynamicDetailPage(content);
break;
case ContentConstants.TYPE_THIRTY:
ProcessUtils.gotoThemeListPage(content)
break;
default:
ToastUtils.shortToast('敬请期待')
break;
}
}
/**
* 动态详情页(动态视频/动态图片)
* @param content
* */
public static gotoDynamicDetailPage(content: ContentDTO) {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: Number.parseInt(content.objectType),
contentID: content?.objectId,
extra: {
relType: content?.relType,
relId: content?.relId,
sourcePage: '5',
commentId: content?.commentInfo?.commentId
} as ExtraDTO,
targetLayout: content.customParamTargetLayout
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
Logger.debug(TAG, `gotoDynamicDetailPage, ${content.objectId}`);
}
/**
* 图集详情页
* @param content
* */
public static gotoMultiPictureListPage(photoList: PhotoListBean[], swiperIndex?: number) {
let tempP = [] as PhotoListBean[]
let relIndex = 0;
for (let index = 0; index < photoList.length; index++) {
const element = photoList[index];
if (!StringUtils.isEmpty(element.picPath)) {
relIndex = relIndex + 1
}
}
tempP.length = relIndex
relIndex = 0
for (let index = 0; index < photoList.length; index++) {
const element = photoList[index];
if (!StringUtils.isEmpty(element.picPath)) {
tempP[relIndex] = element
relIndex = relIndex + 1
}
}
photoList.length = tempP.length
photoList = tempP
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: 18,
extra: {
photoList,
swiperIndex
} as ExtraDTO
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
Logger.debug(TAG, `gotoMultiPictureListPage`);
}
public static _gotoSpecialTopic(linkUrl: string) {
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
url: linkUrl,
pageID: 'SPACIAL_TOPIC_PAGE',
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
public static gotoSpecialTopic(content: ContentDTO, backVisibility?: boolean) {
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
contentID: content?.objectId,
url: content.linkUrl,
pageID: 'SPACIAL_TOPIC_PAGE',
backVisibility: backVisibility,
extra: {
relType: content?.relType,
relId: content?.relId,
channelId: content?.channelId,
pageId: content?.pageId,
sourcePage: '5',
commentId: content?.commentInfo?.commentId
} as ExtraDTO,
targetLayout: content.customParamTargetLayout
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
public static _gotoDefaultWeb(linkUrl: string) {
let taskAction: Action = {
type: 'JUMP_H5_BY_WEB_VIEW',
params: {
url: linkUrl,
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
public static gotoDefaultWeb(content: ContentDTO) {
// 内链
if (content.openType == '1') {
let taskAction: Action = {
type: 'JUMP_H5_BY_WEB_VIEW',
params: {
url: content.linkUrl,
extra: {
sourcePage: '5',
commentId: content?.commentInfo?.commentId
} as ExtraDTO
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
} else if (content.openType == '2') {
// 外链
ProcessUtils.jumpExternalWebPage(content.linkUrl);
} else {
// 无需跳转
}
Logger.debug(TAG, `gotoWeb, ${content.objectId}`)
}
static commentGotoWeb(content: commentInfo) {
let contentBean = ProcessUtils.commentBeanToContentBean(content)
if(contentBean == null){
return
}
ProcessUtils.processPage(contentBean)
// let taskAction: Action = {
// type: 'JUMP_INNER_NEW_PAGE',
// params: {
// contentID: content?.newsId,
// url:content?.linkUrl,
// pageID: 'IMAGE_TEXT_DETAIL',
// extra: {
// relType: content?.relType,
// relId: content?.relId,
// sourcePage: '5',
// commentId: content?.commentId
// } as ExtraDTO
// } as Params,
// };
// WDRouterRule.jumpWithAction(taskAction)
// Logger.debug(TAG, `commentGotoWeb, ${content.newsId}`);
}
public static gotoWeb(content: ContentDTO) {
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
contentID: content?.objectId,
//fixme 图文外链,需要单独处理
url:content?.linkUrl,
pageID: 'IMAGE_TEXT_DETAIL',
extra: {
relType: content?.relType,
relId: content?.relId,
channelId: content?.channelId,
sourcePage: '5',
commentId: content?.commentInfo?.commentId
} as ExtraDTO,
targetLayout: content.customParamTargetLayout
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
Logger.debug(TAG, `gotoWeb, ${content.objectId}`);
}
public static gotoVod(content: ContentDTO) {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: 1,
contentID: content?.objectId,
extra: {
relType: content?.relType,
relId: content?.relId,
sourcePage: '5',
commentId: content?.commentInfo?.commentId
} as ExtraDTO,
targetLayout: content.customParamTargetLayout
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
Logger.debug(TAG, `gotoVod, ${content.objectId}`);
}
/**
* 进入直播详情页面
* @param content
*/
public static async gotoLive(content: ContentDTO) {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: 2,
contentID: content?.objectId,
extra: {
relType: content?.relType,
relId: content?.relId,
sourcePage: '5',
commentId: content?.commentInfo?.commentId
} as ExtraDTO
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
Logger.debug(TAG, `gotoLive, ${content.objectId}`);
}
//音频详情页
public static gotoAudio(content: ContentDTO) {
ToastUtils.shortToast('该音频类型暂不支持')
// let taskAction: Action = {
// type: 'JUMP_DETAIL_PAGE',
// params: {
// detailPageType: 13,
// contentID: content?.objectId,
// extra: {
// relType: content?.relType,
// relId: content?.relId,
// } as ExtraDTO,
// targetLayout: content.customParamTargetLayout
// } as Params,
// };
// WDRouterRule.jumpWithAction(taskAction)
Logger.debug(TAG, `gotoAudio, ${content.objectId}`);
}
/**
* 金刚位聚合页
* @param content
* */
public static gotoThemeListPage(content: ContentDTO) {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: 30,
contentID: content?.objectId,
extra: {
relType: content?.relType,
relId: content?.relId,
extra: content?.extra,
title: content?.newsTitle,
sourcePage: '5',
commentId: content?.commentInfo?.commentId
} as ExtraDTO
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
Logger.debug(TAG, `gotoAtlasDetailPage, ${content.objectId}`);
}
/**
* 图片预览页
* @param content
* */
public static gotoAtlasDetailPage(content: ContentDTO) {
let taskAction: Action = {
type: 'JUMP_DETAIL_PAGE',
params: {
detailPageType: 9,
contentID: content?.objectId,
extra: {
relType: content?.relType,
relId: content?.relId,
sourcePage: '5',
commentId: content?.commentInfo?.commentId
} as ExtraDTO,
targetLayout: content.customParamTargetLayout
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
Logger.debug(TAG, `gotoAtlasDetailPage, ${content.objectId}`);
}
/**
* 打开外链
* @param url 外链地址
*/
public static jumpExternalWebPage(url: string) {
let context = getContext() as common.UIAbilityContext;
let wantInfo: Want = {
action: 'ohos.want.action.viewData',
entities: ['entity.system.browsable'],
uri: url
}
context.startAbility(wantInfo).then(() => {
Logger.debug(TAG, 'jumpExternalWebPage success')
}).catch((err: BusinessError) => {
Logger.error(TAG, 'jumpExternalWebPage success, error: ' + JSON.stringify(err))
})
}
/**
* 打开端内web页面
* @param url web地址
*/
public static gotoDefaultWebPage(url: string) {
let taskAction: Action = {
type: 'JUMP_H5_BY_WEB_VIEW',
params: {
url: url,
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
/**
* 打开早晚报
*/
public static gotoMorningEveningPaper() {
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
pageID: 'MorningEveningPaper'
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
/**
* 打开电子报
*/
public static gotoENewsPaper() {
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
pageID: 'E_NEWSPAPER'
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
/**
* 打开播报
*/
public static gotoBroadcastPage(pageId: number) {
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
pageID: 'BroadcastPage',
id: pageId
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
/**
* 切换到指定频道
*
* @param channelId 频道id【顶导id】
*/
public static jumpChannelTab(channelId: string, pageId: string, pageName?: string) {
HomeChannelUtils.jumpChannelTab(channelId, pageId, pageName)
}
/**
* 跳转人民号主页
* @param creatorId 创作者id
* @param banControl 是否封禁可以查看号主页 0 可以,1不可以
* @param mainControl 中文端账号是否拥有主页展示权限:0-未拥有,1-拥有
* @param userId 用户id
* @param userType 用户类型 1: 普通用户,2: 创作者 3: 矩阵号 4:运营子账号 5:内容源账号
*/
public static gotoPeopleShipHomePage(creatorId: string, banControl?: number, mainControl?: number, userId?: string,
userType?: string) {
let params = { 'creatorId': creatorId } as Record<string, string>;
WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params)
}
/**
* 意见反馈
*/
public static async gotoFeedBackActivity() {
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
let taskAction: Action = {
type: 'JUMP_INNER_NEW_PAGE',
params: {
pageID: 'FeedBackActivity'
} as Params,
};
WDRouterRule.jumpWithAction(taskAction)
}
/**
* 跳转到登录页
*/
public static gotoLoginPage() {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
}
}