liyubing

feat:进入横屏多路直播-置空-评论预显示禁止直播间,大家聊不支持下拉刷新

1 import { ContentDetailDTO, LiveDetailsBean, LiveRoomItemBean } from 'wdBean/Index' 1 import { ContentDetailDTO, LiveDetailsBean, LiveRoomItemBean } from 'wdBean/Index'
2 -import { EmptyComponent, ErrorComponent, WDViewDefaultType } from 'wdComponent/Index' 2 +import { CustomPullToRefresh, EmptyComponent, ErrorComponent, WDViewDefaultType } from 'wdComponent/Index'
3 import CustomRefreshLoadLayout from 'wdComponent/src/main/ets/components/page/CustomRefreshLoadLayout' 3 import CustomRefreshLoadLayout from 'wdComponent/src/main/ets/components/page/CustomRefreshLoadLayout'
4 import RefreshLayout from 'wdComponent/src/main/ets/components/page/RefreshLayout' 4 import RefreshLayout from 'wdComponent/src/main/ets/components/page/RefreshLayout'
5 import { RefreshLayoutBean } from 'wdComponent/src/main/ets/components/page/RefreshLayoutBean' 5 import { RefreshLayoutBean } from 'wdComponent/src/main/ets/components/page/RefreshLayoutBean'
@@ -7,8 +7,10 @@ import PageModel from 'wdComponent/src/main/ets/viewmodel/PageModel' @@ -7,8 +7,10 @@ import PageModel from 'wdComponent/src/main/ets/viewmodel/PageModel'
7 import { ViewType } from 'wdConstant/Index' 7 import { ViewType } from 'wdConstant/Index'
8 import { LiveViewModel } from '../../viewModel/LiveViewModel' 8 import { LiveViewModel } from '../../viewModel/LiveViewModel'
9 import { TabChatItemComponent } from './TabChatItemComponent' 9 import { TabChatItemComponent } from './TabChatItemComponent'
10 -import { EmitterEventId, EmitterUtils, Logger } from 'wdKit'; 10 +import { EmitterEventId, EmitterUtils, LazyDataSource, Logger } from 'wdKit';
11 import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel' 11 import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel'
  12 +import { PeopleShipNoMoreData } from 'wdComponent/src/main/ets/components/reusable/PeopleShipNoMoreData'
  13 +import LoadMoreLayout from 'wdComponent/src/main/ets/components/page/LoadMoreLayout'
