chenquansheng

ref |> 评论删除逻辑添加

@@ -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
@@ -59,6 +62,9 @@ export struct CommentComponent { @@ -59,6 +62,9 @@ export struct CommentComponent {
59 @State isZD: boolean = false // 存储是否折叠屏 62 @State isZD: boolean = false // 存储是否折叠屏
60 private screenWidth: number = 0 63 private screenWidth: number = 0
61 @State windowWidth: number = AppStorage.get<number>('windowWidth') || 0 64 @State windowWidth: number = AppStorage.get<number>('windowWidth') || 0
  65 + private item: commentItemModel = new commentItemModel();
  66 + mainComment:boolean = false
  67 + itemIndex:number = 0
62 68
63 // 在自定义组件即将析构销毁时将dialogControlle置空 69 // 在自定义组件即将析构销毁时将dialogControlle置空
64 aboutToDisappear() { 70 aboutToDisappear() {
@@ -141,7 +147,116 @@ export struct CommentComponent { @@ -141,7 +147,116 @@ export struct CommentComponent {
141 if (model) { 147 if (model) {
142 this.isComments = true 148 this.isComments = true
143 } 149 }
  150 + }
  151 +
  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){
  179 +
  180 + //复制评论内容
  181 + if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Copy){
  182 + let systemPasteboard = pasteboard.getSystemPasteboard();
  183 + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, this.item?.commentContent)
  184 + // // 将数据写入系统剪贴板
  185 + systemPasteboard.setData(pasteData).then(()=>{
  186 + // 存入成功,处理正常场景
  187 + ToastUtils.shortToast('复制成功')
  188 + }).catch((error: BusinessError) => {
  189 + // 处理异常场景
  190 + Logger.debug(TAG, '长按文字存储失败:' + error);
  191 + });
  192 + return
  193 + }
  194 +
  195 + if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Delete) {
  196 + //删除评论内容
  197 + this.delDialogController.open();
  198 + return
  199 + }
  200 +
  201 + if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Reply) {
  202 + //回复评论
  203 + getContext(this).eventHub.emit('1')
  204 + }
  205 + }
