yangsunyue_wd

desc:评论相关

1 -import { Logger, NumberFormatterUtils, DateTimeUtils } from 'wdKit'; 1 +import { Logger, NumberFormatterUtils, DateTimeUtils, EmitterUtils, EmitterEventId } from 'wdKit';
2 import { 2 import {
3 Action, 3 Action,
4 ContentDetailDTO, 4 ContentDetailDTO,
@@ -126,6 +126,7 @@ export struct ImageAndTextPageComponent { @@ -126,6 +126,7 @@ export struct ImageAndTextPageComponent {
126 CommentComponent({ 126 CommentComponent({
127 publishCommentModel: this.publishCommentModel 127 publishCommentModel: this.publishCommentModel
128 }) 128 })
  129 + // .onMeasureSize()
129 } 130 }
130 } 131 }
131 } 132 }
@@ -280,6 +281,15 @@ export struct ImageAndTextPageComponent { @@ -280,6 +281,15 @@ export struct ImageAndTextPageComponent {
280 281
281 aboutToAppear() { 282 aboutToAppear() {
282 this.getDetail() 283 this.getDetail()
  284 + //注册通知,来自别的组件的评论成功通知
  285 + EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, (targetId?: string) => {
  286 + if (targetId) {
  287 + if (targetId == this.publishCommentModel.targetId) {
  288 + // 滚动到评论列表
  289 +
  290 + }
  291 + }
  292 + })
283 } 293 }
284 294
285 aboutToDisappear() { 295 aboutToDisappear() {
@@ -25,6 +25,10 @@ export struct CommentComponent { @@ -25,6 +25,10 @@ export struct CommentComponent {
25 // @State private browSingModel: commentListModel = new commentListModel() 25 // @State private browSingModel: commentListModel = new commentListModel()
26 /*必传*/ 26 /*必传*/
27 @ObjectLink publishCommentModel: publishCommentModel 27 @ObjectLink publishCommentModel: publishCommentModel
  28 +
  29 + listScroller: ListScroller = new ListScroller(); // scroller控制器
  30 + historyOffset: number = 0; // 上次浏览到列表距离顶端的偏移量offset
  31 +
28 isloading: boolean = false 32 isloading: boolean = false
29 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource(); 33 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
30 @State dialogController: CustomDialogController | null = null; 34 @State dialogController: CustomDialogController | null = null;
@@ -69,11 +73,12 @@ export struct CommentComponent { @@ -69,11 +73,12 @@ export struct CommentComponent {
69 73
70 // 74 //
71 addCommentLocal() { 75 addCommentLocal() {
72 - let model = commentViewModel.deepCopyCommentItemModel(this.publishCommentModel.lastCommentModel) 76 + // let model = commentViewModel.deepCopyCommentItemModel(this.publishCommentModel.lastCommentModel)
  77 + let model = this.publishCommentModel.lastCommentModel
73 /*一级评论*/ 78 /*一级评论*/
  79 + // if (this.publishCommentModel.lastCommentModel)
74 if (this.publishCommentModel.lastCommentModel.parentId == '-1') { 80 if (this.publishCommentModel.lastCommentModel.parentId == '-1') {
75 this.allDatas.addFirstItem(model) 81 this.allDatas.addFirstItem(model)
76 - //TODO 跳转顶部  
77 } else { 82 } else {
78 //二级评论 83 //二级评论
79 this.allDatas.getDataArray().forEach(element => { 84 this.allDatas.getDataArray().forEach(element => {
@@ -134,7 +139,7 @@ export struct CommentComponent { @@ -134,7 +139,7 @@ export struct CommentComponent {
134 139
135 build() { 140 build() {
136 Column() { 141 Column() {
137 - List() { 142 + List({scroller:this.listScroller}) {
138 ListItemGroup({ header: this.titleHeader() }) 143 ListItemGroup({ header: this.titleHeader() })
139 144
140 LazyForEach(this.allDatas, (item: commentItemModel, index: number) => { 145 LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
@@ -176,7 +181,9 @@ export struct CommentComponent { @@ -176,7 +181,9 @@ export struct CommentComponent {
176 if (this.hasMore === false) NoMoreLayout() 181 if (this.hasMore === false) NoMoreLayout()
177 } 182 }
178 } 183 }
179 - 184 +// .onScrollFrameBegin((offset: number, state: ScrollState)=>{
  185 +//
  186 +// })
180 .onReachEnd(()=>{ 187 .onReachEnd(()=>{
181 if (this.hasMore) { 188 if (this.hasMore) {
182 this.getData() 189 this.getData()
@@ -27,7 +27,9 @@ export struct CommentCustomDialog { @@ -27,7 +27,9 @@ export struct CommentCustomDialog {
27 this.publishCommentModel.commentType = '2' 27 this.publishCommentModel.commentType = '2'
28 commentViewModel.publishComment(this.publishCommentModel).then((model:commentItemModel) => { 28 commentViewModel.publishComment(this.publishCommentModel).then((model:commentItemModel) => {
29 this.publishCommentModel.commentContent = '' 29 this.publishCommentModel.commentContent = ''
30 - this.publishCommentModel.lastCommentModel = model 30 + //
  31 +
  32 + this.publishCommentModel.lastCommentModel = commentViewModel.deepCopyCommentItemModel(model)
31 // this.commentText = '' 33 // this.commentText = ''
32 if (this.controller != null) { 34 if (this.controller != null) {
33 this.controller.close() 35 this.controller.close()
@@ -44,7 +44,10 @@ export struct CommentTabComponent { @@ -44,7 +44,10 @@ export struct CommentTabComponent {
44 } 44 }
45 }.width(151).height(30) 45 }.width(151).height(30)
46 .onClick(() => { 46 .onClick(() => {
  47 +
  48 + this.publishCommentModel.rootCommentId = '-1';
47 this.publishCommentModel.parentId = '-1'; 49 this.publishCommentModel.parentId = '-1';
  50 + this.publishCommentModel.placeHolderText = "优质评论会获得最佳评论人的称号"
48 this.dialogController?.open(); 51 this.dialogController?.open();
49 }) 52 })
50 } 53 }