feat: 完成社区首页功能迭代,新增首页聚合与工作台组件

本次提交实现了完整的社区首页功能:
1. 新增首页聚合接口与服务,包含社区统计、热门帖、活跃用户与板块数据
2. 实现帖子推荐排序、SSR缓存与点赞态同步逻辑
3. 重构导航与布局系统,新增工作台侧边栏与移动端适配
4. 优化主题色与UI样式,统一设计系统风格
5. 修复登录注册页自动跳转与组件状态同步问题
This commit is contained in:
2026-09-12 23:36:18 +08:00
parent 055688a6cf
commit bee06fa962
24 changed files with 1446 additions and 359 deletions

View File

@@ -14,4 +14,5 @@ type Handlers struct {
Comment *service.CommentService
Like *service.LikeService
Notification *service.NotificationService
OverviewSvc *service.OverviewService
}

View File

@@ -0,0 +1,34 @@
package handler
import (
"net/http"
"github.com/freefire/jiang13-bbs/middleware"
"github.com/gin-gonic/gin"
)
// Overview 首页聚合数据:统计、热门榜、活跃用户、板块计数
func (h *Handlers) Overview(c *gin.Context) {
data, err := h.OverviewSvc.Get()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
// 热门榜按当前登录用户填充点赞态
if claims := middleware.CurrentUser(c); claims != nil {
ids := make([]uint, 0, len(data.Hot))
for _, p := range data.Hot {
ids = append(ids, p.ID)
}
likedMap := h.Like.BatchHasLiked(ids, claims.ID)
for i := range data.Hot {
data.Hot[i].Liked = likedMap[data.Hot[i].ID]
}
}
c.JSON(http.StatusOK, gin.H{
"stats": data.Stats,
"hot": data.Hot,
"active_users": data.ActiveUsers,
"boards": data.Boards,
})
}

View File

@@ -16,13 +16,15 @@ func (h *Handlers) Posts(c *gin.Context) {
boardID, _ := strconv.ParseUint(c.Query("board_id"), 10, 64)
sort := c.DefaultQuery("sort", "latest")
keyword := c.Query("keyword")
recommended := c.Query("recommended") == "true"
items, total, err := h.Post.List(service.PostListQuery{
BoardID: uint(boardID),
Page: page,
Size: size,
Sort: sort,
Keyword: keyword,
BoardID: uint(boardID),
Page: page,
Size: size,
Sort: sort,
Keyword: keyword,
Recommended: recommended,
})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})