chenquansheng

ref |> 添加长按评论回复功能

@@ -45,6 +45,9 @@ export struct CommentComponent { @@ -45,6 +45,9 @@ export struct CommentComponent {
45 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource(); 45 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
46 firstPageHotIds: string = '' 46 firstPageHotIds: string = ''
47 @State dialogController: CustomDialogController | null = null; 47 @State dialogController: CustomDialogController | null = null;
  48 + @State customDialogController: CustomDialogController | null = null;
  49 + @State delDialogController: CustomDialogController | null = null;
  50 +
48 // @State private browSingModel: commentListModel = new commentListModel() 51 // @State private browSingModel: commentListModel = new commentListModel()
49 52
50 // 是否为固定高度模式。true时,里面上拉加载更多生效,外层不能包Scroll。 53 // 是否为固定高度模式。true时,里面上拉加载更多生效,外层不能包Scroll。
@@ -69,6 +72,8 @@ export struct CommentComponent { @@ -69,6 +72,8 @@ export struct CommentComponent {
69 // 在自定义组件即将析构销毁时将dialogControlle置空 72 // 在自定义组件即将析构销毁时将dialogControlle置空
70 aboutToDisappear() { 73 aboutToDisappear() {
71 this.dialogController = null // 将dialogController置空 74 this.dialogController = null // 将dialogController置空
  75 + this.customDialogController = null
  76 + this.delDialogController = null
72 } 77 }
73 78
74 aboutToAppear() { 79 aboutToAppear() {
@@ -104,6 +109,32 @@ export struct CommentComponent { @@ -104,6 +109,32 @@ export struct CommentComponent {
104 maskColor: "#50000000", 109 maskColor: "#50000000",
105 }) 110 })
106 111
  112 + this.customDialogController = new CustomDialogController({
  113 + builder:DeleteCommentDialogView({
  114 + configItem:this.itemType(),
  115 + confirmCallback: (actionType:PublicCommentMoreActionType) =>{
  116 + this.confirmCallback(actionType)
  117 + }
  118 + }),
  119 + alignment:DialogAlignment.Bottom
  120 + })
  121 +
  122 + this.delDialogController = new CustomDialogController({
  123 + builder: ConfirmLogoutDialog({
  124 + tipShow:false,
  125 + title:"是否确认删除?",
  126 + leftText:"取消",
  127 + leftTextColor:$r('app.color.color_648DF2'),
  128 + rightText:"确认",
  129 + cancelIsLeft:true,
  130 + confirm: () => {
  131 + this.deleteComponent()
  132 + }
  133 + }),
  134 + customStyle: true,
  135 + alignment: DialogAlignment.Center
  136 + })
  137 +
107 this.getData(); 138 this.getData();
108 139
109 this.windowClass = WindowModel.shared.getWindowClass(); // 获取应用主窗口 140 this.windowClass = WindowModel.shared.getWindowClass(); // 获取应用主窗口
@@ -149,32 +180,6 @@ export struct CommentComponent { @@ -149,32 +180,6 @@ export struct CommentComponent {
149 } 180 }
150 } 181 }
151 182
152 - customDialogController: CustomDialogController = new CustomDialogController({  
153 - builder:DeleteCommentDialogView({  
154 - configItem:this.itemType(),  
155 - confirmCallback: (actionType:PublicCommentMoreActionType) =>{  
156 - this.confirmCallback(actionType)  
157 - }  
158 - }),  
159 - alignment:DialogAlignment.Bottom  
160 - })  
161 -  
162 - delDialogController: CustomDialogController = new CustomDialogController({  
163 - builder: ConfirmLogoutDialog({  
164 - tipShow:false,  
165 - title:"是否确认删除?",  
166 - leftText:"取消",  
167 - leftTextColor:$r('app.color.color_648DF2'),  
168 - rightText:"确认",  
169 - cancelIsLeft:true,  
170 - confirm: () => {  
171 - this.deleteComponent()  
172 - }  
173 - }),  
174 - customStyle: true,  
175 - alignment: DialogAlignment.Center  
176 - })  
177 -  
178 confirmCallback(actionType:PublicCommentMoreActionType){ 183 confirmCallback(actionType:PublicCommentMoreActionType){
179 184
180 //复制评论内容 185 //复制评论内容
@@ -194,7 +199,7 @@ export struct CommentComponent { @@ -194,7 +199,7 @@ export struct CommentComponent {
194 199
195 if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Delete) { 200 if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Delete) {
196 //删除评论内容 201 //删除评论内容
197 - this.delDialogController.open(); 202 + this.delDialogController?.open();
198 return 203 return
199 } 204 }
200 205
@@ -243,9 +248,9 @@ export struct CommentComponent { @@ -243,9 +248,9 @@ export struct CommentComponent {
243 248
244 itemType() { 249 itemType() {
245 let typeArr:string[] = [] 250 let typeArr:string[] = []
246 - // if (this.item.id && this.item.checkStatus == '2') {  
247 - // typeArr.push('回复')  
248 - // } 251 + if (this.item.id && this.item.checkStatus == '2') {
  252 + typeArr.push('回复')
  253 + }
249 typeArr.push('复制') 254 typeArr.push('复制')
250 if (HttpUtils.isLogin()) { 255 if (HttpUtils.isLogin()) {
251 if (HttpUtils.getUserId() == this.item.fromUserId) { 256 if (HttpUtils.getUserId() == this.item.fromUserId) {
@@ -256,7 +261,7 @@ export struct CommentComponent { @@ -256,7 +261,7 @@ export struct CommentComponent {
256 } 261 }
257 262
258 showDeleteCommentDialogView(){ 263 showDeleteCommentDialogView(){
259 - this.customDialogController.open(); 264 + this.customDialogController?.open();
260 } 265 }
261 266
262 /*标题:全部评论*/ 267 /*标题:全部评论*/
@@ -585,6 +590,17 @@ struct ChildCommentItem { @@ -585,6 +590,17 @@ struct ChildCommentItem {
585 @Consume inDialog: boolean 590 @Consume inDialog: boolean
586 private dialogBeforeJumpOtherPageAction: () => void = () => {} 591 private dialogBeforeJumpOtherPageAction: () => void = () => {}
587 private longPressCommentAction: () => void = () => {} 592 private longPressCommentAction: () => void = () => {}
  593 + private isLongPress:boolean = false
  594 +
  595 + aboutToAppear() {
  596 + getContext(this).eventHub.on('1',()=>{
  597 +
  598 + if (this.isLongPress) {
  599 + this.replyComment()
  600 + this.isLongPress = false
  601 + }
  602 + })
  603 + }
588 604
589 build() { 605 build() {
590 Column() { 606 Column() {
@@ -653,6 +669,7 @@ struct ChildCommentItem { @@ -653,6 +669,7 @@ struct ChildCommentItem {
653 LongPressGesture() 669 LongPressGesture()
654 .onAction((event: GestureEvent|undefined)=>{ 670 .onAction((event: GestureEvent|undefined)=>{
655 if (event) { 671 if (event) {
  672 + this.isLongPress = true
656 this.longPressCommentAction() 673 this.longPressCommentAction()
657 } 674 }
658 }) 675 })
@@ -841,6 +858,15 @@ struct commentHeaderView { @@ -841,6 +858,15 @@ struct commentHeaderView {
841 @Prop isZD: boolean = false 858 @Prop isZD: boolean = false
842 private isLongPress:boolean = false 859 private isLongPress:boolean = false
843 860
  861 + aboutToAppear() {
  862 + getContext(this).eventHub.on('1',()=>{
  863 +
  864 + if (this.isLongPress) {
  865 + this.replyComment()
  866 + this.isLongPress = false
  867 + }
  868 + })
  869 + }
844 870
845 build() { 871 build() {
846 Column() { 872 Column() {