Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
chenquansheng
2024-11-06 18:30:06 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
282eb018eba48c2cdb1e7ab1de800ffbdb4d258f
282eb018
1 parent
2e21ebc2
ref |> 评论删除逻辑添加
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
185 additions
and
4 deletions
sight_harmony/commons/wdNetwork/src/main/ets/http/HttpUrlUtils.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/comment/viewmodel/CommentViewModel.ets
sight_harmony/commons/wdNetwork/src/main/ets/http/HttpUrlUtils.ets
View file @
282eb01
...
...
@@ -501,6 +501,18 @@ export class HttpUrlUtils {
return url
}
/*删除评论*/
static getDeleteCommentUrl() {
let url = HttpUrlUtils.getHost() + "/api/rmrb-comment/comment/zh/c/delete"
return url
}
/*游客删除评论*/
static getNoUserDeleteCommentUrl() {
let url = HttpUrlUtils.getHost() + "/api/rmrb-comment/comment/zh/c/visitorDelete"
return url
}
/*levleIcon*/
static getBatchUserUrl() {
let url = HttpUrlUtils.getHost() + "/api/rmrb-user-point/auth/level/zh/c/batchUser"
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/view/CommentComponent.ets
View file @
282eb01
import { DateTimeUtils, EmitterEventId, EmitterUtils, LazyDataSource,
Logger,
PublicDialogManager,
StringUtils } from 'wdKit/Index';
StringUtils
,ToastUtils
} from 'wdKit/Index';
import { CommentItemCustomType, commentItemModel, WDPublicUserType } from '../model/CommentModel';
import commentViewModel from '../viewmodel/CommentViewModel';
import { CommentText } from './CommentText';
...
...
@@ -15,6 +15,9 @@ import { ContentDetailDTO, Params } from 'wdBean/Index';
import { TrackingContent, TrackParamConvert } from 'wdTracking/Index';
import { WindowModel } from 'wdKit/Index';
import { window } from '@kit.ArkUI';
import { DeleteCommentDialogView,PublicCommentMoreActionType } from '../../view/areaPickerDialog/DeleteCommentDialogView';
import {BusinessError, pasteboard} from '@kit.BasicServicesKit';
import { ConfirmLogoutDialog } from '../../../components/setting/ConfirmLogoutDialog';
const TAG = 'CommentComponent';
...
...
@@ -59,6 +62,9 @@ export struct CommentComponent {
@State isZD: boolean = false // 存储是否折叠屏
private screenWidth: number = 0
@State windowWidth: number = AppStorage.get<number>('windowWidth') || 0
private item: commentItemModel = new commentItemModel();
mainComment:boolean = false
itemIndex:number = 0
// 在自定义组件即将析构销毁时将dialogControlle置空
aboutToDisappear() {
...
...
@@ -141,7 +147,116 @@ export struct CommentComponent {
if (model) {
this.isComments = true
}
}
customDialogController: CustomDialogController = new CustomDialogController({
builder:DeleteCommentDialogView({
configItem:this.itemType(),
confirmCallback: (actionType:PublicCommentMoreActionType) =>{
this.confirmCallback(actionType)
}
}),
alignment:DialogAlignment.Bottom
})
delDialogController: CustomDialogController = new CustomDialogController({
builder: ConfirmLogoutDialog({
tipShow:false,
title:"是否确认删除?",
leftText:"取消",
leftTextColor:$r('app.color.color_648DF2'),
rightText:"确认",
cancelIsLeft:true,
confirm: () => {
this.deleteComponent()
}
}),
customStyle: true,
alignment: DialogAlignment.Center
})
confirmCallback(actionType:PublicCommentMoreActionType){
//复制评论内容
if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Copy){
let systemPasteboard = pasteboard.getSystemPasteboard();
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, this.item?.commentContent)
// // 将数据写入系统剪贴板
systemPasteboard.setData(pasteData).then(()=>{
// 存入成功,处理正常场景
ToastUtils.shortToast('复制成功')
}).catch((error: BusinessError) => {
// 处理异常场景
Logger.debug(TAG, '长按文字存储失败:' + error);
});
return
}
if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Delete) {
//删除评论内容
this.delDialogController.open();
return
}
if (actionType == PublicCommentMoreActionType.PublicCommentMoreActionType_Reply) {
//回复评论
getContext(this).eventHub.emit('1')
}
}
deleteComponent(){
commentViewModel.deleteComment(this.publishCommentModel.targetId,this.item)?.then(()=>{
// ToastUtils.shortToast('删除成功')
if (this.mainComment) {
this.allDatas.deleteItem(this.itemIndex)
let totalNum:number = Number(this.publishCommentModel.totalCommentNumer)
let childNum:number = Number(this.item.childCommentNum)
totalNum -= (childNum+1)
this.publishCommentModel.totalCommentNumer = totalNum.toString()
}else {
//删除子评论
for (let index = 0; index < this.allDatas.getDataArray().length; index++) {
const element = this.allDatas.getDataArray()[index];
if (element.api_customType === CommentItemCustomType.hotTitle
|| element.api_customType === CommentItemCustomType.newTitle) {
continue;
}
/// 根据当前评论数据的父评论ID 查询数据源中的父评论数据
if (this.item.parentId == element.id && element.childCommentsLazyDataSource.getDataArray().length > 0) {
element.childCommentsLazyDataSource.deleteItem(this.itemIndex)
// element.childComments.splice(this.itemIndex,1)
let totalNum:number = Number(this.publishCommentModel.totalCommentNumer)
let childNum:number = Number(element.childCommentNum)
totalNum -= 1
childNum -= 1
element.childCommentNum = childNum.toString()
this.publishCommentModel.totalCommentNumer = totalNum.toString()
break;
}
}
}
})
.catch(()=>{
})
}
itemType() {
let typeArr:string[] = []
// if (this.item.id && this.item.checkStatus == '2') {
// typeArr.push('回复')
// }
typeArr.push('复制')
if (HttpUtils.isLogin()) {
if (HttpUtils.getUserId() == this.item.fromUserId) {
typeArr.push('删除')
}
}
return typeArr
}
showDeleteCommentDialogView(){
this.customDialogController.open();
}
/*标题:全部评论*/
...
...
@@ -192,6 +307,12 @@ export struct CommentComponent {
dialogController: this.dialogController,
publishCommentModel: this.publishCommentModel,
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
longPressCommentAction:()=>{
this.item = item
this.itemIndex = index
this.mainComment = true
this.showDeleteCommentDialogView()
},
isZD:isZD
})
}
...
...
@@ -242,7 +363,12 @@ export struct CommentComponent {
item: childItem,
dialogController: this.dialogController,
publishCommentModel: this.publishCommentModel,
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
longPressCommentAction:()=>{
this.item = item
this.mainComment = false
this.showDeleteCommentDialogView()
}
});
}
.onClick(() => {
...
...
@@ -258,7 +384,12 @@ export struct CommentComponent {
item: childItem,
dialogController: this.dialogController,
publishCommentModel: this.publishCommentModel,
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
longPressCommentAction:()=>{
this.item = item
this.mainComment = false
this.showDeleteCommentDialogView()
},
});
}
.onClick(() => {
...
...
@@ -451,6 +582,7 @@ struct ChildCommentItem {
private leftGap: number = 95 + 4
@Consume inDialog: boolean
private dialogBeforeJumpOtherPageAction: () => void = () => {}
private longPressCommentAction: () => void = () => {}
build() {
Column() {
...
...
@@ -519,7 +651,7 @@ struct ChildCommentItem {
LongPressGesture()
.onAction((event: GestureEvent|undefined)=>{
if (event) {
//TODO: 显示功能菜单
this.longPressCommentAction()
}
})
)
...
...
@@ -701,9 +833,12 @@ struct commentHeaderView {
@Consume inDialog: boolean
private dialogBeforeJumpOtherPageAction: () => void = () => {}
private longPressCommentAction: () => void = () => {}
private leftGap: number = 64
@State isCanClickHeader:boolean = true
@Prop isZD: boolean = false
private isLongPress:boolean = false
build() {
Column() {
...
...
@@ -762,6 +897,8 @@ struct commentHeaderView {
.onAction((event: GestureEvent|undefined)=>{
if (event) {
//TODO: 显示功能菜单
this.isLongPress = true
this.longPressCommentAction()
}
})
)
...
...
@@ -850,6 +987,7 @@ struct commentHeaderView {
}
replyComment() {
if (this.item.id && this.item.checkStatus == '2') { // 审核通过的才显示回复
this.publishCommentModel.rootCommentId = this.item.rootCommentId
this.publishCommentModel.parentId = this.item.id
...
...
sight_harmony/features/wdComponent/src/main/ets/components/comment/viewmodel/CommentViewModel.ets
View file @
282eb01
...
...
@@ -240,6 +240,37 @@ class CommentViewModel {
})
}
/*删除评论*/
deleteComment(contentId: string,model:commentItemModel){
if (contentId.length == 0 || model.id.length == 0 || model.uuid.length == 0) {
return
}
return new Promise<void>((success, fail) => {//model.visitorComment == "1" &&
const visitorMode = HttpUtils.isLogin() == false
let url = visitorMode ? HttpUrlUtils.getNoUserDeleteCommentUrl() : HttpUrlUtils.getDeleteCommentUrl()
let bean: Record<string, string> = {};
bean['targetId'] = contentId;
bean['commentId'] = model.id;
bean['uuid'] = model.uuid;
if (visitorMode) {
bean['deviceId'] = DeviceUtil.clientId()
// bean['userName'] = SPHelper.default.getSync(SpConstants.TOURIST_NICK_NAME, "") as string
}
HttpBizUtil.post<ResponseDTO<object>>(url, bean).then((data: ResponseDTO<object>) => {
if (data.code != 0) {
fail()
return
}
Logger.debug('>>>>>>>删除成功:'+data.message)
success()
}, (error: Error) => {
fail()
Logger.debug('>>>>>>>删除失败:'+error.toString())
})
})
}
async fetchCurrentUserAuthIcons(model: commentItemModel) {
if (false == HttpUtils.isLogin()) {
return
...
...
Please
register
or
login
to post a comment