diff --git a/ZR.LiveForum.Model/Liveforum/Dto/T_CommentsDto.cs b/ZR.LiveForum.Model/Liveforum/Dto/T_CommentsDto.cs index 091bb5d..3581ceb 100644 --- a/ZR.LiveForum.Model/Liveforum/Dto/T_CommentsDto.cs +++ b/ZR.LiveForum.Model/Liveforum/Dto/T_CommentsDto.cs @@ -55,5 +55,25 @@ namespace ZR.LiveForum.Model.Liveforum.Dto public string? StatusLabel { get; set; } [ExcelColumn(Name = "是否已删除")] public string? IsDeletedLabel { get; set; } + + /// + /// 评论者昵称 + /// + public string? UserName { get; set; } + + /// + /// 被回复用户昵称 + /// + public string? ReplyToUserName { get; set; } + + /// + /// 帖子标题 + /// + public string? PostTitle { get; set; } + + /// + /// 父评论内容 + /// + public string? ParentCommentContent { get; set; } } } \ No newline at end of file diff --git a/ZR.Service/Liveforum/T_CommentsService.cs b/ZR.Service/Liveforum/T_CommentsService.cs index c2ac41a..6a49a91 100644 --- a/ZR.Service/Liveforum/T_CommentsService.cs +++ b/ZR.Service/Liveforum/T_CommentsService.cs @@ -22,12 +22,58 @@ namespace ZR.Service.Liveforum { var predicate = QueryExp(parm); - var response = Queryable() - //.OrderBy("Id desc") + var query = Queryable() .Where(predicate.ToExpression()) - .ToPage(parm); + .LeftJoin((c, u) => c.UserId == u.Id) + .LeftJoin((c, u, ru) => c.ReplyToUserId == ru.Id) + .LeftJoin((c, u, ru, p) => c.PostId == p.Id) + .LeftJoin((c, u, ru, p, pc) => c.ParentCommentId == pc.Id); - return response; + // 排序:顶级评论在前,回复评论在后,同层级按创建时间倒序 + // 使用多个OrderBy组合排序 + query = query.OrderBy((c, u, ru, p, pc) => c.ParentCommentId == null ? 0 : 1, OrderByType.Asc) + .OrderBy((c, u, ru, p, pc) => c.CreatedAt, OrderByType.Desc); + + var response = query.Select((c, u, ru, p, pc) => new T_CommentsDto() + { + Id = c.Id, + PostId = c.PostId, + UserId = c.UserId, + ParentCommentId = c.ParentCommentId, + ReplyToUserId = c.ReplyToUserId, + Content = c.Content, + LikeCount = c.LikeCount, + ReplyCount = c.ReplyCount, + Status = c.Status, + IpAddress = c.IpAddress, + CreatedAt = c.CreatedAt, + UpdatedAt = c.UpdatedAt, + IsDeleted = c.IsDeleted, + DeletedAt = c.DeletedAt, + UserName = u.NickName, + ReplyToUserName = ru.NickName, + PostTitle = p.Title, + ParentCommentContent = pc.Content, + }, true); + + var resp = ToPage(response, parm); + return resp; + } + + /// + /// 分页查询(排序已在Select之前完成) + /// + private PagedInfo ToPage(ISugarQueryable source, PagerInfo parm) + { + var page = new PagedInfo(); + var total = 0; + page.PageSize = parm.PageSize; + page.PageIndex = parm.PageNum; + // 注意:排序已经在 Select 之前完成了,这里不再需要排序 + page.Result = source + .ToPageList(parm.PageNum, parm.PageSize, ref total); + page.TotalNum = total; + return page; } diff --git a/ZR.Vue/src/views/liveforum/tcomments.vue b/ZR.Vue/src/views/liveforum/tcomments.vue index 1427ef2..9b50c2c 100644 --- a/ZR.Vue/src/views/liveforum/tcomments.vue +++ b/ZR.Vue/src/views/liveforum/tcomments.vue @@ -43,12 +43,25 @@ @selection-change="handleSelectionChange" > - + - - - - + + + + + + + + + @@ -158,12 +171,15 @@ const queryParams = reactive({ userId: undefined, }) const columns = ref([ - { visible: true, align: 'center', type: '', prop: 'id', label: '评论ID,主键自增' }, + { visible: true, align: 'center', type: '', prop: 'id', label: '评论ID' }, + { visible: true, align: 'center', type: '', prop: 'postTitle', label: '帖子标题' ,showOverflowTooltip: true }, + { visible: true, align: 'center', type: '', prop: 'userName', label: '评论者' ,showOverflowTooltip: true }, + { visible: true, align: 'center', type: '', prop: 'replyToUserName', label: '被回复用户' ,showOverflowTooltip: true }, { visible: true, align: 'center', type: '', prop: 'postId', label: '帖子ID' }, { visible: true, align: 'center', type: '', prop: 'userId', label: '用户Id' }, - { visible: true, align: 'center', type: '', prop: 'parentCommentId', label: '父评论Id' }, - { visible: true, align: 'center', type: '', prop: 'replyToUserId', label: '回复用户Id' }, - { visible: true, align: 'center', type: '', prop: 'content', label: '评论内容' ,showOverflowTooltip: true }, + { visible: false, align: 'center', type: '', prop: 'parentCommentId', label: '父评论Id' }, + { visible: false, align: 'center', type: '', prop: 'replyToUserId', label: '回复用户Id' }, + { visible: true, align: 'left', type: '', prop: 'content', label: '评论内容' ,showOverflowTooltip: true }, { visible: true, align: 'center', type: '', prop: 'likeCount', label: '评论点赞数' }, { visible: true, align: 'center', type: '', prop: 'replyCount', label: '评论回复数量' }, { visible: false, align: 'center', type: 'dict', prop: 'status', label: '评论状态' ,dictType: 'liveforum_posts_comments' },