InsightIntentShare.ets
6 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
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',
}
//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((item: CompDTO | CompList) => {
item.operDataList.forEach((_item: ContentDTO) => {
let viewBlogInsightIntentItem: insightIntent.InsightIntent = {
intentName: 'ViewBlog',
intentVersion: '1.0.1',
identifier,
intentActionInfo: {
actionMode,
currentPercentage: 50,
//目前不考虑发生时段
// executedTimeSlots: {
// executedEndTime: new Date().getTime(),
// executedStartTime: pageModel.executedStartTime
// }
},
intentEntityInfo: {
entityName: 'Blog',
entityId: _item?.objectId,
displayName: _item?.newsTitle,
entityGroupId, //channelId
logoURL: _item?.coverUrl,
metadataModificationTime: _item?.publishTimestamp,
blogTitle: _item?.newsTitle,
blogType: 'Normal',
blogCategory: item.name,
categoryDisplayName: item.name,
blogSubTitle: _item?.newsSummary.length > 20 ?
_item?.newsSummary.substring(0, 20) : _item?.newsSummary,
blogAuthor: _item?.source,
blogPublishTime: _item?.publishTimestamp,
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,
isPublicData: true
}
}
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(context: common.UIAbilityContext, item: ContentDetailDTO,
interactData?: InteractDataDTO) {
let identifier = generateUUID()
let viewBlogInsightIntentItem: insightIntent.InsightIntent = {
intentName: 'ViewBlog',
intentVersion: '1.0.1',
identifier,
intentActionInfo: {
actionMode: ActionMode.EXECUTED,
currentPercentage: 50,
},
intentEntityInfo: {
entityName: 'Blog',
entityId: String(item?.newsId),
displayName: item?.newsTitle,
entityGroupId: String(item?.reLInfo?.channelId), //channelId
logoURL: item.fullColumnImgUrls.length > 0 ? item.fullColumnImgUrls[0]?.url : item.firstFrameImageUri,
metadataModificationTime: item?.publishTime,
blogTitle: item?.newsTitle,
blogType: 'Normal',
blogCategory: item,
categoryDisplayName: '', //TODO 分类名称
blogSubTitle: item?.newsSummary.length > 20 ?
item?.newsSummary.substring(0, 20) : item?.newsSummary,
blogAuthor: item?.newsSourceName,
blogPublishTime: item?.publishTime,
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,
isPublicData: true
}
}
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(context: common.UIAbilityContext, entityId: string,
pageInfoBean: PageInfoBean) {
console.log('viewColumInsightIntentShare')
let viewColumInsightIntentItem: insightIntent.InsightIntent = {
intentName: 'ViewColumn',
intentVersion: '1.0.1',
identifier: generateUUID(),
intentActionInfo: {
actionMode: ActionMode.EXECUTED,
currentPercentage: 50,
},
intentEntityInfo: {
entityName: 'Column',
entityId,
displayName: pageInfoBean?.topicInfo?.title,
description: pageInfoBean?.shareSummary,
logoURL: pageInfoBean?.shareCoverUrl,
activityType: ['RecentViews'],
columnTitle: pageInfoBean?.topicInfo?.title,
columnSubTitle: pageInfoBean?.shareSummary,
rankingHint: 99,
isPublicData: true
}
}
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}`);
});
}