H5NewsWebPageComponent.ets
10.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
import {
Logger,
NumberFormatterUtils,
DateTimeUtils,
EmitterUtils,
EmitterEventId,
NetworkUtil,
} from 'wdKit';
import {
Action,
ContentDetailDTO,
ContentDTO,
postRecommendListParams,
postExecuteLikeParams,
batchLikeAndCollectResult,
batchLikeAndCollectParams,
InteractDataDTO,
contentListParams,
} from 'wdBean';
import { WdWebComponent } from 'wdWebComponent';
import DetailViewModel from '../viewmodel/DetailViewModel';
import router from '@ohos.router';
import { CommonConstants } from 'wdConstant'
import { BridgeWebViewControl } from 'wdJsBridge';
import { publishCommentModel } from '../components/comment/model/PublishCommentModel';
import { HttpUtils } from 'wdNetwork/Index';
import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { PageRepository } from '../repository/PageRepository';
import { OperRowListView } from './view/OperRowListView';
import { CommentDialogView } from './CommentDialogView';
import { CustomTitleUI } from 'wdcomponent/ets/components/reusable/CustomTitleUI';
const TAG = 'H5NewsWebPageComponent'
@Component
export struct H5NewsWebPageComponent {
@State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') as number;
@State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
webviewControl: BridgeWebViewControl = new BridgeWebViewControl()
scroller: Scroller = new Scroller();
action: Action = {} as Action
@State webUrl: string = '';
@Provide contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
@State recommendList: ContentDTO[] = []
@State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态
@State interactData: InteractDataDTO = {} as InteractDataDTO
@State isPageEnd: boolean = false
@State publishTime: string = ''
@State publishCommentModel: publishCommentModel = new publishCommentModel()
@State isNetConnected: boolean = true
@State emptyType: number = 1 // 缺省图类型
@State detailContentEmpty: boolean = false
@State info: Area | null = null
@State likeNum: number = 0
@State operationButtonList: string[] = []
@State showComment: boolean = false
@State showCommentList: boolean = false
@State index: number = 0
@State currentIndex: number = 0
private navTitle = '人民日报';
build() {
Stack({ alignContent: Alignment.Top }){
Stack(){
Column(){
CustomTitleUI({ titleName: this.navTitle })
WdWebComponent({
webviewControl: this.webviewControl,
webUrl: this.webUrl,
isPageEnd: $isPageEnd
})
}.width(CommonConstants.FULL_WIDTH)
.height(`calc(85% - ${ this.topSafeHeight + 'px'})`)
}
Stack(){
//底部交互区
OperRowListView({
contentDetailData: this.contentDetailData,
publishCommentModel: this.publishCommentModel,
operationButtonList: this.operationButtonList,
styleType: 1,
onCommentIconClick: () => {
this.showCommentList = true
}
})
}
.alignContent(Alignment.Top)
.position({y:'85%'})
.width(CommonConstants.FULL_WIDTH)
.backgroundColor(Color.White)
.height(150)
}
.margin({top: `${this.topSafeHeight}px`, bottom: `${this.bottomSafeHeight}px`})
.width(CommonConstants.FULL_WIDTH)
.height(CommonConstants.FULL_HEIGHT)
}
private async getDetail() {
this.isNetConnected = NetworkUtil.isNetConnected()
if (!this.isNetConnected) {
this.emptyType = 1
}
let contentId: string = ''
let relId: string = ''
let relType: string = ''
if (this.action && this.action.params) {
if (this.action.params.contentID) {
contentId = this.action.params.contentID;
}
if (this.action && this.action.params && this.action.params.extra) {
this.navTitle = this.action.params.extra.title
if (this.action.params.extra.relId) {
relId = this.action.params.extra.relId;
}
if (this.action.params.extra.relType) {
relType = this.action.params.extra.relType
}
}
let detailBeans = await DetailViewModel.getDetailPageData(relId, contentId, relType)
// 判断内容是否已下线,空数组表示下线
this.detailContentEmpty = detailBeans.length === 0 ? true : false
if (this.detailContentEmpty) {
this.emptyType = 18
}
console.log(TAG, "dl1111111111", JSON.stringify(detailBeans[0]))
if (detailBeans && detailBeans.length > 0) {
this.contentDetailData = detailBeans[0];
let dateTime =
DateTimeUtils.parseDate(this.contentDetailData?.publishTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN);
// let _publishTime = DateTimeUtils.formatDate(dateTime, PATTERN_DATE_CN_RN)
// this.publishTime = DateTimeUtils.removeTrailingZeros(_publishTime)
if (this.contentDetailData?.recommendShow === 1) {
this.getRecommend()
}
if (this.contentDetailData?.openLikes === 1) {
console.log(TAG, '点赞this.getInteractDataStatus()')
this.getInteractDataStatus()
this.queryContentInteractCount()
}
if (this.contentDetailData?.openComment) {
this.publishCommentModel.targetId = String(this.contentDetailData?.newsId || '')
this.publishCommentModel.targetRelId = String(this.contentDetailData?.reLInfo?.relId || '')
this.publishCommentModel.targetTitle = this.contentDetailData?.newsTitle
this.publishCommentModel.targetRelType = String(this.contentDetailData?.reLInfo?.relType || '')
this.publishCommentModel.targetRelObjectId = String(this.contentDetailData?.reLInfo?.relObjectId || '')
this.publishCommentModel.keyArticle = String(this.contentDetailData?.keyArticle || '')
this.publishCommentModel.targetType = String(this.contentDetailData?.newsType || '')
this.publishCommentModel.visitorComment = String(this.contentDetailData?.visitorComment || '')
}
this.operationButtonList = []
if ( this.contentDetailData.openComment === 1) {
this.operationButtonList.push('comment')
}
if (this.contentDetailData.openLikes === 1) {
this.operationButtonList.push('like')
}
if (this.contentDetailData?.openAudio && this.contentDetailData?.audioList?.length &&
this.contentDetailData?.audioList[0].audioUrl) {
this.operationButtonList.push('listen')
}
this.operationButtonList.push('collect')
if (this.contentDetailData.shareInfo?.shareOpen === 1) {
this.operationButtonList.push('share')
}
}
}
}
private async getRecommend() {
let params: postRecommendListParams = {
imei: HttpUtils.getImei(),
userId: HttpUtils.getUserId(),
contentId: String(this.contentDetailData?.newsId),
recType: 1,
contentType: this.contentDetailData?.newsType,
relId: this.contentDetailData?.reLInfo?.relId,
// channelId: String(this.contentDetailData?.reLInfo?.channelId)
}
let recommendList = await DetailViewModel.postRecommendList(params)
if (recommendList.length > 0) {
//推荐列表过滤音频和活动入口
this.recommendList = recommendList.filter(item => item.objectType !== '3' && item.objectType !== '13');
}
}
// 已登录->查询用户对作品点赞、收藏状态
private async getInteractDataStatus() {
try {
const params: batchLikeAndCollectParams = {
contentList: [
{
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType + '',
contentRelId: this.contentDetailData?.reLInfo?.relId || '' + '',
}
]
}
// console.log(TAG,'contentDetailData', JSON.stringify(params.contentList))
let data = await MultiPictureDetailViewModel.getInteractDataStatus(params)
console.log(TAG, '查询用户对作品点赞、收藏状态', JSON.stringify(data))
this.newsStatusOfUser = data[0];
// console.log(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`)
} catch (exception) {
console.error(TAG,'exception', JSON.stringify(exception))
}
}
/**
* 点赞、取消点赞
*/
toggleLikeStatus() {
// 未登录,跳转登录
if (!HttpUtils.getUserId()) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
const params: postExecuteLikeParams = {
status: this.newsStatusOfUser?.likeStatus == '1' ? '0' : '1',
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType + '',
contentRelId: this.contentDetailData?.reLInfo?.relId || '' + '',
}
console.log(TAG, '点赞、取消点赞params', JSON.stringify(params))
PageRepository.postExecuteLike(params).then(res => {
// console.log(TAG, '点赞、res', JSON.stringify(res))
console.log(TAG, '点赞、取消点赞 this.newsStatusOfUser', JSON.stringify(this.newsStatusOfUser))
if (this.newsStatusOfUser) {
//内容点赞、取消点赞Tracking 1点赞 0取消点赞
this.newsStatusOfUser.likeStatus = this.newsStatusOfUser?.likeStatus == '1' ? '0' : '1'
if (this.newsStatusOfUser.likeStatus === '1') {
this.likeNum = Number(this.likeNum) + 1
} else {
this.likeNum = Number(this.likeNum) - 1
}
console.log(TAG, '点赞newsStatusOfUser.likeStatus ', this.newsStatusOfUser.likeStatus)
// this.queryContentInteractCount()
// TrackingContent.like(this.newsStatusOfUser?.likeStatus == '1', TrackConstants.PageName.My, TrackConstants.PageName.My)
} else {
// 初次进入详情页偶现获取失败,重新获取newsStatusOfUser对象
this.getInteractDataStatus()
}
})
}
/**
* 查询点赞、收藏数量
*/
queryContentInteractCount() {
console.error(TAG, 'contentDetailData2222', JSON.stringify(this.contentDetailData))
const params: contentListParams = {
contentList: [{
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType,
}]
}
PageRepository.getContentInteract(params).then(res => {
console.error(TAG, 'queryContentInteractCount', JSON.stringify(res))
if (res.data) {
this.interactData = res.data[0]
this.likeNum = Number(res.data[0]?.likeNum) || 0
}
})
}
aboutToAppear() {
let action: Action = router.getParams() as Action
if (action) {
this.webUrl = action.params?.url || ''
}
this.getDetail()
// 登录成功
EmitterUtils.receiveEvent(EmitterEventId.LOGIN_SUCCESS, () => {
this.getInteractDataStatus()
})
}
}