wangliang_wd

Merge branch 'main' of http://192.168.1.42/developOne/harmonyPool into main

* 'main' of http://192.168.1.42/developOne/harmonyPool:
  ref |> 添加长按评论回复功能
  fix |> 修复子评论删除错误逻辑
  ref |> 评论删除逻辑添加
  fix |> 长按评论显示弹窗优化
@@ -501,6 +501,18 @@ export class HttpUrlUtils { @@ -501,6 +501,18 @@ export class HttpUrlUtils {
501 return url 501 return url
502 } 502 }
503 503
  504 + /*删除评论*/
  505 + static getDeleteCommentUrl() {
  506 + let url = HttpUrlUtils.getHost() + "/api/rmrb-comment/comment/zh/c/delete"
  507 + return url
  508 + }
  509 +
  510 + /*游客删除评论*/
  511 + static getNoUserDeleteCommentUrl() {
  512 + let url = HttpUrlUtils.getHost() + "/api/rmrb-comment/comment/zh/c/visitorDelete"
  513 + return url
  514 + }
  515 +
504 /*levleIcon*/ 516 /*levleIcon*/
505 static getBatchUserUrl() { 517 static getBatchUserUrl() {
506 let url = HttpUrlUtils.getHost() + "/api/rmrb-user-point/auth/level/zh/c/batchUser" 518 let url = HttpUrlUtils.getHost() + "/api/rmrb-user-point/auth/level/zh/c/batchUser"
1 import { DateTimeUtils, EmitterEventId, EmitterUtils, LazyDataSource, 1 import { DateTimeUtils, EmitterEventId, EmitterUtils, LazyDataSource,
2 Logger, 2 Logger,
3 PublicDialogManager, 3 PublicDialogManager,
4 - StringUtils } from 'wdKit/Index'; 4 + StringUtils,ToastUtils } from 'wdKit/Index';
5 import { CommentItemCustomType, commentItemModel, WDPublicUserType } from '../model/CommentModel'; 5 import { CommentItemCustomType, commentItemModel, WDPublicUserType } from '../model/CommentModel';
6 import commentViewModel from '../viewmodel/CommentViewModel'; 6 import commentViewModel from '../viewmodel/CommentViewModel';
7 import { CommentText } from './CommentText'; 7 import { CommentText } from './CommentText';
@@ -15,6 +15,9 @@ import { ContentDetailDTO, Params } from 'wdBean/Index'; @@ -15,6 +15,9 @@ import { ContentDetailDTO, Params } from 'wdBean/Index';
15 import { TrackingContent, TrackParamConvert } from 'wdTracking/Index'; 15 import { TrackingContent, TrackParamConvert } from 'wdTracking/Index';
16 import { WindowModel } from 'wdKit/Index'; 16 import { WindowModel } from 'wdKit/Index';
17 import { window } from '@kit.ArkUI'; 17 import { window } from '@kit.ArkUI';
  18 +import { DeleteCommentDialogView,PublicCommentMoreActionType } from '../../view/areaPickerDialog/DeleteCommentDialogView';
  19 +import {BusinessError, pasteboard} from '@kit.BasicServicesKit';
  20 +import { ConfirmLogoutDialog } from '../../../components/setting/ConfirmLogoutDialog';
18 21
19 const TAG = 'CommentComponent'; 22 const TAG = 'CommentComponent';
20 23
@@ -42,6 +45,9 @@ export struct CommentComponent { @@ -42,6 +45,9 @@ export struct CommentComponent {
42 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource(); 45 @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
43 firstPageHotIds: string = '' 46 firstPageHotIds: string = ''
44 @State dialogController: CustomDialogController | null = null; 47 @State dialogController: CustomDialogController | null = null;
  48 + @State customDialogController: CustomDialogController | null = null;
  49 + @State delDialogController: CustomDialogController | null = null;
  50 +
45 // @State private browSingModel: commentListModel = new commentListModel() 51 // @State private browSingModel: commentListModel = new commentListModel()
46 52
47 // 是否为固定高度模式。true时,里面上拉加载更多生效,外层不能包Scroll。 53 // 是否为固定高度模式。true时,里面上拉加载更多生效,外层不能包Scroll。
@@ -59,10 +65,15 @@ export struct CommentComponent { @@ -59,10 +65,15 @@ export struct CommentComponent {
59 @State isZD: boolean = false // 存储是否折叠屏 65 @State isZD: boolean = false // 存储是否折叠屏
60 private screenWidth: number = 0 66 private screenWidth: number = 0
61 @State windowWidth: number = AppStorage.get<number>('windowWidth') || 0 67 @State windowWidth: number = AppStorage.get<number>('windowWidth') || 0
  68 + private item: commentItemModel = new commentItemModel();
  69 + mainComment:boolean = false
  70 + itemIndex:number = 0
62 71
63 // 在自定义组件即将析构销毁时将dialogControlle置空 72 // 在自定义组件即将析构销毁时将dialogControlle置空
64 aboutToDisappear() { 73 aboutToDisappear() {
65 this.dialogController = null // 将dialogController置空 74 this.dialogController = null // 将dialogController置空
  75 + this.customDialogController = null
  76 + this.delDialogController = null
66 } 77 }
67 78
68 aboutToAppear() { 79 aboutToAppear() {
@@ -98,6 +109,32 @@ export struct CommentComponent { @@ -98,6 +109,32 @@ export struct CommentComponent {
98 maskColor: "#50000000", 109 maskColor: "#50000000",
99 }) 110 })
100 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 +
101 this.getData(); 138 this.getData();
102 139
103 this.windowClass = WindowModel.shared.getWindowClass(); // 获取应用主窗口 140 this.windowClass = WindowModel.shared.getWindowClass(); // 获取应用主窗口
@@ -141,7 +178,90 @@ export struct CommentComponent { @@ -141,7 +178,90 @@ export struct CommentComponent {
141 if (model) { 178 if (model) {
142 this.isComments = true 179 this.isComments = true
143 } 180 }
  181 + }
  182 +
  183 + confirmCallback(actionType:PublicCommentMoreActionType){
  184 +
  185 + //复制评论内容
  186 + if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Copy){
  187 + let systemPasteboard = pasteboard.getSystemPasteboard();
  188 + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, this.item?.commentContent)
  189 + // // 将数据写入系统剪贴板
  190 + systemPasteboard.setData(pasteData).then(()=>{
  191 + // 存入成功,处理正常场景
  192 + ToastUtils.shortToast('复制成功')
  193 + }).catch((error: BusinessError) => {
  194 + // 处理异常场景
  195 + Logger.debug(TAG, '长按文字存储失败:' + error);
  196 + });
  197 + return
  198 + }
  199 +
  200 + if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Delete) {
  201 + //删除评论内容
  202 + this.delDialogController?.open();
  203 + return
  204 + }
144 205
  206 + if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Reply) {
  207 + //回复评论
  208 + getContext(this).eventHub.emit('1')
  209 + }
  210 + }
  211 +
  212 + deleteComponent(){
  213 + commentViewModel.deleteComment(this.publishCommentModel.targetId,this.item)?.then(()=>{
  214 + // ToastUtils.shortToast('删除成功')
  215 + if (this.mainComment) {
  216 + this.allDatas.deleteItem(this.itemIndex)
  217 + let totalNum:number = Number(this.publishCommentModel.totalCommentNumer)
  218 + let childNum:number = Number(this.item.childCommentNum)
  219 + totalNum -= (childNum+1)
  220 + this.publishCommentModel.totalCommentNumer = totalNum.toString()
  221 + }else {
  222 + //删除子评论
  223 + for (let index = 0; index < this.allDatas.getDataArray().length; index++) {
  224 + const element = this.allDatas.getDataArray()[index];
  225 + if (element.api_customType === CommentItemCustomType.hotTitle
  226 + || element.api_customType === CommentItemCustomType.newTitle) {
  227 + continue;
  228 + }
  229 + /// 根据当前评论数据的父评论ID 查询数据源中的父评论数据
  230 + if (this.item.parentId == element.id && element.childCommentsLazyDataSource.getDataArray().length > 0) {
  231 + element.childCommentsLazyDataSource.deleteItem(this.itemIndex)
  232 + // element.childComments.splice(this.itemIndex,1)
  233 + let totalNum:number = Number(this.publishCommentModel.totalCommentNumer)
  234 + let childNum:number = Number(element.childCommentNum)
  235 + totalNum -= 1
  236 + childNum -= 1
  237 + element.childCommentNum = childNum.toString()
  238 + this.publishCommentModel.totalCommentNumer = totalNum.toString()
  239 + break;
  240 + }
  241 + }
  242 + }
  243 + })
  244 + .catch(()=>{
  245 +
  246 + })
  247 + }
  248 +
  249 + itemType() {
  250 + let typeArr:string[] = []
  251 + if (this.item.id && this.item.checkStatus == '2') {
  252 + typeArr.push('回复')
  253 + }
  254 + typeArr.push('复制')
  255 + if (HttpUtils.isLogin()) {
  256 + if (HttpUtils.getUserId() == this.item.fromUserId) {
  257 + typeArr.push('删除')
  258 + }
  259 + }
  260 + return typeArr
  261 + }
  262 +
  263 + showDeleteCommentDialogView(){
  264 + this.customDialogController?.open();
145 } 265 }
146 266
147 /*标题:全部评论*/ 267 /*标题:全部评论*/
@@ -192,6 +312,12 @@ export struct CommentComponent { @@ -192,6 +312,12 @@ export struct CommentComponent {
192 dialogController: this.dialogController, 312 dialogController: this.dialogController,
193 publishCommentModel: this.publishCommentModel, 313 publishCommentModel: this.publishCommentModel,
194 dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction, 314 dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
  315 + longPressCommentAction:()=>{
  316 + this.item = item
  317 + this.itemIndex = index
  318 + this.mainComment = true
  319 + this.showDeleteCommentDialogView()
  320 + },
195 isZD:isZD 321 isZD:isZD
196 }) 322 })
197 } 323 }
@@ -242,7 +368,13 @@ export struct CommentComponent { @@ -242,7 +368,13 @@ export struct CommentComponent {
242 item: childItem, 368 item: childItem,
243 dialogController: this.dialogController, 369 dialogController: this.dialogController,
244 publishCommentModel: this.publishCommentModel, 370 publishCommentModel: this.publishCommentModel,
245 - dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction 371 + dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
  372 + longPressCommentAction:()=>{
  373 + this.item = childItem
  374 + this.itemIndex = subIndex
  375 + this.mainComment = false
  376 + this.showDeleteCommentDialogView()
  377 + }
246 }); 378 });
247 } 379 }
248 .onClick(() => { 380 .onClick(() => {
@@ -258,7 +390,13 @@ export struct CommentComponent { @@ -258,7 +390,13 @@ export struct CommentComponent {
258 item: childItem, 390 item: childItem,
259 dialogController: this.dialogController, 391 dialogController: this.dialogController,
260 publishCommentModel: this.publishCommentModel, 392 publishCommentModel: this.publishCommentModel,
261 - dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction 393 + dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
  394 + longPressCommentAction:()=>{
  395 + this.item = childItem
  396 + this.itemIndex = subIndex
  397 + this.mainComment = false
  398 + this.showDeleteCommentDialogView()
  399 + },
262 }); 400 });
263 } 401 }
264 .onClick(() => { 402 .onClick(() => {
@@ -451,6 +589,18 @@ struct ChildCommentItem { @@ -451,6 +589,18 @@ struct ChildCommentItem {
451 private leftGap: number = 95 + 4 589 private leftGap: number = 95 + 4
452 @Consume inDialog: boolean 590 @Consume inDialog: boolean
453 private dialogBeforeJumpOtherPageAction: () => void = () => {} 591 private dialogBeforeJumpOtherPageAction: () => 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 + }
454 604
455 build() { 605 build() {
456 Column() { 606 Column() {
@@ -519,7 +669,8 @@ struct ChildCommentItem { @@ -519,7 +669,8 @@ struct ChildCommentItem {
519 LongPressGesture() 669 LongPressGesture()
520 .onAction((event: GestureEvent|undefined)=>{ 670 .onAction((event: GestureEvent|undefined)=>{
521 if (event) { 671 if (event) {
522 - //TODO: 显示功能菜单 672 + this.isLongPress = true
  673 + this.longPressCommentAction()
523 } 674 }
524 }) 675 })
525 ) 676 )
@@ -701,9 +852,21 @@ struct commentHeaderView { @@ -701,9 +852,21 @@ struct commentHeaderView {
701 852
702 @Consume inDialog: boolean 853 @Consume inDialog: boolean
703 private dialogBeforeJumpOtherPageAction: () => void = () => {} 854 private dialogBeforeJumpOtherPageAction: () => void = () => {}
  855 + private longPressCommentAction: () => void = () => {}
704 private leftGap: number = 64 856 private leftGap: number = 64
705 @State isCanClickHeader:boolean = true 857 @State isCanClickHeader:boolean = true
706 @Prop isZD: boolean = false 858 @Prop isZD: boolean = false
  859 + private isLongPress:boolean = false
  860 +
  861 + aboutToAppear() {
  862 + getContext(this).eventHub.on('1',()=>{
  863 +
  864 + if (this.isLongPress) {
  865 + this.replyComment()
  866 + this.isLongPress = false
  867 + }
  868 + })
  869 + }
707 870
708 build() { 871 build() {
709 Column() { 872 Column() {
@@ -762,6 +925,8 @@ struct commentHeaderView { @@ -762,6 +925,8 @@ struct commentHeaderView {
762 .onAction((event: GestureEvent|undefined)=>{ 925 .onAction((event: GestureEvent|undefined)=>{
763 if (event) { 926 if (event) {
764 //TODO: 显示功能菜单 927 //TODO: 显示功能菜单
  928 + this.isLongPress = true
  929 + this.longPressCommentAction()
765 } 930 }
766 }) 931 })
767 ) 932 )
@@ -850,6 +1015,7 @@ struct commentHeaderView { @@ -850,6 +1015,7 @@ struct commentHeaderView {
850 } 1015 }
851 1016
852 replyComment() { 1017 replyComment() {
  1018 +
853 if (this.item.id && this.item.checkStatus == '2') { // 审核通过的才显示回复 1019 if (this.item.id && this.item.checkStatus == '2') { // 审核通过的才显示回复
854 this.publishCommentModel.rootCommentId = this.item.rootCommentId 1020 this.publishCommentModel.rootCommentId = this.item.rootCommentId
855 this.publishCommentModel.parentId = this.item.id 1021 this.publishCommentModel.parentId = this.item.id
@@ -240,6 +240,37 @@ class CommentViewModel { @@ -240,6 +240,37 @@ class CommentViewModel {
240 }) 240 })
241 } 241 }
242 242
  243 + /*删除评论*/
  244 + deleteComment(contentId: string,model:commentItemModel){
  245 +
  246 + if (contentId.length == 0 || model.id.length == 0 || model.uuid.length == 0) {
  247 + return
  248 + }
  249 + return new Promise<void>((success, fail) => {//model.visitorComment == "1" &&
  250 + const visitorMode = HttpUtils.isLogin() == false
  251 + let url = visitorMode ? HttpUrlUtils.getNoUserDeleteCommentUrl() : HttpUrlUtils.getDeleteCommentUrl()
  252 + let bean: Record<string, string> = {};
  253 + bean['targetId'] = contentId;
  254 + bean['commentId'] = model.id;
  255 + bean['uuid'] = model.uuid;
  256 + if (visitorMode) {
  257 + bean['deviceId'] = DeviceUtil.clientId()
  258 + // bean['userName'] = SPHelper.default.getSync(SpConstants.TOURIST_NICK_NAME, "") as string
  259 + }
  260 + HttpBizUtil.post<ResponseDTO<object>>(url, bean).then((data: ResponseDTO<object>) => {
  261 + if (data.code != 0) {
  262 + fail()
  263 + return
  264 + }
  265 + Logger.debug('>>>>>>>删除成功:'+data.message)
  266 + success()
  267 + }, (error: Error) => {
  268 + fail()
  269 + Logger.debug('>>>>>>>删除失败:'+error.toString())
  270 + })
  271 + })
  272 + }
  273 +
243 async fetchCurrentUserAuthIcons(model: commentItemModel) { 274 async fetchCurrentUserAuthIcons(model: commentItemModel) {
244 if (false == HttpUtils.isLogin()) { 275 if (false == HttpUtils.isLogin()) {
245 return 276 return
@@ -2,14 +2,29 @@ @@ -2,14 +2,29 @@
2 @CustomDialog 2 @CustomDialog
3 3
4 export struct DeleteCommentDialogView { 4 export struct DeleteCommentDialogView {
5 - functionData:FunctionsItem[] = [  
6 - new FunctionsItem('回复',$r('app.media.DeleteComment_reply'),PublicCommentMoreActionType.PublicCommentMoreActionType_Reply),  
7 - new FunctionsItem('复制',$r('app.media.DeleteComment_copy'),PublicCommentMoreActionType.PublicCommentMoreActionType_Copy),  
8 - new FunctionsItem('删除',$r('app.media.DeleteComment_delete'),PublicCommentMoreActionType.PublicCommentMoreActionType_Delete)]  
9 5
  6 + @State configItem:string[] = ['回复','复制','删除']
  7 + @Provide functionData:FunctionsItem[] = []
10 controller: CustomDialogController 8 controller: CustomDialogController
11 confirmCallback: (actionType:PublicCommentMoreActionType) => void = () => { 9 confirmCallback: (actionType:PublicCommentMoreActionType) => void = () => {
12 } 10 }
  11 +
  12 + aboutToAppear(): void {
  13 +
  14 + for (let index = 0; index < this.configItem.length; index++) {
  15 + const element = this.configItem[index];
  16 + if (element === '回复') {
  17 + this.functionData.push(new FunctionsItem('回复',$r('app.media.DeleteComment_reply'),PublicCommentMoreActionType.PublicCommentMoreActionType_Reply))
  18 + }
  19 + if (element === '复制') {
  20 + this.functionData.push(new FunctionsItem('复制',$r('app.media.DeleteComment_copy'),PublicCommentMoreActionType.PublicCommentMoreActionType_Copy))
  21 + }
  22 + if (element === '删除') {
  23 + this.functionData.push(new FunctionsItem('删除',$r('app.media.DeleteComment_delete'),PublicCommentMoreActionType.PublicCommentMoreActionType_Delete))
  24 + }
  25 + }
  26 + }
  27 +
13 build() { 28 build() {
14 Column(){ 29 Column(){
15 Grid(){ 30 Grid(){