JsBridgeBiz.ets
4.25 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
import { Callback } from 'wdJsBridge';
import { Message } from 'wdJsBridge/src/main/ets/bean/Message';
import { Logger } from 'wdKit';
import { H5CallNativeType } from './H5CallNativeType';
import { H5OperateType } from './H5OperateType';
import { ContentConstants } from 'wdConstant';
import { ProcessUtils } from 'wdRouter';
import router from '@ohos.router';
import Url from '@ohos.url'
import { ContentDTO } from 'wdBean/Index';
const TAG = 'JsBridgeBiz'
class AppInfo {
plat: string = ''
system: string = ''
networkStatus: number = 1
// TODO 完善
}
/**
* h5调用native代码
* @param data
* @param call
*/
export function performJSCallNative(data: Message, call: Callback) {
Logger.debug(TAG, 'performJSCallNative handlerName: ' + data.handlerName + ', data: ' + JSON.stringify(data.data))
switch (data.handlerName) {
case H5CallNativeType.jsCall_currentPageOperate:
handleJsCallCurrentPageOperate(data)
break;
case H5CallNativeType.jsCall_getAppPublicInfo:
// h5获取app配置信息
call(getAppPublicInfo())
break;
case H5CallNativeType.jsCall_getArticleDetailBussinessData:
break;
case H5CallNativeType.jsCall_callAppService:
handleJsCallCallAppService(data)
break;
case H5CallNativeType.jsCall_receiveH5Data:
handleJsCallReceiveH5Data(data)
break;
case H5CallNativeType.jsCall_appInnerLinkMethod:
handleJsCallAppInnerLinkMethod(data)
break;
default:
break;
}
}
function handleJsCallCurrentPageOperate(data: Message) {
switch (data?.data?.operateType) {
case H5OperateType.TYPE_ONE:
router.back()
break;
default:
break;
}
}
/**
* 获取App公共信息
*/
function getAppPublicInfo(): string {
let info = new AppInfo()
info.plat = 'Phone'
// 直接用Android,后续适配再新增鸿蒙
info.system = 'Android'
info.networkStatus = 1
let result = JSON.stringify(info)
Logger.debug(TAG, 'getAppPublicInfo: ' + JSON.stringify(info))
return result;
}
function handleJsCallReceiveH5Data(data: Message) {
switch (data?.data?.dataSource) {
case 5:
if (data?.data?.dataSource === 5) {
ProcessUtils.processPage(JSON.parse(data?.data?.dataJson || '{}'))
}
break;
default:
break;
}
}
function handleJsCallCallAppService(data: Message) {
}
function handleJsCallAppInnerLinkMethod(data: Message) {
let urlObject = Url.URL.parseURL(data?.data?.appInnerLink);
let urlParams = new Url.URLParams(urlObject.search);
console.log('urlObject:', `${JSON.stringify(urlParams)}`)
let content: ContentDTO = {
objectId: urlParams.get('contentId') || '',
relId: urlParams.get('relId') || '',
relType: urlParams.get('relType') || '',
pageId:urlParams.get('pageId') || '',
objectType: ''
} as ContentDTO
if (urlParams.get('skipType') === '1') {
switch (urlParams.get('type')) {
case 'video':
content.objectType = ContentConstants.TYPE_VOD
ProcessUtils.processPage(content)
break;
case 'live':
content.objectType = ContentConstants.TYPE_LIVE
ProcessUtils.processPage(content)
break;
case 'article':
content.objectType = ContentConstants.TYPE_TELETEXT
ProcessUtils.processPage(content)
break;
case 'picture':
content.objectType = ContentConstants.TYPE_NINE
ProcessUtils.processPage(content)
break;
case 'audio':
content.objectType = ContentConstants.TYPE_AUDIO
ProcessUtils.processPage(content)
break;
case 'h5':
content.objectType = ContentConstants.TYPE_LINK
ProcessUtils.processPage(content)
break;
case 'topic':
if(urlParams.get('subType') === 'h5'){
content.objectType = ContentConstants.TYPE_SPECIAL_TOPIC
ProcessUtils.processPage(content)
}
if(urlParams.get('subType') === 'moring_evening_news'){
ProcessUtils.gotoMorningEveningPaper()
}
if(urlParams.get('subType') === 'electronic_newspapers'){
ProcessUtils.gotoENewsPaper()
}
break;
case 'dynamic':
content.objectType = ContentConstants.TYPE_FOURTEEN
ProcessUtils.processPage(content)
break;
default:
break;
}
}
}