144 206
  207 + deleteComponent(){
  208 + commentViewModel.deleteComment(this.publishCommentModel.targetId,this.item)?.then(()=>{
  209 + // ToastUtils.shortToast('删除成功')
  210 + if (this.mainComment) {
  211 + this.allDatas.deleteItem(this.itemIndex)
  212 + let totalNum:number = Number(this.publishCommentModel.totalCommentNumer)
  213 + let childNum:number = Number(this.item.childCommentNum)
  214 + totalNum -= (childNum+1)
  215 + this.publishCommentModel.totalCommentNumer = totalNum.toString()
  216 + }else {
  217 + //删除子评论
  218 + for (let index = 0; index < this.allDatas.getDataArray().length; index++) {
  219 + const element = this.allDatas.getDataArray()[index];
  220 + if (element.api_customType === CommentItemCustomType.hotTitle
  221 + || element.api_customType === CommentItemCustomType.newTitle) {
  222 + continue;
  223 + }
  224 + /// 根据当前评论数据的父评论ID 查询数据源中的父评论数据
  225 + if (this.item.parentId == element.id && element.childCommentsLazyDataSource.getDataArray().length > 0) {
  226 + element.childCommentsLazyDataSource.deleteItem(this.itemIndex)
  227 + // element.childComments.splice(this.itemIndex,1)
  228 + let totalNum:number = Number(this.publishCommentModel.totalCommentNumer)
  229 + let childNum:number = Number(element.childCommentNum)
  230 + totalNum -= 1
  231 + childNum -= 1
  232 + element.childCommentNum = childNum.toString()
  233 + this.publishCommentModel.totalCommentNumer = totalNum.toString()
  234 + break;
  235 + }
  236 + }
  237 + }
  238 + })
  239 + .catch(()=>{
  240 +
  241 + })
  242 + }
  243 +
  244 + itemType() {
  245 + let typeArr:string[] = []
  246 + // if (this.item.id && this.item.checkStatus == '2') {
  247 + // typeArr.push('回复')
  248 + // }
  249 + typeArr.push('复制')
  250 + if (HttpUtils.isLogin()) {
  251 + if (HttpUtils.getUserId() == this.item.fromUserId) {
  252 + typeArr.push('删除')
  253 + }
  254 + }
  255 + return typeArr
  256 + }
  257 +
  258 + showDeleteCommentDialogView(){
  259 + this.customDialogController.open();
145 } 260 }
146 261
147 /*标题:全部评论*/ 262 /*标题:全部评论*/
@@ -192,6 +307,12 @@ export struct CommentComponent { @@ -192,6 +307,12 @@ export struct CommentComponent {
192 dialogController: this.dialogController, 307 dialogController: this.dialogController,
193 publishCommentModel: this.publishCommentModel, 308 publishCommentModel: this.publishCommentModel,
194 dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction, 309 dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
  310 + longPressCommentAction:()=>{
  311 + this.item = item
  312 + this.itemIndex = index
  313 + this.mainComment = true
  314 + this.showDeleteCommentDialogView()
  315 + },
195 isZD:isZD 316 isZD:isZD
196 }) 317 })
197 } 318 }
@@ -242,7 +363,12 @@ export struct CommentComponent { @@ -242,7 +363,12 @@ export struct CommentComponent {
242 item: childItem, 363 item: childItem,
243 dialogController: this.dialogController, 364 dialogController: this.dialogController,
244 publishCommentModel: this.publishCommentModel, 365 publishCommentModel: this.publishCommentModel,
245 - dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction 366 + dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
  367 + longPressCommentAction:()=>{
  368 + this.item = item
  369 + this.mainComment = false
  370 + this.showDeleteCommentDialogView()
  371 + }
246 }); 372 });
247 } 373 }
248 .onClick(() => { 374 .onClick(() => {
@@ -258,7 +384,12 @@ export struct CommentComponent { @@ -258,7 +384,12 @@ export struct CommentComponent {
258 item: childItem, 384 item: childItem,
259 dialogController: this.dialogController, 385 dialogController: this.dialogController,
260 publishCommentModel: this.publishCommentModel, 386 publishCommentModel: this.publishCommentModel,
261 - dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction 387 + dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
  388 + longPressCommentAction:()=>{
  389 + this.item = item
  390 + this.mainComment = false
  391 + this.showDeleteCommentDialogView()
  392 + },
262 }); 393 });
263 } 394 }
264 .onClick(() => { 395 .onClick(() => {
@@ -451,6 +582,7 @@ struct ChildCommentItem { @@ -451,6 +582,7 @@ struct ChildCommentItem {
451 private leftGap: number = 95 + 4 582 private leftGap: number = 95 + 4
452 @Consume inDialog: boolean 583 @Consume inDialog: boolean
453 private dialogBeforeJumpOtherPageAction: () => void = () => {} 584 private dialogBeforeJumpOtherPageAction: () => void = () => {}
  585 + private longPressCommentAction: () => void = () => {}
454 586
455 build() { 587 build() {
456 Column() { 588 Column() {
@@ -519,7 +651,7 @@ struct ChildCommentItem { @@ -519,7 +651,7 @@ struct ChildCommentItem {
519 LongPressGesture() 651 LongPressGesture()
520 .onAction((event: GestureEvent|undefined)=>{ 652 .onAction((event: GestureEvent|undefined)=>{
521 if (event) { 653 if (event) {
522 - //TODO: 显示功能菜单 654 + this.longPressCommentAction()
523 } 655 }
524 }) 656 })
525 ) 657 )
@@ -701,9 +833,12 @@ struct commentHeaderView { @@ -701,9 +833,12 @@ struct commentHeaderView {
701 833
702 @Consume inDialog: boolean 834 @Consume inDialog: boolean
703 private dialogBeforeJumpOtherPageAction: () => void = () => {} 835 private dialogBeforeJumpOtherPageAction: () => void = () => {}
  836 + private longPressCommentAction: () => void = () => {}
704 private leftGap: number = 64 837 private leftGap: number = 64
705 @State isCanClickHeader:boolean = true 838 @State isCanClickHeader:boolean = true
706 @Prop isZD: boolean = false 839 @Prop isZD: boolean = false
  840 + private isLongPress:boolean = false
  841 +
707 842
708 build() { 843 build() {
709 Column() { 844 Column() {
@@ -762,6 +897,8 @@ struct commentHeaderView { @@ -762,6 +897,8 @@ struct commentHeaderView {
762 .onAction((event: GestureEvent|undefined)=>{ 897 .onAction((event: GestureEvent|undefined)=>{
763 if (event) { 898 if (event) {
764 //TODO: 显示功能菜单 899 //TODO: 显示功能菜单
  900 + this.isLongPress = true
  901 + this.longPressCommentAction()
765 } 902 }
766 }) 903 })
767 ) 904 )
@@ -850,6 +987,7 @@ struct commentHeaderView { @@ -850,6 +987,7 @@ struct commentHeaderView {
850 } 987 }
851 988
852 replyComment() { 989 replyComment() {
  990 +
853 if (this.item.id && this.item.checkStatus == '2') { // 审核通过的才显示回复 991 if (this.item.id && this.item.checkStatus == '2') { // 审核通过的才显示回复
854 this.publishCommentModel.rootCommentId = this.item.rootCommentId 992 this.publishCommentModel.rootCommentId = this.item.rootCommentId
855 this.publishCommentModel.parentId = this.item.id 993 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