yuzhilin
@@ -87,6 +87,10 @@ export class commentItemModel { @@ -87,6 +87,10 @@ export class commentItemModel {
87 maxLine: number = 3 87 maxLine: number = 3
88 /*是否有展示更多*/ 88 /*是否有展示更多*/
89 hasMore: boolean = false 89 hasMore: boolean = false
  90 + /*展开子评论的状态下是否有展开更多*/
  91 + childsHasMore: boolean = false
  92 + /*子评论pageNum*/
  93 + pageNum:number = 1
90 /*当有展示更多的时候,当前的状态是展开还是收起*/ 94 /*当有展示更多的时候,当前的状态是展开还是收起*/
91 expanded: boolean = false 95 expanded: boolean = false
92 /*是否正在加载子评论*/ 96 /*是否正在加载子评论*/
1 @Observed 1 @Observed
2 export class publishCommentModel { 2 export class publishCommentModel {
3 - /*被评论的内容id*/ 3 +
  4 + //页面必传
  5 + /*被评论的内容id 页面必传*/
4 targetId: string = "" 6 targetId: string = ""
5 - /*被评论的内容关系id*/ 7 + /*被评论的内容关系id 页面必传*/
6 targetRelId: string = "" 8 targetRelId: string = ""
7 - /*1.文字 2.文字+表情 3.定制表情(客户端写死) 4.图片*/  
8 - commentType: string = '1'  
9 - /*根评论id,如果是一级评论,传-1;否则,传当前评论所属的根评论id*/  
10 - rootCommentId: string = "-1"  
11 - /*【迭代二新增】内容的标题,取bff内容详情接口中newsTitle字段*/ 9 + /*【迭代二新增】内容的标题,取bff内容详情接口中newsTitle字段 页面必传*/
12 targetTitle: string = "" 10 targetTitle: string = ""
13 - /*被评论的内容关系类型,1.频道关系;2.专题关系;【人民号内容为空】默认0*/ 11 + /*被评论的内容关系类型,1.频道关系;2.专题关系;【人民号内容为空】默认0 页面必传*/
14 targetRelType: string = '' 12 targetRelType: string = ''
15 - /*【迭代二新增】关联的频道id/专题id;*/ 13 + /*【迭代二新增】关联的频道id/专题id; 页面必传*/
16 targetRelObjectId: string = "" 14 targetRelObjectId: string = ""
  15 + /*【迭代二新增】是否是重点稿件 1是 0否 页面必传*/
  16 + keyArticle: string = ''
  17 + /*内容类别, 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增) 页面必传*/
  18 + targetType: string = ''
  19 +
  20 +
  21 + //评论传参
17 /*评论图片url,多个逗号隔开*/ 22 /*评论图片url,多个逗号隔开*/
18 commentPics: string = "" 23 commentPics: string = ""
19 /*评论内容*/ 24 /*评论内容*/
20 commentContent: string = "" 25 commentContent: string = ""
21 - /*【迭代二新增】是否是重点稿件 1是 0否*/  
22 - keyArticle: string = ''  
23 - /*内容类别, 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增)*/  
24 - targetType: string = '' 26 + /*1.文字 2.文字+表情 3.定制表情(客户端写死) 4.图片*/
  27 + commentType: string = '1'
  28 + /*根评论id,如果是一级评论,传-1;否则,传当前评论所属的根评论id*/
  29 + rootCommentId: string = "-1"
25 /*父评论id,如果是其它评论的回复,该字段必填*/ 30 /*父评论id,如果是其它评论的回复,该字段必填*/
26 parentId: string = "-1" 31 parentId: string = "-1"
27 32
28 33
  34 + //可选
29 placeHolderText: string = "优质评论会获得最佳评论人的称号" 35 placeHolderText: string = "优质评论会获得最佳评论人的称号"
30 36
31 } 37 }
@@ -12,36 +12,37 @@ import { ifaa } from '@kit.OnlineAuthenticationKit'; @@ -12,36 +12,37 @@ import { ifaa } from '@kit.OnlineAuthenticationKit';
12 12
13 const TAG = 'CommentComponent'; 13 const TAG = 'CommentComponent';
14 14
  15 +const testString = '因为读书的人\n是低着头向上看的人\n身处一隅,却能放眼世界\n2,因为读书的人\n总是比不读书的人\n活得有趣一点\n3,因为读书的人\n即使平凡,绝不平庸'
15 16
16 // @Entry 17 // @Entry
17 @Preview 18 @Preview
18 @Component 19 @Component
19 export struct CommentComponent { 20 export struct CommentComponent {
20 - @State contentId: string = '30004266013'  
21 - /*内容类别, 1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增)*/  
22 - @State contentType: string = '8'  
23 - /*内容的标题,取bff内容详情接口中newsTitle字段*/  
24 - @State targetTitle: string = '北约同意向乌克兰提供防空系统在内的更多军事支持'  
25 - /*被评论的内容关系id*/  
26 - @State targetRelId: string = "500002849023"  
27 - /*关联的频道id/专题id*/  
28 - @State targetRelObjectId: string = "2002"  
29 - /*是否是重点稿件 1是 0否*/  
30 - @State keyArticle: string = "0"  
31 - /*被评论的内容关系类型,1.频道关系;2.专题关系;【人民号内容为空】默认0*/  
32 - @State targetRelType: string = "1" 21 +
33 // @State private browSingModel: commentListModel = new commentListModel() 22 // @State private browSingModel: commentListModel = new commentListModel()
  23 + /*必传*/
  24 + @ObjectLink publishCommentModel: publishCommentModel
  25 +
34 isloading: boolean = false 26 isloading: boolean = false
  27 +
35 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource(); 28 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
36 - @State publishCommentModel: publishCommentModel = new publishCommentModel()  
37 - @State dialogController: CustomDialogController | null = new CustomDialogController({  
38 29
  30 + @State dialogController: CustomDialogController | null = null;
  31 +
  32 +
  33 + // 在自定义组件即将析构销毁时将dialogControlle置空
  34 + aboutToDisappear() {
  35 + this.dialogController = null // 将dialogController置空
  36 + }
  37 +
  38 + aboutToAppear() {
  39 +
  40 + this.dialogController = new CustomDialogController({
39 builder: CommentCustomDialog({ 41 builder: CommentCustomDialog({
40 confirm: (value: Record<string, string>) => { 42 confirm: (value: Record<string, string>) => {
41 - this.publishComment(value) 43 +
42 }, 44 },
43 - commentText: this.publishCommentModel.commentContent,  
44 - placeHolderText: this.publishCommentModel.placeHolderText, 45 + publishCommentModel:this.publishCommentModel
45 }), 46 }),
46 autoCancel: true, 47 autoCancel: true,
47 alignment: DialogAlignment.Bottom, 48 alignment: DialogAlignment.Bottom,
@@ -52,20 +53,6 @@ export struct CommentComponent { @@ -52,20 +53,6 @@ export struct CommentComponent {
52 }, 53 },
53 }) 54 })
54 55
55 - // 在自定义组件即将析构销毁时将dialogControlle置空  
56 - aboutToDisappear() {  
57 - this.dialogController = null // 将dialogController置空  
58 - }  
59 -  
60 - aboutToAppear() {  
61 - this.publishCommentModel.targetTitle = this.targetTitle  
62 - this.publishCommentModel.targetId = this.contentId  
63 - this.publishCommentModel.targetType = this.contentType  
64 - this.publishCommentModel.targetRelId = this.targetRelId  
65 - this.publishCommentModel.targetRelType = this.targetRelType  
66 - this.publishCommentModel.targetRelObjectId = this.targetRelObjectId  
67 - this.publishCommentModel.keyArticle = this.keyArticle  
68 -  
69 this.getData(); 56 this.getData();
70 57
71 } 58 }
@@ -105,7 +92,7 @@ export struct CommentComponent { @@ -105,7 +92,7 @@ export struct CommentComponent {
105 /*查看更多和收起*/ 92 /*查看更多和收起*/
106 @Builder 93 @Builder
107 GroupFooterView(item: commentItemModel, index: number) { 94 GroupFooterView(item: commentItemModel, index: number) {
108 - footerExpandedView({ item: item, contentId: this.contentId, contentType: this.contentType }) 95 + footerExpandedView({ item: item, contentId: this.publishCommentModel.targetId, contentType: this.publishCommentModel.targetType })
109 } 96 }
110 97
111 build() { 98 build() {
@@ -152,13 +139,13 @@ export struct CommentComponent { @@ -152,13 +139,13 @@ export struct CommentComponent {
152 139
153 //获取数据 140 //获取数据
154 async getData() { 141 async getData() {
155 - commentViewModel.fetchContentCommentList('1', this.contentId, this.contentType).then(commentListModel => { 142 + commentViewModel.fetchContentCommentList('1', this.publishCommentModel.targetId, this.publishCommentModel.targetType).then(commentListModel => {
156 if (commentListModel && commentListModel.list && commentListModel.list.length > 0) { 143 if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
157 commentListModel.list.forEach(element => { 144 commentListModel.list.forEach(element => {
158 element.hasMore = Number.parseInt(element.childCommentNum) ? true : false 145 element.hasMore = Number.parseInt(element.childCommentNum) ? true : false
159 let newModel = commentViewModel.deepCopyCommentItemModel(element) 146 let newModel = commentViewModel.deepCopyCommentItemModel(element)
160 - newModel.targetId = this.contentId  
161 - newModel.targetType = this.contentType 147 + // newModel.targetId = this.publishCommentModel.targetId
  148 + // newModel.targetType = this.publishCommentModel.targetType
162 this.allDatas.push(newModel) 149 this.allDatas.push(newModel)
163 }); 150 });
164 151
@@ -167,20 +154,6 @@ export struct CommentComponent { @@ -167,20 +154,6 @@ export struct CommentComponent {
167 }) 154 })
168 155
169 } 156 }
170 -  
171 - /*回复评论*/  
172 - publishComment(value: Record<string, string>) {  
173 -  
174 - this.publishCommentModel.commentContent = value['commentContent']  
175 - this.publishCommentModel.commentType = value['commentType']  
176 -  
177 - commentViewModel.publishComment(this.publishCommentModel).then(() => {  
178 - this.publishCommentModel.commentContent = ''  
179 - }).catch(() => {  
180 -  
181 - })  
182 -  
183 - }  
184 } 157 }
185 158
186 159
@@ -230,7 +203,7 @@ struct ChildCommentItem { @@ -230,7 +203,7 @@ struct ChildCommentItem {
230 .fontSize(14) 203 .fontSize(14)
231 .fontColor($r('app.color.color_222222')) 204 .fontColor($r('app.color.color_222222'))
232 .fontWeight(FontWeight.Medium) 205 .fontWeight(FontWeight.Medium)
233 - .margin({ left: 0 , right:0}) 206 + .margin({ left: 0, right: 0 })
234 207
235 208
236 /// 暂时不显示 “我” 的标签了 209 /// 暂时不显示 “我” 的标签了
@@ -257,10 +230,12 @@ struct ChildCommentItem { @@ -257,10 +230,12 @@ struct ChildCommentItem {
257 .margin({ left: 5 }); 230 .margin({ left: 5 });
258 } 231 }
259 }.margin({ left: 0, right: 16 }) 232 }.margin({ left: 0, right: 16 })
  233 +
260 // .backgroundColor(Color.Red) 234 // .backgroundColor(Color.Red)
261 235
262 CommentText({ 236 CommentText({
263 longMessage: this.item.commentContent, 237 longMessage: this.item.commentContent,
  238 + // longMessage:testString,
264 maxline: 3, 239 maxline: 3,
265 fontSize: 14, 240 fontSize: 14,
266 fontWeight: FontWeight.Regular, 241 fontWeight: FontWeight.Regular,
@@ -297,12 +272,27 @@ struct footerExpandedView { @@ -297,12 +272,27 @@ struct footerExpandedView {
297 build() { 272 build() {
298 Row() { 273 Row() {
299 if (this.item.expanded) { 274 if (this.item.expanded) {
  275 + if (this.item.childsHasMore) {
  276 + Row() {
  277 + Text().backgroundColor($r('app.color.color_EDEDED')).width(24).height(1)
  278 + Text('查看更多回复').fontColor($r('app.color.color_222222')).fontSize(14).margin({ left: 6 })
  279 + Image($r('app.media.comment_unfold')).width(12).height(12)
  280 + }.margin({ left: 53 })
  281 + .onClick(() => {
  282 + if (this.item.isLoading) {
  283 + return
  284 + }
  285 + this.item.isLoading = true
  286 + fetchChildContentCommentList(this.contentId, this.contentType, this.item)
  287 + })
  288 + }
300 Row() { 289 Row() {
301 Text('收起').fontColor($r('app.color.color_222222')).fontSize(14) 290 Text('收起').fontColor($r('app.color.color_222222')).fontSize(14)
302 Image($r('app.media.comment_pickUp')).width(12).height(12) 291 Image($r('app.media.comment_pickUp')).width(12).height(12)
303 - }.margin({ left: 213 }) 292 + }.margin({ left: this.item.childsHasMore ? 32 : 213 })
304 .onClick(() => { 293 .onClick(() => {
305 - this.item.expanded = !this.item.expanded 294 + this.item.pageNum = 1
  295 + this.item.expanded = false
306 this.item.childComments = [] 296 this.item.childComments = []
307 this.item.childCommentsLazyDataSource.clear() 297 this.item.childCommentsLazyDataSource.clear()
308 }) 298 })
@@ -317,28 +307,35 @@ struct footerExpandedView { @@ -317,28 +307,35 @@ struct footerExpandedView {
317 return 307 return
318 } 308 }
319 this.item.isLoading = true 309 this.item.isLoading = true
320 - //load child  
321 - commentViewModel.fetchChildContentCommentList('1', this.contentId, this.contentType, this.item.id) 310 + fetchChildContentCommentList(this.contentId, this.contentType, this.item)
  311 + })
  312 + }
  313 + }.height(30)
  314 + }
  315 +}
  316 +
  317 +function fetchChildContentCommentList(contentId: string, contentType: string, item: commentItemModel) {
  318 +
  319 + commentViewModel.fetchChildContentCommentList(item.pageNum + '', contentId, contentType, item.id)
322 .then((commentListModel) => { 320 .then((commentListModel) => {
323 - this.item.isLoading = false  
324 - this.item.expanded = !this.item.expanded 321 + item.pageNum = item.pageNum + 1
  322 + item.childsHasMore = commentListModel.hasNext > 0 ? true : false
  323 + item.isLoading = false
  324 + item.expanded = true
325 commentListModel.list.forEach(element => { 325 commentListModel.list.forEach(element => {
326 - this.item.childComments.push(element) 326 + item.childComments.push(element)
327 let newModel = commentViewModel.deepCopyCommentItemModel(element) 327 let newModel = commentViewModel.deepCopyCommentItemModel(element)
328 - newModel.targetId = this.contentId  
329 - newModel.targetType = this.contentType 328 + newModel.targetId = contentId
  329 + newModel.targetType = contentType
330 330
331 - this.item.childCommentsLazyDataSource.push(newModel) 331 + item.childCommentsLazyDataSource.push(newModel)
332 }) 332 })
333 }).catch(() => { 333 }).catch(() => {
334 - this.item.isLoading = false  
335 - }) 334 + item.isLoading = false
336 }) 335 })
337 - }  
338 - }.height(30)  
339 - }  
340 } 336 }
341 337
  338 +
342 @Component 339 @Component
343 struct commentHeaderView { 340 struct commentHeaderView {
344 @Link publishCommentModel: publishCommentModel 341 @Link publishCommentModel: publishCommentModel
@@ -411,7 +408,14 @@ struct commentHeaderView { @@ -411,7 +408,14 @@ struct commentHeaderView {
411 marginWidth: (59 + 16) 408 marginWidth: (59 + 16)
412 }) 409 })
413 .margin({ left: 59, right: 16, top: -5 }) 410 .margin({ left: 59, right: 16, top: -5 })
414 - 411 + .onClick(() => {
  412 + this.publishCommentModel.rootCommentId = this.item.rootCommentId
  413 + this.publishCommentModel.parentId = this.item.id
  414 + this.publishCommentModel.placeHolderText = '回复' + this.item.fromUserName + ':'
  415 + if (this.dialogController != null) {
  416 + this.dialogController.open()
  417 + }
  418 + })
415 419
416 commentFooterView({ 420 commentFooterView({
417 item: this.item, 421 item: this.item,
@@ -456,7 +460,12 @@ struct commentFooterView { @@ -456,7 +460,12 @@ struct commentFooterView {
456 .fontColor($r('app.color.color_222222')) 460 .fontColor($r('app.color.color_222222'))
457 .fontSize(12) 461 .fontSize(12)
458 .onClick(() => { 462 .onClick(() => {
459 - //TODO: 回复 463 + this.publishCommentModel.rootCommentId = this.item.rootCommentId
  464 + this.publishCommentModel.parentId = this.item.id
  465 + this.publishCommentModel.placeHolderText = '回复' + this.item.fromUserName + ':'
  466 + if (this.dialogController != null) {
  467 + this.dialogController.open()
  468 + }
460 }) 469 })
461 } 470 }
462 471
@@ -5,27 +5,51 @@ import commentViewModel from '../viewmodel/CommentViewModel' @@ -5,27 +5,51 @@ import commentViewModel from '../viewmodel/CommentViewModel'
5 @Preview 5 @Preview
6 @CustomDialog 6 @CustomDialog
7 export struct CommentCustomDialog { 7 export struct CommentCustomDialog {
8 - commentText: string = ''  
9 - placeHolderText: string = '优质评论会获得最佳评论人的称号' 8 +
  9 + @ObjectLink publishCommentModel: publishCommentModel
10 controller?: CustomDialogController 10 controller?: CustomDialogController
11 confirm: (value: Record<string, string>) => void = () => { 11 confirm: (value: Record<string, string>) => void = () => {
12 } 12 }
13 @State private emojiSwitch: boolean = false 13 @State private emojiSwitch: boolean = false
14 textInputController: TextAreaController = new TextAreaController() 14 textInputController: TextAreaController = new TextAreaController()
15 15
  16 + aboutToAppear(): void {
  17 +
  18 +
  19 + }
  20 +
  21 + publishCommentRequest() {
  22 + let bean: Record<string, string> = {};
  23 + // this.publishCommentModel.commentContent = this.commentText
  24 + //TODO 判断类型
  25 + this.publishCommentModel.commentType = '1'
  26 + commentViewModel.publishComment(this.publishCommentModel).then(() => {
  27 + this.publishCommentModel.commentContent = ''
  28 + // this.commentText = ''
  29 + if (this.controller != null) {
  30 + this.controller.close()
  31 + }
  32 + this.confirm(bean)
  33 + }).catch(() => {
  34 + if (this.controller != null) {
  35 + this.controller.close()
  36 + }
  37 + })
  38 + }
  39 +
16 build() { 40 build() {
17 Column() { 41 Column() {
18 Row() { 42 Row() {
19 TextArea({ 43 TextArea({
20 - placeholder: this.placeHolderText, 44 + placeholder: this.publishCommentModel.placeHolderText,
21 controller: this.textInputController, 45 controller: this.textInputController,
22 - text: this.commentText 46 + text: this.publishCommentModel.commentContent
23 }) 47 })
24 .height('100%') 48 .height('100%')
25 .width('100%') 49 .width('100%')
26 .backgroundColor($r('app.color.color_transparent')) 50 .backgroundColor($r('app.color.color_transparent'))
27 .onChange(value => { 51 .onChange(value => {
28 - this.commentText = value; 52 + this.publishCommentModel.commentContent = value;
29 }) 53 })
30 } 54 }
31 .backgroundColor('#F9F9F9') 55 .backgroundColor('#F9F9F9')
@@ -68,18 +92,11 @@ export struct CommentCustomDialog { @@ -68,18 +92,11 @@ export struct CommentCustomDialog {
68 .textAlign(TextAlign.Center) 92 .textAlign(TextAlign.Center)
69 .borderRadius(4) 93 .borderRadius(4)
70 .onClick(() => { 94 .onClick(() => {
71 - if (this.commentText.length > 0) { 95 + if (this.publishCommentModel.commentContent.length > 0) {
72 //请求评论接口 96 //请求评论接口
73 //commentType 97 //commentType
74 //commentContent 98 //commentContent
75 - let bean: Record<string, string> = {};  
76 - bean['commentContent'] = this.commentText  
77 - //TODO 判断类型  
78 - bean['commentType'] = '1'  
79 - this.confirm(bean)  
80 - if (this.controller != null) {  
81 - this.controller.close()  
82 - } 99 + this.publishCommentRequest()
83 } 100 }
84 }) 101 })
85 } 102 }
@@ -239,7 +239,8 @@ class CommentViewModel { @@ -239,7 +239,8 @@ class CommentViewModel {
239 239
240 let promiseArray: Promise<commentStatusListModel | void>[] = []; 240 let promiseArray: Promise<commentStatusListModel | void>[] = [];
241 241
242 - //TODO 未登录不用批查 242 + //未登录不用批查
  243 + if (HttpUrlUtils.getUserId()){
243 if (commentIDs.length > 0) { 244 if (commentIDs.length > 0) {
244 let promise1 = new Promise<void>((success) => { 245 let promise1 = new Promise<void>((success) => {
245 // HttpRequest HttpBizUtil 246 // HttpRequest HttpBizUtil
@@ -284,7 +285,7 @@ class CommentViewModel { @@ -284,7 +285,7 @@ class CommentViewModel {
284 }) 285 })
285 promiseArray.push(promise1); 286 promiseArray.push(promise1);
286 } 287 }
287 - 288 + }
288 if (fromUserIDs.length > 0) { 289 if (fromUserIDs.length > 0) {
289 let promise2 = new Promise<void>((success) => { 290 let promise2 = new Promise<void>((success) => {
290 let url = HttpUrlUtils.getBatchUserUrl(); 291 let url = HttpUrlUtils.getBatchUserUrl();
@@ -385,21 +386,7 @@ class CommentViewModel { @@ -385,21 +386,7 @@ class CommentViewModel {
385 386
386 } 387 }
387 388
388 - commnetLikeChange(model: commentItemModel) {  
389 - model.api_status = !model.api_status  
390 - //点赞  
391 - if (model.api_status) {  
392 - model.likeNum = (Number.parseInt(model.likeNum) + 1) + ''  
393 - }  
394 - //取消点赞  
395 - if (!model.api_status) {  
396 - model.likeNum = (Number.parseInt(model.likeNum) - 1) + ''  
397 - if (Number.parseInt(model.likeNum) < 0) {  
398 - model.likeNum = '0'  
399 - }  
400 - }  
401 - // return model  
402 - } 389 +
403 390
404 deepCopyCommentItemModel(model: commentItemModel) { 391 deepCopyCommentItemModel(model: commentItemModel) {
405 let newModel = new commentItemModel() 392 let newModel = new commentItemModel()