xugenyuan

ref |> 调整评论列表数据加载交互,解决每次进入页面会把所有评论数据都加载一遍

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
... ... @@ -69,6 +69,7 @@ export struct DynamicDetailComponent {
@State isNetConnected: boolean = true
@State isPageEnd: boolean = false
@State publishCommentModel: publishCommentModel = new publishCommentModel()
@State reachEndIncreament: number = 0
async aboutToAppear() {
await this.getContentDetailData()
... ... @@ -709,4 +710,4 @@ interface radiusType {
topRight: number | Resource;
bottomLeft: number | Resource;
bottomRight: number | Resource;
}
\ No newline at end of file
}
... ...
... ... @@ -52,6 +52,7 @@ export struct ImageAndTextPageComponent {
@State isNetConnected: boolean = true
@State info: Area | null = null
@State likeNum: number = 0
@State reachEndIncreament : number = 0
build() {
Column() {
... ... @@ -141,7 +142,12 @@ export struct ImageAndTextPageComponent {
if (this.contentDetailData?.openComment) {
Divider().strokeWidth(6).color('#f5f5f5')
CommentComponent({
publishCommentModel: this.publishCommentModel
publishCommentModel: this.publishCommentModel,
fixedHeightMode: false,
reachEndIncreament: this.reachEndIncreament,
reachEndLoadMoreFinish: () => {
}
}).onAreaChange((oldValue: Area, newValue: Area) => {
this.info = newValue
})
... ... @@ -157,6 +163,9 @@ export struct ImageAndTextPageComponent {
.padding({ bottom: 76 })
.scrollBar(BarState.Off)
.align(Alignment.Top)
.onReachEnd(() => {
this.reachEndIncreament += 1
})
if (!this.isNetConnected) {
EmptyComponent({
... ... @@ -340,4 +349,4 @@ export struct ImageAndTextPageComponent {
aboutToDisappear() {
}
}
\ No newline at end of file
}
... ...
... ... @@ -20,6 +20,8 @@ export class publishCommentModel {
targetType: string = ''
/*评论总数*/
totalCommentNumer: string = '0'
/// 游客评论开关:visitorComment 1:打开;0:关闭
visitorComment: string = "0"
//评论传参
/*评论图片url,多个逗号隔开*/
... ...
... ... @@ -24,12 +24,17 @@ export struct CommentComponent {
@ObjectLink publishCommentModel: publishCommentModel
listScroller: ListScroller = new ListScroller(); // scroller控制器
historyOffset: number = 0; // 上次浏览到列表距离顶端的偏移量offset
isloading: boolean = false
@State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
@State dialogController: CustomDialogController | null = null;
// @State private browSingModel: commentListModel = new commentListModel()
// 是否为固定高度模式。true时,里面上拉加载更多生效,外层不能包Scroll。
// false时,外层实现加载更多,并通过reachEndIncreament通知开发加载更多,reachEndLoadMoreFinish 通知上层加载更多完成
fixedHeightMode: boolean = false
@Prop @Watch("parentOnReachEnd") reachEndIncreament : number = 0
reachEndLoadMoreFinish?: () => void
// 在自定义组件即将析构销毁时将dialogControlle置空
aboutToDisappear() {
this.dialogController = null // 将dialogController置空
... ... @@ -183,23 +188,43 @@ export struct CommentComponent {
// 加载更多
ListItem() {
if (this.hasMore === false) {
if (this.hasMore == false) {
NoMoreLayout()
}
}
}
}
.margin({bottom: 10})
.onReachEnd(() => {
if (!this.fixedHeightMode) {
return
}
if (this.hasMore) {
this.getData()
}
})
.enableScrollInteraction(false)
.enableScrollInteraction(this.fixedHeightMode ? true: false)
// .nestedScroll({
// scrollForward: NestedScrollMode.PARENT_FIRST,
// scrollBackward: NestedScrollMode.SELF_FIRST
// })
}
}
parentOnReachEnd() {
if (this.fixedHeightMode) {
return
}
if (this.hasMore) {
this.getData()
} else {
if (this.reachEndLoadMoreFinish) {
this.reachEndLoadMoreFinish()
}
}
}
//获取数据
async getData() {
commentViewModel.fetchContentCommentList(this.currentPage + '', this.publishCommentModel.targetId,
... ... @@ -237,6 +262,9 @@ export struct CommentComponent {
} else {
this.hasMore = false
}
if (!this.fixedHeightMode && this.reachEndLoadMoreFinish) {
this.reachEndLoadMoreFinish()
}
})
}
}
... ...
import { ContentDetailDTO, PageInfoDTO } from 'wdBean/Index'
import { publishCommentModel } from '../model/PublishCommentModel'
@CustomDialog
export struct CommentListDialog {
/// 内部使用
private publishCommentModel: publishCommentModel = new publishCommentModel()
controller?: CustomDialogController
/// 外部初始化
contentDetail?: ContentDetailDTO
pageInfo?: PageInfoDTO
build() {
}
}
\ No newline at end of file
... ...