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 {
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"
... ...
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';
... ... @@ -42,6 +45,9 @@ export struct CommentComponent {
@State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
firstPageHotIds: string = ''
@State dialogController: CustomDialogController | null = null;
@State customDialogController: CustomDialogController | null = null;
@State delDialogController: CustomDialogController | null = null;
// @State private browSingModel: commentListModel = new commentListModel()
// 是否为固定高度模式。true时,里面上拉加载更多生效,外层不能包Scroll。
... ... @@ -59,10 +65,15 @@ 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() {
this.dialogController = null // 将dialogController置空
this.customDialogController = null
this.delDialogController = null
}
aboutToAppear() {
... ... @@ -98,6 +109,32 @@ export struct CommentComponent {
maskColor: "#50000000",
})
this.customDialogController = new CustomDialogController({
builder:DeleteCommentDialogView({
configItem:this.itemType(),
confirmCallback: (actionType:PublicCommentMoreActionType) =>{
this.confirmCallback(actionType)
}
}),
alignment:DialogAlignment.Bottom
})
this.delDialogController = 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
})
this.getData();
this.windowClass = WindowModel.shared.getWindowClass(); // 获取应用主窗口
... ... @@ -141,7 +178,90 @@ export struct CommentComponent {
if (model) {
this.isComments = true
}
}
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 +312,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 +368,13 @@ export struct CommentComponent {
item: childItem,
dialogController: this.dialogController,
publishCommentModel: this.publishCommentModel,
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
longPressCommentAction:()=>{
this.item = childItem
this.itemIndex = subIndex
this.mainComment = false
this.showDeleteCommentDialogView()
}
});
}
.onClick(() => {
... ... @@ -258,7 +390,13 @@ export struct CommentComponent {
item: childItem,
dialogController: this.dialogController,
publishCommentModel: this.publishCommentModel,
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction
dialogBeforeJumpOtherPageAction: this.dialogBeforeJumpOtherPageAction,
longPressCommentAction:()=>{
this.item = childItem
this.itemIndex = subIndex
this.mainComment = false
this.showDeleteCommentDialogView()
},
});
}
.onClick(() => {
... ... @@ -451,6 +589,18 @@ struct ChildCommentItem {
private leftGap: number = 95 + 4
@Consume inDialog: boolean
private dialogBeforeJumpOtherPageAction: () => void = () => {}
private longPressCommentAction: () => void = () => {}
private isLongPress:boolean = false
aboutToAppear() {
getContext(this).eventHub.on('1',()=>{
if (this.isLongPress) {
this.replyComment()
this.isLongPress = false
}
})
}
build() {
Column() {
... ... @@ -519,7 +669,8 @@ struct ChildCommentItem {
LongPressGesture()
.onAction((event: GestureEvent|undefined)=>{
if (event) {
//TODO: 显示功能菜单
this.isLongPress = true
this.longPressCommentAction()
}
})
)
... ... @@ -701,9 +852,21 @@ 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
aboutToAppear() {
getContext(this).eventHub.on('1',()=>{
if (this.isLongPress) {
this.replyComment()
this.isLongPress = false
}
})
}
build() {
Column() {
... ... @@ -762,6 +925,8 @@ struct commentHeaderView {
.onAction((event: GestureEvent|undefined)=>{
if (event) {
//TODO: 显示功能菜单
this.isLongPress = true
this.longPressCommentAction()
}
})
)
... ... @@ -850,6 +1015,7 @@ struct commentHeaderView {
}
replyComment() {
if (this.item.id && this.item.checkStatus == '2') { // 审核通过的才显示回复
this.publishCommentModel.rootCommentId = this.item.rootCommentId
this.publishCommentModel.parentId = this.item.id
... ...
... ... @@ -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
... ...
... ... @@ -2,14 +2,29 @@
@CustomDialog
export struct DeleteCommentDialogView {
functionData:FunctionsItem[] = [
new FunctionsItem('回复',$r('app.media.DeleteComment_reply'),PublicCommentMoreActionType.PublicCommentMoreActionType_Reply),
new FunctionsItem('复制',$r('app.media.DeleteComment_copy'),PublicCommentMoreActionType.PublicCommentMoreActionType_Copy),
new FunctionsItem('删除',$r('app.media.DeleteComment_delete'),PublicCommentMoreActionType.PublicCommentMoreActionType_Delete)]
@State configItem:string[] = ['回复','复制','删除']
@Provide functionData:FunctionsItem[] = []
controller: CustomDialogController
confirmCallback: (actionType:PublicCommentMoreActionType) => void = () => {
}
aboutToAppear(): void {
for (let index = 0; index < this.configItem.length; index++) {
const element = this.configItem[index];
if (element === '回复') {
this.functionData.push(new FunctionsItem('回复',$r('app.media.DeleteComment_reply'),PublicCommentMoreActionType.PublicCommentMoreActionType_Reply))
}
if (element === '复制') {
this.functionData.push(new FunctionsItem('复制',$r('app.media.DeleteComment_copy'),PublicCommentMoreActionType.PublicCommentMoreActionType_Copy))
}
if (element === '删除') {
this.functionData.push(new FunctionsItem('删除',$r('app.media.DeleteComment_delete'),PublicCommentMoreActionType.PublicCommentMoreActionType_Delete))
}
}
}
build() {
Column(){
Grid(){
... ...