diff --git a/ZR.Admin.WebApi/Controllers/Liveforum/T_PostsController.cs b/ZR.Admin.WebApi/Controllers/Liveforum/T_PostsController.cs index 2153c66..8ec8a69 100644 --- a/ZR.Admin.WebApi/Controllers/Liveforum/T_PostsController.cs +++ b/ZR.Admin.WebApi/Controllers/Liveforum/T_PostsController.cs @@ -1,6 +1,8 @@ -using Microsoft.AspNetCore.Mvc; -using ZR.LiveForum.Model.Liveforum.Dto; +using Microsoft.AspNetCore.Mvc; + using ZR.LiveForum.Model.Liveforum; +using ZR.LiveForum.Model.Liveforum.Dto; +using ZR.Model; using ZR.Service.Liveforum.ILiveforumService; //创建时间:2025-11-16 @@ -16,10 +18,14 @@ namespace ZR.Admin.WebApi.Controllers.Liveforum /// 论坛帖子接口 /// private readonly IT_PostsService _T_PostsService; + private readonly IT_LikesService _T_LikesService; + private readonly IT_CommentsService _T_CommentsService; - public T_PostsController(IT_PostsService T_PostsService) + public T_PostsController(IT_PostsService T_PostsService, IT_LikesService T_LikesService, IT_CommentsService T_CommentsService) { _T_PostsService = T_PostsService; + _T_LikesService = T_LikesService; + _T_CommentsService = T_CommentsService; } /// @@ -124,5 +130,41 @@ namespace ZR.Admin.WebApi.Controllers.Liveforum return ExportExcel(result.Item2, result.Item1); } + /// + /// 获取帖子的点赞列表 + /// + /// 帖子ID + /// 分页参数 + /// + [HttpGet("{postId}/likes")] + [ActionPermissionFilter(Permission = "tposts:query")] + public IActionResult GetPostLikes([FromRoute] long postId, [FromQuery] PagerInfo parm) + { + var response = _T_LikesService.GetLikesByPostId(postId, parm); + return SUCCESS(response); + } + + /// + /// 获取帖子的评论列表 + /// + /// 帖子ID + /// 分页参数 + /// + [HttpGet("{postId}/comments")] + [ActionPermissionFilter(Permission = "tposts:query")] + public IActionResult GetPostComments([FromRoute] long postId, [FromQuery] PagerInfo parm) + { + var queryDto = new T_CommentsQueryDto + { + PostId = postId, + PageNum = parm.PageNum, + PageSize = parm.PageSize, + Sort = parm.Sort, + SortType = parm.SortType + }; + var response = _T_CommentsService.GetList(queryDto); + return SUCCESS(response); + } + } } \ No newline at end of file diff --git a/ZR.Service/Liveforum/ILiveforumService/IT_LikesService.cs b/ZR.Service/Liveforum/ILiveforumService/IT_LikesService.cs index 84bf1a3..9c1dbb2 100644 --- a/ZR.Service/Liveforum/ILiveforumService/IT_LikesService.cs +++ b/ZR.Service/Liveforum/ILiveforumService/IT_LikesService.cs @@ -12,6 +12,13 @@ namespace ZR.Service.Liveforum.ILiveforumService T_Likes GetInfo(long Id); + /// + /// 根据帖子ID查询该帖子的所有点赞记录 + /// + /// 帖子ID + /// 分页参数 + /// + PagedInfo GetLikesByPostId(long postId, PagerInfo parm); T_Likes AddT_Likes(T_Likes parm); int UpdateT_Likes(T_Likes parm); diff --git a/ZR.Service/Liveforum/T_LikesService.cs b/ZR.Service/Liveforum/T_LikesService.cs index 3089bc5..3d3f54a 100644 --- a/ZR.Service/Liveforum/T_LikesService.cs +++ b/ZR.Service/Liveforum/T_LikesService.cs @@ -98,6 +98,36 @@ namespace ZR.Service.Liveforum return Update(model, true); } + /// + /// 根据帖子ID查询该帖子的所有点赞记录 + /// + /// 帖子ID + /// 分页参数 + /// + public PagedInfo GetLikesByPostId(long postId, PagerInfo parm) + { + var query = Queryable() + .Where(l => l.TargetType == 1 && l.TargetId == postId) + .LeftJoin((l, u) => l.UserId == u.Id); + + // 默认按创建时间倒序 + query = query.OrderBy((l, u) => l.CreatedAt, OrderByType.Desc); + + var response = query.Select((l, u) => new T_LikesDto() + { + Id = l.Id, + UserId = l.UserId, + TargetType = l.TargetType, + TargetId = l.TargetId, + CreatedAt = l.CreatedAt, + UserName = u.NickName, + TargetInfo = null, // 帖子点赞时不需要显示目标信息 + }, true); + + var resp = ToPage(response, parm); + return resp; + } + /// /// 查询导出表达式 /// diff --git a/ZR.Vue/src/api/liveforum/tposts.js b/ZR.Vue/src/api/liveforum/tposts.js index f0d0b47..0a2a9c8 100644 --- a/ZR.Vue/src/api/liveforum/tposts.js +++ b/ZR.Vue/src/api/liveforum/tposts.js @@ -60,3 +60,29 @@ export function deltposts(pid) { export async function exporttposts(query) { await downFile('liveforum/tposts/export', { ...query }) } + +/** + * 获取帖子的点赞列表 + * @param {帖子ID} postId + * @param {查询条件} query + */ +export function getPostLikes(postId, query) { + return request({ + url: 'liveforum/tposts/' + postId + '/likes', + method: 'get', + params: query, + }) +} + +/** + * 获取帖子的评论列表 + * @param {帖子ID} postId + * @param {查询条件} query + */ +export function getPostComments(postId, query) { + return request({ + url: 'liveforum/tposts/' + postId + '/comments', + method: 'get', + params: query, + }) +} diff --git a/ZR.Vue/src/views/liveforum/tagreements.vue b/ZR.Vue/src/views/liveforum/tagreements.vue index 1b2efc9..e09a9b9 100644 --- a/ZR.Vue/src/views/liveforum/tagreements.vue +++ b/ZR.Vue/src/views/liveforum/tagreements.vue @@ -56,7 +56,7 @@ - + @@ -69,14 +69,14 @@ - + @@ -118,9 +118,9 @@ \ No newline at end of file + diff --git a/ZR.Vue/src/views/liveforum/tposts.vue b/ZR.Vue/src/views/liveforum/tposts.vue index a1011fd..3276e06 100644 --- a/ZR.Vue/src/views/liveforum/tposts.vue +++ b/ZR.Vue/src/views/liveforum/tposts.vue @@ -92,8 +92,32 @@ - - + + + + + + - + @@ -292,7 +316,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -353,6 +439,7 @@ import { listtposts, addtposts, deltposts, updatetposts,gettposts, + getPostLikes, getPostComments, } from '@/api/liveforum/tposts.js' import { listtpostimages, @@ -442,6 +529,7 @@ const imageFormRules = { var dictParams = [ "liveforum_action_bool", "liveforum_posts_status", + "liveforum_posts_comments", ] proxy.getDicts(dictParams).then((response) => { @@ -812,5 +900,95 @@ function closeImageManageDialog() { imageIds.value = [] } +/*************** 点赞列表相关方法 ***************/ +// 点赞列表弹窗状态 +const likeDialogOpen = ref(false) +const currentPostForLikes = ref({ id: null, title: '' }) +const likeList = ref([]) +const likeTotal = ref(0) +const likeLoading = ref(false) +const likeQueryParams = reactive({ + pageNum: 1, + pageSize: 10, +}) + +// 打开点赞列表弹窗 +function handleViewLikes(row) { + currentPostForLikes.value = { + id: row.id, + title: row.title || '未命名帖子' + } + likeQueryParams.pageNum = 1 + likeDialogOpen.value = true + getLikeList() +} + +// 查询点赞列表 +function getLikeList() { + likeLoading.value = true + getPostLikes(currentPostForLikes.value.id, likeQueryParams).then(res => { + const { code, data } = res + if (code == 200) { + likeList.value = data.result + likeTotal.value = data.totalNum + likeLoading.value = false + } + }) +} + +// 关闭点赞列表弹窗 +function closeLikeDialog() { + likeDialogOpen.value = false + currentPostForLikes.value = { id: null, title: '' } + likeList.value = [] + likeTotal.value = 0 + likeQueryParams.pageNum = 1 +} + +/*************** 评论列表相关方法 ***************/ +// 评论列表弹窗状态 +const commentDialogOpen = ref(false) +const currentPostForComments = ref({ id: null, title: '' }) +const commentList = ref([]) +const commentTotal = ref(0) +const commentLoading = ref(false) +const commentQueryParams = reactive({ + pageNum: 1, + pageSize: 10, +}) + +// 打开评论列表弹窗 +function handleViewComments(row) { + currentPostForComments.value = { + id: row.id, + title: row.title || '未命名帖子' + } + commentQueryParams.pageNum = 1 + commentDialogOpen.value = true + getCommentList() +} + +// 查询评论列表 +function getCommentList() { + commentLoading.value = true + getPostComments(currentPostForComments.value.id, commentQueryParams).then(res => { + const { code, data } = res + if (code == 200) { + commentList.value = data.result + commentTotal.value = data.totalNum + commentLoading.value = false + } + }) +} + +// 关闭评论列表弹窗 +function closeCommentDialog() { + commentDialogOpen.value = false + currentPostForComments.value = { id: null, title: '' } + commentList.value = [] + commentTotal.value = 0 + commentQueryParams.pageNum = 1 +} + handleQuery() diff --git a/ZR.Vue/src/views/liveforum/tuserlevels.vue b/ZR.Vue/src/views/liveforum/tuserlevels.vue index 37efac6..7aa6206 100644 --- a/ZR.Vue/src/views/liveforum/tuserlevels.vue +++ b/ZR.Vue/src/views/liveforum/tuserlevels.vue @@ -64,7 +64,7 @@ - +