diff --git a/lib/pages/video/detail/reply/controller.dart b/lib/pages/video/detail/reply/controller.dart index ab4fc9e3..91aa4fd6 100644 --- a/lib/pages/video/detail/reply/controller.dart +++ b/lib/pages/video/detail/reply/controller.dart @@ -132,4 +132,24 @@ class VideoReplyController extends GetxController { queryReplyList(type: 'init'); }); } + + // 移除评论 + Future removeReply(int? rpid, int? frpid) async { + // 移除一楼评论 + if (rpid != null) { + replyList.removeWhere((item) { + return item.rpid == rpid; + }); + } + // 移除二楼评论 + if (frpid != 0 && frpid != null) { + replyList.value = replyList.map((item) { + if (item.rpid! == frpid) { + return item..replies!.removeWhere((reply) => reply.rpid == rpid); + } else { + return item; + } + }).toList(); + } + } } diff --git a/lib/pages/video/detail/reply/view.dart b/lib/pages/video/detail/reply/view.dart index 54372c5e..28d36979 100644 --- a/lib/pages/video/detail/reply/view.dart +++ b/lib/pages/video/detail/reply/view.dart @@ -242,10 +242,9 @@ class _VideoReplyPanelState extends State .replyList[index], showReplyRow: true, replyLevel: replyLevel, - replyReply: (replyItem, currentReply, - loadMore) => - replyReply(replyItem, currentReply, - loadMore), + replyReply: replyReply, + onDelete: + _videoReplyController.removeReply, replyType: ReplyType.video, ); } diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 84c0a62f..76a25331 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -37,6 +37,7 @@ class ReplyItem extends StatelessWidget { this.replyReply, this.replyType, this.replySave = false, + this.onDelete, super.key, }); final ReplyItemModel? replyItem; @@ -46,6 +47,7 @@ class ReplyItem extends StatelessWidget { final Function? replyReply; final ReplyType? replyType; final bool replySave; + final Function(int? rpid, int? frpid)? onDelete; @override Widget build(BuildContext context) { @@ -75,6 +77,7 @@ class ReplyItem extends StatelessWidget { item: replyItem, mainFloor: true, isOwner: isOwner, + onDelete: onDelete, ); }, ); @@ -275,6 +278,7 @@ class ReplyItem extends StatelessWidget { // f_rpid: replyItem!.rpid, replyItem: replyItem, replyReply: replyReply, + onDelete: onDelete, ), ), ], @@ -371,15 +375,15 @@ class ReplyItemRow extends StatelessWidget { super.key, this.replies, this.replyControl, - // this.f_rpid, this.replyItem, this.replyReply, + this.onDelete, }); final List? replies; ReplyControl? replyControl; - // int? f_rpid; ReplyItemModel? replyItem; Function? replyReply; + final Function(int? rpid, int? frpid)? onDelete; @override Widget build(BuildContext context) { @@ -410,12 +414,18 @@ class ReplyItemRow extends StatelessWidget { }, onLongPress: () { feedBack(); + final bool isOwner = int.parse(replyItem!.member!.mid!) == + (GlobalDataCache().userInfo?.mid ?? -1); showModalBottomSheet( context: context, useRootNavigator: true, isScrollControlled: true, builder: (context) { - return MorePanel(item: replies![i]); + return MorePanel( + item: replies![i], + isOwner: isOwner, + onDelete: onDelete, + ); }, ); }, @@ -1019,11 +1029,13 @@ class MorePanel extends StatelessWidget { final dynamic item; final bool mainFloor; final bool isOwner; + final Function(int? rpid, int? frpid)? onDelete; const MorePanel({ super.key, required this.item, this.mainFloor = false, this.isOwner = false, + this.onDelete, }); Future menuActionHandler(String type) async { @@ -1077,13 +1089,17 @@ class MorePanel extends StatelessWidget { TextButton( onPressed: () async { Get.back(); + print('item.rpid: ${item.rpid}'); + onDelete?.call(item.rpid!, item.root); + return; var result = await ReplyHttp.replyDel( type: item.type!, oid: item.oid!, rpid: item.rpid!, ); if (result['status']) { - SmartDialog.showToast('评论删除成功,需手动刷新'); + // SmartDialog.showToast('评论删除成功,需手动刷新'); + onDelete?.call(item.rpid!, item.root); Get.back(); } else { SmartDialog.showToast(result['msg']); diff --git a/lib/pages/video/detail/reply_reply/controller.dart b/lib/pages/video/detail/reply_reply/controller.dart index d0f67b80..2795b7a9 100644 --- a/lib/pages/video/detail/reply_reply/controller.dart +++ b/lib/pages/video/detail/reply_reply/controller.dart @@ -84,6 +84,16 @@ class VideoReplyReplyController extends GetxController { return res; } + // 移除评论 + Future removeReply(int? rpid, int? frpid) async { + // 移除一楼评论 + if (rpid != null) { + replyList.removeWhere((item) { + return item.rpid == rpid; + }); + } + } + @override void onClose() { currentPage = 0; diff --git a/lib/pages/video/detail/reply_reply/view.dart b/lib/pages/video/detail/reply_reply/view.dart index 592ea684..aaa84fe6 100644 --- a/lib/pages/video/detail/reply_reply/view.dart +++ b/lib/pages/video/detail/reply_reply/view.dart @@ -118,6 +118,7 @@ class _VideoReplyReplyPanelState extends State { }, replyType: widget.replyType, replyReply: (replyItem) => replyReply(replyItem), + onDelete: _videoReplyReplyController.removeReply, ); }