Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
xugenyuan
2024-08-26 18:54:01 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
26c3e3e3981cae5e1d3d77df2985e1e9d1950685
26c3e3e3
1 parent
11c886ab
ref |> 增加热门评论接口数据展示
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
160 additions
and
23 deletions
sight_harmony/features/wdComponent/src/main/ets/components/comment/model/CommentModel.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentListDialog.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/viewmodel/CommentViewModel.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/model/CommentModel.ets
View file @
26c3e3e
...
...
@@ -35,6 +35,8 @@ export class commentListModel extends PageModel {
totalCommentNum: string = '0'
hasNext: number = 0
list: commentItemModel[] = []
hotList: commentItemModel[] = [] // 仅第一页存在
hotIds: string[] = [] // 仅第一页存在
// constructor(pageNum:number, pageSize:number, totalCount: number, hasNext: number, list: commentItemModel[]) {
// super()
// this.pageNum = pageNum
...
...
@@ -45,9 +47,16 @@ export class commentListModel extends PageModel {
// }
}
export enum CommentItemCustomType {
comment = 0,
newTitle = 1, // 最新评论标题
hotTitle = 2, // 热门评论标题
hotComment = 3,
}
@Observed
export class commentItemModel {
api_customType: CommentItemCustomType = CommentItemCustomType.comment
authorLike: string = ''
avatarFrame: string = ''
checkStatus: string = ''
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentComponent.ets
View file @
26c3e3e
import { DateTimeUtils, EmitterEventId, EmitterUtils, LazyDataSource,
PublicDialogManager,
StringUtils } from 'wdKit/Index';
import { commentItemModel, WDPublicUserType } from '../model/CommentModel';
import {
CommentItemCustomType,
commentItemModel, WDPublicUserType } from '../model/CommentModel';
import commentViewModel from '../viewmodel/CommentViewModel';
import { CommentText } from './CommentText';
import { CommentCustomDialog } from './CommentCustomDialog';
...
...
@@ -37,6 +37,7 @@ export struct CommentComponent {
listScroller: ListScroller = new ListScroller(); // scroller控制器
historyOffset: number = 0; // 上次浏览到列表距离顶端的偏移量offset
@State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
firstPageHotIds: string = ''
@State dialogController: CustomDialogController | null = null;
// @State private browSingModel: commentListModel = new commentListModel()
...
...
@@ -49,6 +50,7 @@ export struct CommentComponent {
// 是否在弹框中
@Provide inDialog: boolean = false
private dialogBeforeJumpOtherPageAction: () => void = () => {}
private dialogUpdateTitle: (title: string) => void = () => {}
// 在自定义组件即将析构销毁时将dialogControlle置空
aboutToDisappear() {
...
...
@@ -99,7 +101,16 @@ export struct CommentComponent {
/*一级评论*/
// if (this.publishCommentModel.lastCommentModel)
if (this.publishCommentModel.lastCommentModel.parentId == '-1') {
this.allDatas.addFirstItem(model)
let newCommentHeaderIndex = this.indexOfNewCommentHeaderTitle()
if (newCommentHeaderIndex === -1) {
let newCommentTitle = new commentItemModel()
newCommentTitle.api_customType = CommentItemCustomType.newTitle
this.allDatas.addItems([newCommentTitle, model])
} else {
this.allDatas.addItem(model, newCommentHeaderIndex + 1)
}
} else {
//二级评论
this.allDatas.getDataArray().forEach(element => {
...
...
@@ -116,14 +127,19 @@ export struct CommentComponent {
/*标题:全部评论*/
@Builder
titleHeader() {
titleHeader(title: string = "最新评论", showGapLine: boolean = false) {
Column() {
if (showGapLine) {
Divider().strokeWidth(6).color('#f5f5f5')
}
Row() {
Row() {
Image($r('app.media.redLine'))
.height(16)
.width(3)
Text('全部评论'
)
Text(title
)
.fontSize(16)// .fontColor('#222222')
.fontColor($r('app.color.color_222222'))
.fontWeight(FontWeight.Medium)
...
...
@@ -145,12 +161,7 @@ export struct CommentComponent {
.height(44)
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.onClick(() => {
// this.allDatas.push(new commentItemModel())
// this.allDatas.addFirstItem(new commentItemModel())
// this.allDatas.reloadData();
})
}
}
/*1级评论作为titleHeader*/
...
...
@@ -177,16 +188,29 @@ export struct CommentComponent {
build() {
Column() {
List({ scroller: this.listScroller }) {
if (!this.isComments) {
if (this.showTitleComponent) {
ListItemGroup({ header: this.titleHeader() })
}
if (!this.isComments) {
EmptyComponent({ emptyType: 17 })
.height(300)
} else {
LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
if (item.hasMore) {
if (item.api_customType === CommentItemCustomType.newTitle) {
if (this.inDialog && index === 0) {
ListItemGroup()
} else {
ListItemGroup({ header: this.titleHeader("最新评论", index !== 0) })
}
}
else if (item.api_customType === CommentItemCustomType.hotTitle) {
if (this.inDialog && index === 0) {
ListItemGroup()
} else {
ListItemGroup({ header: this.titleHeader("热门评论") })
}
}
else if (item.hasMore) {
ListItemGroup({
header: this.CommentHeaderItem(item, index),
footer: this.GroupFooterView(item, index)
...
...
@@ -234,6 +258,9 @@ export struct CommentComponent {
}
.scrollBar(BarState.Off)
.margin({ bottom: 10 })
.onScrollIndex((start) => {
this.updateDialogTitleWithStartIndex(start)
})
.onReachEnd(() => {
if (!this.fixedHeightMode) {
return
...
...
@@ -252,6 +279,30 @@ export struct CommentComponent {
}
updateDialogTitleWithStartIndex(start: number) {
if (!this.inDialog) {
return
}
if (this.allDatas.size() === 0) {
this.dialogUpdateTitle("评论")
return
}
if (this.allDatas.getFirst().api_customType !== CommentItemCustomType.hotTitle) {
this.dialogUpdateTitle("最新评论")
return
}
let newCommentHeaderIndex = this.indexOfNewCommentHeaderTitle()
if (newCommentHeaderIndex == -1) {
this.dialogUpdateTitle("热门评论")
return
}
if (start < newCommentHeaderIndex + 1) {
this.dialogUpdateTitle("热门评论")
} else {
this.dialogUpdateTitle("最新评论")
}
}
parentOnReachEnd() {
if (this.fixedHeightMode) {
return
...
...
@@ -268,11 +319,41 @@ export struct CommentComponent {
//获取数据
async getData() {
let pageIndex = this.currentPage
commentViewModel.fetchContentCommentList(pageIndex + '', this.publishCommentModel.targetId,
this.publishCommentModel.targetType)
commentViewModel.fetchContentCommentList(pageIndex + ''
,this.publishCommentModel.targetId
,this.publishCommentModel.targetType
,this.firstPageHotIds)
.then(commentListModel => {
console.log('评论:', JSON.stringify(commentListModel.list))
if (pageIndex == 1) {
// 保存第一页热门评论ids
if (commentListModel.hotIds.length > 0) {
this.firstPageHotIds = commentListModel.hotIds.join(",")
}
if (commentListModel.list.length > 0) { // 热门评论增加头部
let newCommentTitle = new commentItemModel()
newCommentTitle.api_customType = CommentItemCustomType.newTitle
let newArray = [newCommentTitle]
commentListModel.list = newArray.concat(commentListModel.list)
}
if (commentListModel.hotList.length > 0) { // 最新评论增加头部
let hotCommentTitle = new commentItemModel()
hotCommentTitle.api_customType = CommentItemCustomType.hotTitle
let newArray = [hotCommentTitle]
commentListModel.hotList = newArray.concat(commentListModel.hotList)
commentListModel.list = commentListModel.hotList.concat(commentListModel.list)
}
} else { // 非首页数据
if (commentListModel.list.length > 0 && !this.hasNewCommentHeaderTitle()) { // 如果之前仅存在热门评论,这里需要补下数据
let newCommentTitle = new commentItemModel()
newCommentTitle.api_customType = CommentItemCustomType.newTitle
let newArray = [newCommentTitle]
commentListModel.list = newArray.concat(commentListModel.list)
}
}
// 这里需要先赋值,否则下次UI刷新可能重复进入第1页两次
this.currentPage = pageIndex + 1
...
...
@@ -313,6 +394,29 @@ export struct CommentComponent {
}
})
}
hasNewCommentHeaderTitle() {
let hasNewCommentHeader = false
this.allDatas.getDataArray().forEach((comment) => {
if (comment.api_customType === CommentItemCustomType.newTitle) {
hasNewCommentHeader = true
}
})
return hasNewCommentHeader
}
indexOfNewCommentHeaderTitle() {
let resultIndex = -1;
const array = this.allDatas.getDataArray()
for (let index = 0; index < array.length; index++) {
if (array[index].api_customType === CommentItemCustomType.newTitle) {
resultIndex = index;
break
}
}
return resultIndex
}
}
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentListDialog.ets
View file @
26c3e3e
...
...
@@ -74,6 +74,7 @@ struct CommentListDialog {
/// 内部使用
@Link publishCommentModel: publishCommentModel
@State private operationButtonList: string[] = []
@State title: string = "评论"
/// 外部初始化
@Link contentDetailData: ContentDetailDTO // 详情页传
...
...
@@ -122,6 +123,9 @@ struct CommentListDialog {
if (this.onClose) {
this.onClose()
}
},
dialogUpdateTitle: (title) => {
this.title = title
}
}).layoutWeight(1)
...
...
@@ -153,7 +157,7 @@ struct CommentListDialog {
Image($r('app.media.redLine'))
.height(16)
.width(3)
Text(
'全部评论'
)
Text(
this.title
)
.fontSize(16)// .fontColor('#222222')
.fontColor($r('app.color.color_222222'))
.fontWeight(FontWeight.Medium)
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/viewmodel/CommentViewModel.ets
View file @
26c3e3e
...
...
@@ -8,6 +8,7 @@ import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { TrackConstants, TrackingContent } from 'wdTracking/Index';
import {
CommentItemCustomType,
commentItemModel,
commentListModel,
commentStatusListModel,
...
...
@@ -33,9 +34,13 @@ class CommentViewModel {
}
/*获取所有评论*/
fetchContentCommentList(pageNum: string, contentId: string, contentType: string): Promise<commentListModel> {
fetchContentCommentList(pageNum: string, contentId: string, contentType: string
, firstPageHotIds: string = ''
): Promise<commentListModel> {
let url = HttpUrlUtils.getContentCommentListDataUrl() + `?&pageSize=${10}&pageNum=${pageNum}&contentId=${contentId}&contentType=${contentType}&deviceId=${HttpUtils.getDeviceId()}&userId=${HttpUtils.getUserId()}&userType=${HttpUtils.getUserType()}&time=${DateTimeUtils.getCurTime(DateTimeUtils.PATTERN_DATE_TIME_HYPHEN)}`
url = url + "&hotComment=1"
if (pageNum !== "1" && firstPageHotIds.length > 0) {
url = url + `&hotIds=` + firstPageHotIds
}
url = url.replace(' ', '%20')
return new Promise<commentListModel>((success, fail) => {
...
...
@@ -49,10 +54,24 @@ class CommentViewModel {
return
}
let listData = data.data as commentListModel
this.fetchCommentStatusAndConfigAuthIcon(listData).then((commentListModel) => {
this.fetchCommentStatusAndConfigAuthIcon(listData
, false
).then((commentListModel) => {
console.log(TAG, 'fetchCommentStatusAndConfigAuthIcon完成')
if (pageNum !== "1") {
success(commentListModel)
return
}
// 热门评论批查
this.fetchCommentStatusAndConfigAuthIcon(listData, true).then((commentListModel) => {
console.log(TAG, 'hot comment fetchCommentStatusAndConfigAuthIcon完成')
listData.hotList.forEach((item) => {
item.api_customType = CommentItemCustomType.hotComment
})
success(commentListModel)
})
})
}, (error: Error) => {
fail(error.message)
...
...
@@ -213,7 +232,7 @@ class CommentViewModel {
}
/*多接口批查*/
fetchCommentStatusAndConfigAuthIcon(model: commentListModel): Promise<commentListModel> {
fetchCommentStatusAndConfigAuthIcon(model: commentListModel
, hot: boolean = false
): Promise<commentListModel> {
let commentIDs: string[] = [];
...
...
@@ -222,7 +241,7 @@ class CommentViewModel {
let creatorIDs: string[] = [];
//主评论
for (const element of
model.list
) {
for (const element of
(hot ? model.hotList : model.list)
) {
if ((element.id + '').length > 0) {
commentIDs.push(element.id + '')
}
...
...
@@ -277,7 +296,7 @@ class CommentViewModel {
let listData = data.data as commentStatusModel[]
//点赞
for (const element of listData) {
for (const commentModel of
model.list
) {
for (const commentModel of
(hot ? model.hotList : model.list)
) {
if (element.commentId == commentModel.id) {
commentModel.api_status = element.status
}
...
...
@@ -319,7 +338,7 @@ class CommentViewModel {
let listData = data.data as commentStatusModel[]
for (const element of listData) {
for (const commentModel of
model.list
) {
for (const commentModel of
(hot ? model.hotList : model.list)
) {
if (element.userId == commentModel.fromUserId) {
commentModel.api_levelHead = element.levelHead
}
...
...
@@ -364,7 +383,7 @@ class CommentViewModel {
let listData = data.data as commentStatusModel[]
for (const element of listData) {
for (const commentModel of
model.list
) {
for (const commentModel of
(hot ? model.hotList : model.list)
) {
if (element.creatorId == commentModel.fromCreatorId) {
commentModel.api_authIcon = element.authIcon
}
...
...
@@ -400,6 +419,7 @@ class CommentViewModel {
deepCopyCommentItemModel(model: commentItemModel) {
let newModel = new commentItemModel()
newModel.api_customType = model.api_customType
newModel.authorLike = model.authorLike
newModel.avatarFrame = model.avatarFrame
newModel.checkStatus = model.checkStatus
...
...
Please
register
or
login
to post a comment