yuzhilin
... ... @@ -87,6 +87,10 @@ export class commentItemModel {
maxLine: number = 3
/*是否有展示更多*/
hasMore: boolean = false
/*展开子评论的状态下是否有展开更多*/
childsHasMore: boolean = false
/*子评论pageNum*/
pageNum:number = 1
/*当有展示更多的时候,当前的状态是展开还是收起*/
expanded: boolean = false
/*是否正在加载子评论*/
... ...
@Observed
export class publishCommentModel {
/*被评论的内容id*/
//页面必传
/*被评论的内容id 页面必传*/
targetId: string = ""
/*被评论的内容关系id*/
/*被评论的内容关系id 页面必传*/
targetRelId: string = ""
/*1.文字 2.文字+表情 3.定制表情(客户端写死) 4.图片*/
commentType: string = '1'
/*根评论id,如果是一级评论,传-1;否则,传当前评论所属的根评论id*/
rootCommentId: string = "-1"
/*【迭代二新增】内容的标题,取bff内容详情接口中newsTitle字段*/
/*【迭代二新增】内容的标题,取bff内容详情接口中newsTitle字段 页面必传*/
targetTitle: string = ""
/*被评论的内容关系类型,1.频道关系;2.专题关系;【人民号内容为空】默认0*/
/*被评论的内容关系类型,1.频道关系;2.专题关系;【人民号内容为空】默认0 页面必传*/
targetRelType: string = ''
/*【迭代二新增】关联的频道id/专题id;*/
/*【迭代二新增】关联的频道id/专题id; 页面必传*/
targetRelObjectId: string = ""
/*【迭代二新增】是否是重点稿件 1是 0否 页面必传*/
keyArticle: string = ''
/*内容类别, 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增) 页面必传*/
targetType: string = ''
//评论传参
/*评论图片url,多个逗号隔开*/
commentPics: string = ""
/*评论内容*/
commentContent: string = ""
/*【迭代二新增】是否是重点稿件 1是 0否*/
keyArticle: string = ''
/*内容类别, 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增)*/
targetType: string = ''
/*1.文字 2.文字+表情 3.定制表情(客户端写死) 4.图片*/
commentType: string = '1'
/*根评论id,如果是一级评论,传-1;否则,传当前评论所属的根评论id*/
rootCommentId: string = "-1"
/*父评论id,如果是其它评论的回复,该字段必填*/
parentId: string = "-1"
//可选
placeHolderText: string = "优质评论会获得最佳评论人的称号"
}
... ...
... ... @@ -12,45 +12,23 @@ import { ifaa } from '@kit.OnlineAuthenticationKit';
const TAG = 'CommentComponent';
const testString = '因为读书的人\n是低着头向上看的人\n身处一隅,却能放眼世界\n2,因为读书的人\n总是比不读书的人\n活得有趣一点\n3,因为读书的人\n即使平凡,绝不平庸'
// @Entry
@Preview
@Component
export struct CommentComponent {
@State contentId: string = '30004266013'
/*内容类别, 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增)*/
@State contentType: string = '8'
/*内容的标题,取bff内容详情接口中newsTitle字段*/
@State targetTitle: string = '北约同意向乌克兰提供防空系统在内的更多军事支持'
/*被评论的内容关系id*/
@State targetRelId: string = "500002849023"
/*关联的频道id/专题id*/
@State targetRelObjectId: string = "2002"
/*是否是重点稿件 1是 0否*/
@State keyArticle: string = "0"
/*被评论的内容关系类型,1.频道关系;2.专题关系;【人民号内容为空】默认0*/
@State targetRelType: string = "1"
// @State private browSingModel: commentListModel = new commentListModel()
/*必传*/
@ObjectLink publishCommentModel: publishCommentModel
isloading: boolean = false
@State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
@State publishCommentModel: publishCommentModel = new publishCommentModel()
@State dialogController: CustomDialogController | null = new CustomDialogController({
builder: CommentCustomDialog({
confirm: (value: Record<string, string>) => {
this.publishComment(value)
},
commentText: this.publishCommentModel.commentContent,
placeHolderText: this.publishCommentModel.placeHolderText,
}),
autoCancel: true,
alignment: DialogAlignment.Bottom,
customStyle: true,
offset: {
dx: 0,
dy: -20
},
})
@State dialogController: CustomDialogController | null = null;
// 在自定义组件即将析构销毁时将dialogControlle置空
aboutToDisappear() {
... ... @@ -58,13 +36,22 @@ export struct CommentComponent {
}
aboutToAppear() {
this.publishCommentModel.targetTitle = this.targetTitle
this.publishCommentModel.targetId = this.contentId
this.publishCommentModel.targetType = this.contentType
this.publishCommentModel.targetRelId = this.targetRelId
this.publishCommentModel.targetRelType = this.targetRelType
this.publishCommentModel.targetRelObjectId = this.targetRelObjectId
this.publishCommentModel.keyArticle = this.keyArticle
this.dialogController = new CustomDialogController({
builder: CommentCustomDialog({
confirm: (value: Record<string, string>) => {
},
publishCommentModel:this.publishCommentModel
}),
autoCancel: true,
alignment: DialogAlignment.Bottom,
customStyle: true,
offset: {
dx: 0,
dy: -20
},
})
this.getData();
... ... @@ -105,7 +92,7 @@ export struct CommentComponent {
/*查看更多和收起*/
@Builder
GroupFooterView(item: commentItemModel, index: number) {
footerExpandedView({ item: item, contentId: this.contentId, contentType: this.contentType })
footerExpandedView({ item: item, contentId: this.publishCommentModel.targetId, contentType: this.publishCommentModel.targetType })
}
build() {
... ... @@ -152,13 +139,13 @@ export struct CommentComponent {
//获取数据
async getData() {
commentViewModel.fetchContentCommentList('1', this.contentId, this.contentType).then(commentListModel => {
commentViewModel.fetchContentCommentList('1', this.publishCommentModel.targetId, this.publishCommentModel.targetType).then(commentListModel => {
if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
commentListModel.list.forEach(element => {
element.hasMore = Number.parseInt(element.childCommentNum) ? true : false
let newModel = commentViewModel.deepCopyCommentItemModel(element)
newModel.targetId = this.contentId
newModel.targetType = this.contentType
// newModel.targetId = this.publishCommentModel.targetId
// newModel.targetType = this.publishCommentModel.targetType
this.allDatas.push(newModel)
});
... ... @@ -167,20 +154,6 @@ export struct CommentComponent {
})
}
/*回复评论*/
publishComment(value: Record<string, string>) {
this.publishCommentModel.commentContent = value['commentContent']
this.publishCommentModel.commentType = value['commentType']
commentViewModel.publishComment(this.publishCommentModel).then(() => {
this.publishCommentModel.commentContent = ''
}).catch(() => {
})
}
}
... ... @@ -230,7 +203,7 @@ struct ChildCommentItem {
.fontSize(14)
.fontColor($r('app.color.color_222222'))
.fontWeight(FontWeight.Medium)
.margin({ left: 0 , right:0})
.margin({ left: 0, right: 0 })
/// 暂时不显示 “我” 的标签了
... ... @@ -257,10 +230,12 @@ struct ChildCommentItem {
.margin({ left: 5 });
}
}.margin({ left: 0, right: 16 })
// .backgroundColor(Color.Red)
CommentText({
longMessage: this.item.commentContent,
// longMessage:testString,
maxline: 3,
fontSize: 14,
fontWeight: FontWeight.Regular,
... ... @@ -297,12 +272,27 @@ struct footerExpandedView {
build() {
Row() {
if (this.item.expanded) {
if (this.item.childsHasMore) {
Row() {
Text().backgroundColor($r('app.color.color_EDEDED')).width(24).height(1)
Text('查看更多回复').fontColor($r('app.color.color_222222')).fontSize(14).margin({ left: 6 })
Image($r('app.media.comment_unfold')).width(12).height(12)
}.margin({ left: 53 })
.onClick(() => {
if (this.item.isLoading) {
return
}
this.item.isLoading = true
fetchChildContentCommentList(this.contentId, this.contentType, this.item)
})
}
Row() {
Text('收起').fontColor($r('app.color.color_222222')).fontSize(14)
Image($r('app.media.comment_pickUp')).width(12).height(12)
}.margin({ left: 213 })
}.margin({ left: this.item.childsHasMore ? 32 : 213 })
.onClick(() => {
this.item.expanded = !this.item.expanded
this.item.pageNum = 1
this.item.expanded = false
this.item.childComments = []
this.item.childCommentsLazyDataSource.clear()
})
... ... @@ -317,28 +307,35 @@ struct footerExpandedView {
return
}
this.item.isLoading = true
//load child
commentViewModel.fetchChildContentCommentList('1', this.contentId, this.contentType, this.item.id)
.then((commentListModel) => {
this.item.isLoading = false
this.item.expanded = !this.item.expanded
commentListModel.list.forEach(element => {
this.item.childComments.push(element)
let newModel = commentViewModel.deepCopyCommentItemModel(element)
newModel.targetId = this.contentId
newModel.targetType = this.contentType
this.item.childCommentsLazyDataSource.push(newModel)
})
}).catch(() => {
this.item.isLoading = false
})
fetchChildContentCommentList(this.contentId, this.contentType, this.item)
})
}
}.height(30)
}
}
function fetchChildContentCommentList(contentId: string, contentType: string, item: commentItemModel) {
commentViewModel.fetchChildContentCommentList(item.pageNum + '', contentId, contentType, item.id)
.then((commentListModel) => {
item.pageNum = item.pageNum + 1
item.childsHasMore = commentListModel.hasNext > 0 ? true : false
item.isLoading = false
item.expanded = true
commentListModel.list.forEach(element => {
item.childComments.push(element)
let newModel = commentViewModel.deepCopyCommentItemModel(element)
newModel.targetId = contentId
newModel.targetType = contentType
item.childCommentsLazyDataSource.push(newModel)
})
}).catch(() => {
item.isLoading = false
})
}
@Component
struct commentHeaderView {
@Link publishCommentModel: publishCommentModel
... ... @@ -411,7 +408,14 @@ struct commentHeaderView {
marginWidth: (59 + 16)
})
.margin({ left: 59, right: 16, top: -5 })
.onClick(() => {
this.publishCommentModel.rootCommentId = this.item.rootCommentId
this.publishCommentModel.parentId = this.item.id
this.publishCommentModel.placeHolderText = '回复' + this.item.fromUserName + ':'
if (this.dialogController != null) {
this.dialogController.open()
}
})
commentFooterView({
item: this.item,
... ... @@ -456,7 +460,12 @@ struct commentFooterView {
.fontColor($r('app.color.color_222222'))
.fontSize(12)
.onClick(() => {
//TODO: 回复
this.publishCommentModel.rootCommentId = this.item.rootCommentId
this.publishCommentModel.parentId = this.item.id
this.publishCommentModel.placeHolderText = '回复' + this.item.fromUserName + ':'
if (this.dialogController != null) {
this.dialogController.open()
}
})
}
... ...
... ... @@ -5,27 +5,51 @@ import commentViewModel from '../viewmodel/CommentViewModel'
@Preview
@CustomDialog
export struct CommentCustomDialog {
commentText: string = ''
placeHolderText: string = '优质评论会获得最佳评论人的称号'
@ObjectLink publishCommentModel: publishCommentModel
controller?: CustomDialogController
confirm: (value: Record<string, string>) => void = () => {
}
@State private emojiSwitch: boolean = false
textInputController: TextAreaController = new TextAreaController()
aboutToAppear(): void {
}
publishCommentRequest() {
let bean: Record<string, string> = {};
// this.publishCommentModel.commentContent = this.commentText
//TODO 判断类型
this.publishCommentModel.commentType = '1'
commentViewModel.publishComment(this.publishCommentModel).then(() => {
this.publishCommentModel.commentContent = ''
// this.commentText = ''
if (this.controller != null) {
this.controller.close()
}
this.confirm(bean)
}).catch(() => {
if (this.controller != null) {
this.controller.close()
}
})
}
build() {
Column() {
Row() {
TextArea({
placeholder: this.placeHolderText,
placeholder: this.publishCommentModel.placeHolderText,
controller: this.textInputController,
text: this.commentText
text: this.publishCommentModel.commentContent
})
.height('100%')
.width('100%')
.backgroundColor($r('app.color.color_transparent'))
.onChange(value => {
this.commentText = value;
this.publishCommentModel.commentContent = value;
})
}
.backgroundColor('#F9F9F9')
... ... @@ -68,18 +92,11 @@ export struct CommentCustomDialog {
.textAlign(TextAlign.Center)
.borderRadius(4)
.onClick(() => {
if (this.commentText.length > 0) {
if (this.publishCommentModel.commentContent.length > 0) {
//请求评论接口
//commentType
//commentContent
let bean: Record<string, string> = {};
bean['commentContent'] = this.commentText
//TODO 判断类型
bean['commentType'] = '1'
this.confirm(bean)
if (this.controller != null) {
this.controller.close()
}
this.publishCommentRequest()
}
})
}
... ...
... ... @@ -239,52 +239,53 @@ class CommentViewModel {
let promiseArray: Promise<commentStatusListModel | void>[] = [];
//TODO 未登录不用批查
if (commentIDs.length > 0) {
let promise1 = new Promise<void>((success) => {
// HttpRequest HttpBizUtil
let url = HttpUrlUtils.getBatchCommentStatusUrl();
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
let bean: Record<string, string[]> = {};
bean['commentIdList'] = commentIDs;
HttpRequest.post<ResponseDTO<commentStatusModel[]>>(url, bean, headers).then((data: ResponseDTO<commentStatusModel[]>) => {
if (!data || !data.data) {
success()
return
}
if (data.code != 0) {
success()
return
}
if (data.data.length == 0) {
success()
return
}
let listData = data.data as commentStatusModel[]
//点赞
for (const element of listData) {
for (const commentModel of model.list) {
if (element.commentId == commentModel.id) {
commentModel.api_status = element.status
}
if (commentModel.childComments) {
for (const childCommentModel of commentModel.childComments) {
if (element.commentId == childCommentModel.id) {
childCommentModel.api_status = element.status
//未登录不用批查
if (HttpUrlUtils.getUserId()){
if (commentIDs.length > 0) {
let promise1 = new Promise<void>((success) => {
// HttpRequest HttpBizUtil
let url = HttpUrlUtils.getBatchCommentStatusUrl();
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
let bean: Record<string, string[]> = {};
bean['commentIdList'] = commentIDs;
HttpRequest.post<ResponseDTO<commentStatusModel[]>>(url, bean, headers).then((data: ResponseDTO<commentStatusModel[]>) => {
if (!data || !data.data) {
success()
return
}
if (data.code != 0) {
success()
return
}
if (data.data.length == 0) {
success()
return
}
let listData = data.data as commentStatusModel[]
//点赞
for (const element of listData) {
for (const commentModel of model.list) {
if (element.commentId == commentModel.id) {
commentModel.api_status = element.status
}
if (commentModel.childComments) {
for (const childCommentModel of commentModel.childComments) {
if (element.commentId == childCommentModel.id) {
childCommentModel.api_status = element.status
}
}
}
}
}
}
success()
}, (error: Error) => {
success()
Logger.debug(TAG, error.toString())
success()
}, (error: Error) => {
success()
Logger.debug(TAG, error.toString())
})
})
})
promiseArray.push(promise1);
}
promiseArray.push(promise1);
}
}
if (fromUserIDs.length > 0) {
let promise2 = new Promise<void>((success) => {
let url = HttpUrlUtils.getBatchUserUrl();
... ... @@ -385,21 +386,7 @@ class CommentViewModel {
}
commnetLikeChange(model: commentItemModel) {
model.api_status = !model.api_status
//点赞
if (model.api_status) {
model.likeNum = (Number.parseInt(model.likeNum) + 1) + ''
}
//取消点赞
if (!model.api_status) {
model.likeNum = (Number.parseInt(model.likeNum) - 1) + ''
if (Number.parseInt(model.likeNum) < 0) {
model.likeNum = '0'
}
}
// return model
}
deepCopyCommentItemModel(model: commentItemModel) {
let newModel = new commentItemModel()
... ...