InsightIntentShare.ets
7.07 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
import { common } from '@kit.AbilityKit';
import { insightIntent } from '@kit.IntentsKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { CompDTO, CompList, ContentDTO, PageInfoBean, ContentDetailDTO, InteractDataDTO } from 'wdBean';
function generateUUID() {
let dt = new Date().getTime(); // 获取当前时间的时间戳(毫秒)
let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
let r = (dt + Math.random() * 16) % 16 | 0;
dt = Math.floor(dt / 16);
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
}
export const enum ActionMode {
// 将来时
EXPECTED = 'EXPECTED',
// 完成时
EXECUTED = 'EXECUTED',
}
// 上报节目类型白名单
const shareWhiteList = ['1', '2', '8', '9', '14', '15'] //跳转类型:0:不跳转 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14动态图文,15动态视频 */
//ViewBlog意图共享-频道列表
export function viewBlogInsightIntentShare(context: common.UIAbilityContext, entityGroupId: string,
compList: CompDTO[] | CompList[], actionMode: ActionMode) {
console.log('viewBlogInsightIntentShare', actionMode)
let insightIntentArray: insightIntent.InsightIntent [] = []
let identifier = generateUUID()
if (compList?.length > 0) {
compList?.forEach((comp: CompDTO | CompList) => {
comp.operDataList.forEach((item: ContentDTO) => {
if (shareWhiteList.indexOf(item.objectType) > -1) {
let viewBlogInsightIntentItem: insightIntent.InsightIntent = {
intentName: 'ViewBlog',
intentVersion: '1.0.1',
identifier,
intentActionInfo: {
actionMode
},
intentEntityInfo: {
entityName: 'Blog',
entityId: `objectId=${item?.objectId}&objectType=${item?.objectType}` || '', //必传
displayName: item?.newsTitle || '', //必传
entityGroupId, //channelId
logoURL: item?.coverUrl || 'https://cdnjdphoto.aikan.pdnews.cn/WapApi/800/launcher_icon.png',
metadataModificationTime: Number(item?.publishTime) || 0, //int
blogTitle: item?.newsTitle,
blogType: 'Normal',
blogCategory: entityGroupId === '2001' ? '推荐' : '热点',
categoryDisplayName: item?.newsTitle, //卡片上的主标题
description: item?.newsSummary || '', //必传
blogSubTitle: item?.newsSummary.length > 20 ?
item?.newsSummary.substring(0, 20) : item?.newsSummary,
blogAuthor: item?.source,
blogPublishTime: item?.publishTime, //string
tag: item?.newTags.split(','),
likeCount: item?.interactData?.likeNum || 0,
forwardCount: item?.interactData?.shareNum || 0,
commentCount: item?.interactData?.commentNum || 0,
favorites: item?.interactData?.collectNum || 0,
viewCount: item?.interactData?.readNum || 0,
rankingHint: 99
}
}
insightIntentArray.push(viewBlogInsightIntentItem)
}
})
})
console.log('yzl', JSON.stringify(insightIntentArray[0]))
// 共享数据
insightIntent.shareIntent(context, insightIntentArray).then(() => {
console.log('yzl shareIntent success');
}).catch((err: BusinessError) => {
console.error(`yzl failed because ${err?.message}`);
});
}
}
//ViewBlog意图共享-节目详情 详情页上报
export function viewBlogItemInsightIntentShare(executedStartTime: number ,context: common.UIAbilityContext, item: ContentDetailDTO,
interactData?: InteractDataDTO) {
let identifier = generateUUID()
console.log('zzzz', JSON.stringify(item))
let executedEndTime: number = new Date().getTime()
let viewBlogInsightIntentItem: insightIntent.InsightIntent = {
intentName: 'ViewBlog',
intentVersion: '1.0.1',
identifier,
intentActionInfo: {
actionMode: ActionMode.EXECUTED,
executedTimeSlots: {
executedEndTime: executedEndTime,
executedStartTime: executedStartTime
}
},
intentEntityInfo: {
entityName: 'Blog',
entityId: `objectId=${item?.newsId}&objectType=${item?.newsType}` || '',
displayName: item?.newsTitle || '',
entityGroupId: String(item?.reLInfo?.channelId), //channelId
logoURL: item?.fullColumnImgUrls?.length > 0 ? item.fullColumnImgUrls[0]?.url :
item?.firstFrameImageUri || 'https://cdnjdphoto.aikan.pdnews.cn/WapApi/800/launcher_icon.png',
metadataModificationTime: new Date(item?.publishTime).getTime() || 0,
blogTitle: item?.newsTitle,
blogType: 'Normal',
blogCategory: item?.reLInfo?.channelId === 2001 ? '推荐' : '热点',
categoryDisplayName: item?.newsTitle || '',
blogSubTitle: item?.newsSummary?.length > 20 ?
item?.newsSummary.substring(0, 20) : item?.newsSummary,
description: item?.newsSummary || '', //必传
blogAuthor: item?.newsSourceName,
blogPublishTime: `${new Date(item?.publishTime).getTime()}` || '',
tag: item?.newsTags?.split(','),
viewCount: item?.viewCount || 0,
likeCount: interactData?.likeNum || 0,
forwardCount: interactData?.shareNum || 0,
commentCount: interactData?.commentNum || 0,
favorites: interactData?.collectNum || 0,
rankingHint: 99
}
}
console.log('yzl', JSON.stringify(viewBlogInsightIntentItem))
// 共享数据
insightIntent.shareIntent(context, [viewBlogInsightIntentItem]).then(() => {
console.log('yzl shareIntent success');
}).catch((err: BusinessError) => {
console.error(`yzl failed because ${err?.message}`);
});
}
//ViewColumn意图共享-早晚报
export function viewColumInsightIntentShare(executedStartTime: number ,context: common.UIAbilityContext, entityId: string,
pageInfoBean: PageInfoBean) {
console.log('viewColumInsightIntentShare')
let executedEndTime: number = new Date().getTime()
let viewColumInsightIntentItem: insightIntent.InsightIntent = {
intentName: 'ViewColumn',
intentVersion: '1.0.1',
identifier: generateUUID(),
intentActionInfo: {
actionMode: ActionMode.EXECUTED,
executedTimeSlots: {
executedEndTime: executedEndTime,
executedStartTime: executedStartTime
}
},
intentEntityInfo: {
entityName: 'Column',
entityId,
displayName: pageInfoBean?.topicInfo?.title,
description: pageInfoBean?.shareSummary,
logoURL: pageInfoBean?.shareCoverUrl || 'https://cdnjdphoto.aikan.pdnews.cn/WapApi/800/launcher_icon.png',
activityType: ['RecentViews'],
columnTitle: pageInfoBean?.topicInfo?.title,
columnSubTitle: pageInfoBean?.shareSummary,
rankingHint: 99
}
}
console.log('yzl viewColumInsightIntentShare', JSON.stringify(viewColumInsightIntentItem))
// 共享数据
insightIntent.shareIntent(context, [viewColumInsightIntentItem]).then(() => {
console.log('yzl shareIntent success');
}).catch((err: BusinessError) => {
console.error(`yzl failed because ${err?.message}`);
});
}