PeopleShipMainComponent.ets
19.1 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
import { PeopleShipRecommendComponent } from './PeopleShipRecommendComponent';
import { PeopleShipMainViewModel } from '../../viewmodel/PeopleShipMainViewModel';
import { HttpUtils } from 'wdNetwork/Index';
import { Logger, DateTimeUtils, EmitterEventId, EmitterUtils, ToastUtils, UserDataLocal, StringUtils } from 'wdKit';
import { autoRefresh, onActionEnd, onActionStart, onActionUpdate,closeRefresh } from '../../utils/NewPullDownRefresh';
import {
RmhRecommendDTO,
ContentDTO,
AttentionBatchDTO,
CreatorDTO,
contentListParams,
InteractDataDTO,
CompDTO
} from 'wdBean';
import { ViewType } from 'wdConstant/src/main/ets/enum/ViewType';
import { channelSkeleton } from '../skeleton/channelSkeleton'
import { EmptyComponent } from '../view/EmptyComponent';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'
import MinePageDatasModel from '../../model/MinePageDatasModel';
import { FollowListDetailRequestItem } from '../../viewmodel/FollowListDetailRequestItem';
import { FollowListDetailItem } from '../../viewmodel/FollowListDetailItem';
import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh';
import PageModel from '../../viewmodel/PageModel';
import PageAdModel from '../../viewmodel/PageAdvModel';
import { PeopleShipAttentionContentListTopComponent } from './PeopleShipAttentionContentListTopComponent'
import { CardParser } from '../CardParser'
import { PeopleShipNoMoreData } from '../reusable/PeopleShipNoMoreData';
import PageFollowHelper from '../../viewmodel/PageFollowHelper';
import { MineFollowListItem } from '../../viewmodel/MineFollowListItem';
import { GrayManageModel } from '../../viewmodel/GrayManageModel';
import RefreshLayout from '../refresh/RefreshLayout';
import { RefreshLayoutBean } from '../refresh/RefreshLayoutBean';
import { CommonConstants } from 'wdConstant';
import PageNoMoreLayout from '../page/PageNoMoreLayout';
import LoadMoreLayout from '../page/LoadMoreLayout';
import { NoMoreBean } from '../page/NoMoreBean';
const TAG = 'PeopleShipMainComponent';
/**
* 人民号 --- 关注
*/
@Component
export struct PeopleShipMainComponent {
@State private pageModel: PageModel = new PageModel();
// 自动刷新通知
@Prop @Watch('onAutoRefresh') autoRefresh: number = 0
navIndex: number = 0;
pageId: string = "";
channelId: string = "";
@Link @Watch('onChange') currentTopNavSelectedIndex: number
// private scroller: Scroller = new Scroller()
private listScroller: Scroller = new Scroller()
@State rmhList: RmhRecommendDTO[] = []
@Provide rmhSelectedList: string[] = []
@State viewType: ViewType = ViewType.LOADING
// 一键关注处理
@State @Watch('onOneFollowChange') oneKeyFollow: boolean = false
// 已经关注的列表
@State followList: FollowListDetailItem[] = []
// 换一换
@State @Watch('onChangeButtonClick') changeButton: boolean = false
@State attentionList: ContentDTO[] = []
@State private hasMore: boolean = true
@State private currentPage: number = 1
@State private isLoading: boolean = false
@State private loadTime: string = ''
// 页面展示监听
@Consume @Watch('onPageShowChange') pageShow: number
@State private pageAttentionChange: boolean = false
// 国殇灰度管理
GrayManage: SubscribedAbstractProperty<GrayManageModel> = AppStorage.link<GrayManageModel>('GrayManage')
private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down })
///刷新请求
onRefresh: () => void = () => {
this.currentPage = 1
this.getData()
}
onRefreshMore: () => void = () => {
this.currentPage++;
this.getAttentionContentListData()
}
build() {
Column(){
if (this.viewType == ViewType.LOADING) {
this.LoadingLayout()
}
else if (this.viewType == ViewType.ERROR) {
//缺省页
EmptyComponent({
emptyType: this.pageModel.emptyType,
emptyButton: true,
retry: () => {
this.getData()
}
})
.grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
} else if (this.viewType == ViewType.EMPTY) {
// //缺省页
EmptyComponent({
emptyType: this.pageModel.emptyType,
emptyButton: true,
retry: () => {
this.getData()
}
})
.grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
}
else {
if (this.followList.length == 0) {
this.ListLayout()
} else {
this.ListAttentionLayout()
}
}
}
.parallelGesture(
PanGesture(this.panOption)
.onActionStart((event?: GestureEvent) => {
this.pageModel.isVisiblePullDown = true
onActionStart(this.pageModel, event)
})
.onActionUpdate((event?: GestureEvent) => {
onActionUpdate(this.pageModel, event,this.onRefreshMore)
})
.onActionEnd(() => {
onActionEnd(this.pageModel,this.onRefresh)
})
)
// if (this.viewType == ViewType.LOADING) {
// this.LoadingLayout()
// } else if (this.viewType == ViewType.ERROR) {
// //缺省页
// EmptyComponent({
// emptyType: this.pageModel.emptyType,
// emptyButton: true,
// retry: () => {
// this.getData()
// }
// })
// .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
// } else if (this.viewType == ViewType.EMPTY) {
// //缺省页
// EmptyComponent({
// emptyType: this.pageModel.emptyType,
// emptyButton: true,
// retry: () => {
// this.getData()
// }
// })
// .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
// } else {
// if (this.followList.length == 0) {
// CustomPullToRefresh({
// alldata: this.rmhList,
// scroller: this.listScroller,
// hasMore: false,
// customList: () => {
// this.ListLayout()
// },
// onRefresh: (resolve) => {
// this.currentPage = 1
// this.getData(resolve)
// },
// })
// } else {
// CustomPullToRefresh({
// alldata: this.attentionList,
// scroller: this.listScroller,
// hasMore: this.hasMore,
// customList: () => {
// this.ListAttentionLayout()
// },
// onRefresh: (resolve) => {
// this.currentPage = 1
// this.getData(resolve)
// },
// onLoadMore: (resolve) => {
// if (this.hasMore === false) {
// if (resolve) {
// resolve('')
// }
// return
// }
// if (!this.isLoading && this.hasMore) {
// //加载分页数据
// this.currentPage++;
// this.getAttentionContentListData(resolve)
// } else {
// if (resolve) {
// resolve('')
// }
// }
// },
// })
// }
// }
}
@Builder
LoadingLayout() {
channelSkeleton()
.grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
}
@Builder
ListLayout() {
List({ scroller: this.listScroller }) {
ListItem() {
RefreshLayout({
refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.load,
this.pageModel.offsetY)
})
}
.grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
// 头部关注列表
ListItem() {
PeopleShipRecommendComponent({
rmhList: this.rmhList,
oneKeyFollow: this.oneKeyFollow,
changeButton: this.changeButton
})
}
.grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
}
.edgeEffect(EdgeEffect.None)
.scrollBar(BarState.Off)
.width('100%')
.height('100%')
.onScrollIndex((start: number, end: number) => {
// Listen to the first index of the current list.
this.pageModel.startIndex = start;
// 包含了 头尾item,判断时需要考虑+3
this.pageModel.endIndex = end ;
})
}
@Builder
ListAttentionLayout() {
List({ scroller: this.listScroller }) {
ListItem() {
RefreshLayout({
refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.load,
this.pageModel.offsetY)
})
}
.grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
// // 头部关注列表
ListItem() {
PeopleShipAttentionContentListTopComponent({
followList: this.followList
})
}
.grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
ForEach(this.attentionList, (item: ContentDTO) => {
ListItem() {
Column(){
CardParser({ compDTO: new CompDTO, contentDTO: item })
.margin({
left: 6, right: 6
})
// Divider().strokeWidth(1).color('#f5f5f5').padding({ left: 16, right: 16 })
}.width('100%')
}.width("100%")
.backgroundColor(Color.Transparent)
.grayscale(item.isMourning ? 1 : 0)
}, (item: ContentDTO, index: number) => item.objectId + index.toString())
// // 加载更多
// ListItem() {
// if (!this.hasMore && !this.isLoading) {
// PeopleShipNoMoreData()
// }
// }
// 加载更多
ListItem() {
if (this.pageModel.hasMore) {
LoadMoreLayout({ isVisible: this.pageModel.isVisiblePullUpLoad })
} else {
PageNoMoreLayout({ noMoreBean: new NoMoreBean(this.pageModel.pageInfo.baselineCopywriting) })
}
}
.grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
}
.edgeEffect(EdgeEffect.None)
.scrollBar(BarState.Off)
.width('100%')
.height('100%')
.onScrollIndex((start: number, end: number) => {
// Listen to the first index of the current list.
this.pageModel.startIndex = start;
// 包含了 头尾item,判断时需要考虑+3
this.pageModel.endIndex = end - 2;
})
}
aboutToAppear() {
if (this.navIndex == this.currentTopNavSelectedIndex && this.viewType == ViewType.LOADING) {
this.getData()
}
// 有登录-退出登录-关注接口等问题
EmitterUtils.receiveEvent(EmitterEventId.PEOPLE_SHIP_ATTENTION, () => {
Logger.debug('PeopleShipMainComponent', 'PEOPLE_SHIP_ATTENTION')
this.pageAttentionChange = true
})
}
onChange() {
if (this.navIndex === this.currentTopNavSelectedIndex &&
(this.viewType == ViewType.LOADING || this.pageAttentionChange)) {
this.getData();
}
}
private async getData(resolve?: (value: string | PromiseLike<string>) => void) {
if (this.isLoading) {
if (resolve) {
resolve('已更新至最新')
}
return
}
this.pageAttentionChange = false
this.isLoading = true
this.getInitData()
try {
// 登录后获取
if (HttpUtils.getUserId()) {
// 获取用户关注人数
let object = new FollowListDetailRequestItem(-1, 20, 1)
let followInfo = await MinePageDatasModel.getMineFollowListData(object, getContext(this))
// Logger.debug('PeopleShipMainComponent', '获取页面信息' + `${JSON.stringify(followInfo)}`)
if (followInfo.list.length == 0) {
this.followList = []
this.getRmhRecommendInfo(resolve)
} else {
this.currentPage = 1
this.loadTime = DateTimeUtils.getCurDate(DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)
this.getAttentionContentListData(resolve,followInfo)
}
} else {
this.followList = []
this.getRmhRecommendInfo(resolve)
}
} catch (exception) {
this.viewType = ViewType.ERROR
this.isLoading = false
ToastUtils.shortToast('加载失败,请稍后重试')
}
}
// 获取人民号号主推荐
private async getRmhRecommendInfo(resolve?: (value: string | PromiseLike<string>) => void) {
try {
// 获取页面信息
this.rmhList = await PeopleShipMainViewModel.getPeopleRemRecommendInfo()
this.rmhSelectedList = []
this.rmhList.forEach((item: RmhRecommendDTO) => {
this.rmhSelectedList.push(item.creatorId)
})
this.viewType = ViewType.LOADED
this.changeButton = false
this.isLoading = false
// Logger.debug('PeopleShipMainComponent', 'getRmhRecommendInfo' + `${JSON.stringify(this.rmhList)}`)
if (resolve) {
resolve('已更新至最新')
}
this.closeRefresh(true)
if(this.rmhList?.length! === 0) {
ToastUtils.shortToast('加载失败,请稍后重试')
}
} catch (exception) {
if (resolve) {
resolve('')
}
this.closeRefresh(false)
this.viewType = ViewType.ERROR
this.changeButton = false
this.isLoading = false
ToastUtils.shortToast('加载失败,请稍后重试')
}
}
// 获取关注
private async getAttentionContentListData(resolve?: (value: string | PromiseLike<string>) => void,myFollowInfor?:MineFollowListItem) {
if (this.isLoading && this.currentPage != 1) {
if (resolve) {
resolve('')
}
return
}
this.isLoading = true
try {
// 获取列表数据
let listData = await PeopleShipMainViewModel.getAttentionContentListInfo(this.currentPage, 20, this.loadTime)
// Logger.debug('PeopleShipMainComponent', '获取页面信息' + `${JSON.stringify(listData)}`)
if (listData && listData.list && listData.list.length > 0) {
if (listData.list.length === 20) {
this.hasMore = true;
this.pageModel.hasMore = true
} else {
this.hasMore = false;
this.pageModel.hasMore = false
}
//批量查询各类型内容动态数据接口
this.checkContentInteractData(listData.list, resolve,myFollowInfor)
} else {
this.hasMore = false;
this.pageModel.hasMore = false
this.resolveEnd(true, resolve)
}
} catch (exception) {
this.resolveEnd(false, resolve)
}
}
// 批量查询各类型内容动态数据接口
private async checkContentInteractData(list: ContentDTO[], resolve?: (value: string | PromiseLike<string>) => void,myFollowInfor?:MineFollowListItem) {
// 批量查询内容当前用户点赞、收藏状态
try {
// 获取列表数据
const params: contentListParams = {
contentList: []
}
list.forEach((item: ContentDTO) => {
params.contentList.push({
contentId: item.objectId,
contentType: Number(item.objectType ?? '1')
})
})
let listData = await PeopleShipMainViewModel.getContentInteractInfo(params)
// Logger.debug('PeopleShipMainComponent', '获取页面信息' + `${JSON.stringify(listData)}`)
this.resolveEnd(true, resolve)
if (this.currentPage == 1) {
this.attentionList = []
this.followList = []
}
if(myFollowInfor){
this.followList.push(...myFollowInfor.list)
}
list.forEach((element: ContentDTO) => {
// 获取 interactData 数据
if (listData && listData.length > 0) {
const objc = listData.find((interactModel: InteractDataDTO) => {
return element.objectId == interactModel.contentId
})
if (objc) {
element.interactData = objc
}
}
// 设置人民号都不可关注
if (element.rmhInfo) {
element.rmhInfo.cnIsAttention = 0
}
this.attentionList.push(element)
})
// 关注频道国殇模式开启,最多前8条数据配置成国殇色
if(this.GrayManage.get().isRmhMourning(`${this.channelId}`)) {
for (let i = 0; i < Math.min(8, this.attentionList.length); i++) {
this.attentionList[i].isMourning = true;
}
}
this.pageModel.compList.clear()
this.pageModel.compList.push(...this.attentionList)
this.closeRefresh(true)
} catch (exception) {
this.closeRefresh(false)
this.resolveEnd(false, resolve)
}
}
private resolveEnd(isTop: boolean, resolve?: (value: string | PromiseLike<string>) => void) {
if (resolve) {
if (this.currentPage == 1 && isTop) {
resolve('已更新至最新')
} else {
resolve('')
}
}
if (this.currentPage == 1 && !isTop) {
this.viewType = ViewType.ERROR
ToastUtils.shortToast('加载失败,请稍后重试')
} else {
this.viewType = ViewType.LOADED
}
this.isLoading = false
}
// 说是首页必须要调用
async getInitData() {
// Logger.debug('PeopleShipMainComponent',
// `getData id: ${this.pageId} , ${this.channelId} , navIndex: ${this.currentTopNavSelectedIndex}`);
this.pageModel.pageId = this.pageId;
this.pageModel.groupId = this.pageId;
this.pageModel.channelId = this.channelId;
this.pageModel.currentPage = 1;
PageFollowHelper.getInitData(this.pageModel)
}
// 点击一键关注
onOneFollowChange() {
if (this.oneKeyFollow) {
if (this.rmhSelectedList.length > 0) {
if (!HttpUtils.getUserId()) {
this.oneKeyFollow = false
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
//调用接口
this.attentionBatchPort()
} else {
this.oneKeyFollow = false
}
}
}
// 一键关注接口
private async attentionBatchPort() {
try {
// 获取列表数据
let objects = new AttentionBatchDTO()
this.rmhList.forEach((element: RmhRecommendDTO) => {
if (this.rmhSelectedList.indexOf(element.creatorId) != -1) {
const creator = new CreatorDTO(element.userType, element.userId, element.creatorId)
objects.creators.push(creator)
}
})
// Logger.debug('PeopleShipMainComponent', `一键关注接口参数: ${JSON.stringify(objects)}`);
let batchInfo = await PeopleShipMainViewModel.getAttentionBatchInfo(objects)
this.oneKeyFollow = false
if (batchInfo.code === 0 || batchInfo.code.toString() === "0") {
this.getData()
}
} catch (exception) {
this.oneKeyFollow = false
}
}
// 点击换一换
onChangeButtonClick() {
if (this.changeButton) {
this.getRmhRecommendInfo()
}
}
// 页面展示监听
onPageShowChange() {
if (this.navIndex === this.currentTopNavSelectedIndex && this.pageAttentionChange) {
this.getData()
}
//退出登录的时候 刷新界面
// let userID = UserDataLocal.getUserId()
// if (!StringUtils.isNotEmpty(userID)) {
// this.getData()
// }
}
onAutoRefresh(changedPropertyName: string) {
if (this.navIndex != this.currentTopNavSelectedIndex) {
return
}
// 当前页面,自动刷新数据
// Logger.debug(TAG, 'page onAutoRefresh ' + this.autoRefresh)
this.listScroller.scrollToIndex(0)
autoRefresh(this.pageModel,this.onRefresh)
}
closeRefresh(isRefreshSuccess:boolean){
closeRefresh(this.pageModel,isRefreshSuccess)
}
}