12 14
13 const TAG: string = 'TabChatComponent'; 15 const TAG: string = 'TabChatComponent';
14 16
@@ -20,13 +22,15 @@ const TAG: string = 'TabChatComponent'; @@ -20,13 +22,15 @@ const TAG: string = 'TabChatComponent';
20 export struct TabChatComponent { 22 export struct TabChatComponent {
21 @State private pageModel: PageModel = new PageModel() 23 @State private pageModel: PageModel = new PageModel()
22 liveViewModel: LiveViewModel = new LiveViewModel() 24 liveViewModel: LiveViewModel = new LiveViewModel()
23 - @State liveChatList: Array<LiveRoomItemBean> = [] 25 + @State liveChatList: LazyDataSource<LiveRoomItemBean> = new LazyDataSource();
  26 +
  27 + // @State liveList: LazyDataSource<LiveRoomItemBean> = new LazyDataSource();
24 @Consume contentDetailData: ContentDetailDTO 28 @Consume contentDetailData: ContentDetailDTO
25 @Consume publishCommentModel: publishCommentModel 29 @Consume publishCommentModel: publishCommentModel
26 @Prop @Watch("lastInputedCommentChanged") lastInputedComment: LiveRoomItemBean 30 @Prop @Watch("lastInputedCommentChanged") lastInputedComment: LiveRoomItemBean
27 - 31 + private scroller: Scroller = new Scroller()
28 aboutToAppear(): void { 32 aboutToAppear(): void {
29 - this.getLiveChatList() 33 + this.getLiveList()
30 34
31 //注册通知 35 //注册通知
32 EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, async (targetId?: string) => { 36 EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, async (targetId?: string) => {
@@ -62,7 +66,20 @@ export struct TabChatComponent { @@ -62,7 +66,20 @@ export struct TabChatComponent {
62 } else if (this.pageModel.viewType == ViewType.EMPTY) { 66 } else if (this.pageModel.viewType == ViewType.EMPTY) {
63 EmptyComponent({ emptyType: WDViewDefaultType.WDViewDefaultType_NoComment1 }) 67 EmptyComponent({ emptyType: WDViewDefaultType.WDViewDefaultType_NoComment1 })
64 } else { 68 } else {
65 - this.ListLayout() 69 + // this.ListLayout()
  70 +
  71 + CustomPullToRefresh({
  72 + alldata: this.liveChatList,
  73 + scroller: this.scroller,
  74 + hasMore: false,
  75 + customList: () => {
  76 + this.ListLayout()
  77 + },
  78 + onRefresh: (resolve) => {
  79 + this.pageModel.currentPage = 1
  80 + this.getLiveList(resolve)
  81 + },
  82 + })
66 } 83 }
67 } 84 }
68 .align(Alignment.Top) 85 .align(Alignment.Top)
@@ -73,32 +90,33 @@ export struct TabChatComponent { @@ -73,32 +90,33 @@ export struct TabChatComponent {
73 90
74 @Builder 91 @Builder
75 ListLayout() { 92 ListLayout() {
76 - List() {  
77 - ListItem() {  
78 - // 下拉刷新 TODO 待对接新的下拉刷新组件  
79 - // RefreshLayout({  
80 - // refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.pullDownRefreshImage,  
81 - // this.pageModel.pullDownRefreshText, this.pageModel.pullDownRefreshHeight)  
82 - // })  
83 - } 93 + List({ scroller: this.scroller }) {
84 94
85 - ForEach(this.liveChatList, (item: LiveRoomItemBean) => { 95 + LazyForEach(this.liveChatList, (item: LiveRoomItemBean) => {
86 ListItem() { 96 ListItem() {
87 TabChatItemComponent({ item: item }) 97 TabChatItemComponent({ item: item })
88 } 98 }
89 - }) 99 + },
  100 + (item: LiveRoomItemBean, contentIndex: number) => JSON.stringify(item)
  101 + )
90 // 加载更多 102 // 加载更多
91 - // ListItem() {  
92 - // if (this.pageModel.hasMore) {  
93 - // LoadMoreLayout({  
94 - // refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullUpLoad, this.pageModel.pullUpLoadImage,  
95 - // this.pageModel.pullUpLoadText, this.pageModel.pullUpLoadHeight)  
96 - // })  
97 - // } else {  
98 - // ListHasNoMoreDataUI()  
99 - // }  
100 - // }  
101 - } 103 + ListItem() {
  104 + if (this.pageModel.hasMore && this.liveChatList && this.liveChatList.totalCount() > 0) {
  105 + LoadMoreLayout({ isVisible: this.pageModel.hasMore })
  106 + } else if (!this.pageModel.hasMore && !this.pageModel.isLoading) {
  107 + PeopleShipNoMoreData()
  108 + }
  109 + }
  110 + } .edgeEffect(EdgeEffect.None)
  111 + .scrollBar(BarState.Off)
  112 + .onReachEnd(() => {
  113 + Logger.debug(TAG, "触底了");
  114 + if (!this.pageModel.isLoading && this.pageModel.hasMore) {
  115 + //加载分页数据
  116 + //this.currentPage++;
  117 + this.getLiveList()
  118 + }
  119 + })
102 } 120 }
103 121
104 @Builder 122 @Builder
@@ -109,7 +127,16 @@ export struct TabChatComponent { @@ -109,7 +127,16 @@ export struct TabChatComponent {
109 }) 127 })
110 } 128 }
111 129
112 - getLiveChatList() { 130 + async getLiveList(resolve?: (value: string | PromiseLike<string>) => void) {
  131 +
  132 + if (this.pageModel.isLoading) {
  133 +
  134 + if (resolve) {
  135 + resolve('已更新至最新')
  136 + }
  137 + return
  138 + }
  139 + this.pageModel.isLoading = true
113 this.pageModel.currentPage = 1 140 this.pageModel.currentPage = 1
114 this.liveViewModel.getLiveChatList( 141 this.liveViewModel.getLiveChatList(
115 this.pageModel.currentPage, 142 this.pageModel.currentPage,
@@ -118,6 +145,17 @@ export struct TabChatComponent { @@ -118,6 +145,17 @@ export struct TabChatComponent {
118 20,) 145 20,)
119 .then( 146 .then(
120 (data) => { 147 (data) => {
  148 + this.pageModel.isLoading = false
  149 + if (resolve) {
  150 + if (this.pageModel.currentPage == 1) {
  151 + resolve('已更新至最新')
  152 + } else {
  153 + resolve('')
  154 + }
  155 + }
  156 + if(this.pageModel.currentPage ===1){
  157 + this.liveChatList.clear()
  158 + }
121 Logger.debug(TAG, `${JSON.stringify(data)}`) 159 Logger.debug(TAG, `${JSON.stringify(data)}`)
122 if (data.barrageResponses && data.barrageResponses.length > 0) { 160 if (data.barrageResponses && data.barrageResponses.length > 0) {
123 this.pageModel.viewType = ViewType.LOADED; 161 this.pageModel.viewType = ViewType.LOADED;