diff --git a/internal/controller/interfaces.go b/internal/controller/interfaces.go
index cfb083a..b154cc7 100644
--- a/internal/controller/interfaces.go
+++ b/internal/controller/interfaces.go
@@ -55,7 +55,7 @@ type spaceUseCase interface {
GetSpaceUser(uid uint) (*model.User, error)
GetPostsByUser(uid uint, page, pageSize int) ([]model.Post, int64, error)
CountUserPosts(uid uint) (int64, error)
- GetUserStats(uid uint) (likes, favorites int64, err error)
+ GetUserStats(uid uint) (likes, favorites, reads int64, err error)
UpdateUser(user *model.User) error
}
diff --git a/internal/controller/space_controller.go b/internal/controller/space_controller.go
index 7ec1015..a3e9ad2 100644
--- a/internal/controller/space_controller.go
+++ b/internal/controller/space_controller.go
@@ -81,7 +81,7 @@ func (ctrl *SpaceController) ShowSpace(c *gin.Context) {
// 构建基础数据(含用户统计)
postCount, _ := ctrl.spaceService.CountUserPosts(uint(uid))
- totalLikes, totalFavorites, _ := ctrl.spaceService.GetUserStats(uint(uid))
+ totalLikes, totalFavorites, totalReads, _ := ctrl.spaceService.GetUserStats(uint(uid))
data := gin.H{
"Title": spaceUser.Username + " 的空间",
@@ -93,7 +93,7 @@ func (ctrl *SpaceController) ShowSpace(c *gin.Context) {
"PostCount": postCount,
"TotalLikes": totalLikes,
"TotalFavorites": totalFavorites,
- "TotalReads": int64(0), // 暂无阅读量统计
+ "TotalReads": totalReads,
}
// ---- 根据 Tab 加载对应数据 ----
diff --git a/internal/repository/post_repo.go b/internal/repository/post_repo.go
index 4b1a19f..507b75b 100644
--- a/internal/repository/post_repo.go
+++ b/internal/repository/post_repo.go
@@ -93,18 +93,19 @@ func (r *PostRepo) CountUserPosts(userID uint) (int64, error) {
return count, err
}
-// GetUserStats 获取用户的文章统计数据(总获赞/总收藏)
-func (r *PostRepo) GetUserStats(userID uint) (likes, favorites int64, err error) {
+// GetUserStats 获取用户的文章统计数据(总获赞/总收藏/总阅读)
+func (r *PostRepo) GetUserStats(userID uint) (likes, favorites, reads int64, err error) {
type stats struct {
- TotalLikes int64
+ TotalLikes int64
TotalFavorites int64
+ TotalReads int64
}
var s stats
err = r.db.Model(&model.Post{}).
- Select("COALESCE(SUM(likes_count), 0) AS total_likes, COALESCE(SUM(favorites_count), 0) AS total_favorites").
+ Select("COALESCE(SUM(likes_count), 0) AS total_likes, COALESCE(SUM(favorites_count), 0) AS total_favorites, COALESCE(SUM(views_count), 0) AS total_reads").
Where("user_id = ? AND status = ? AND deleted_at IS NULL", userID, model.PostStatusApproved).
Scan(&s).Error
- return s.TotalLikes, s.TotalFavorites, err
+ return s.TotalLikes, s.TotalFavorites, s.TotalReads, err
}
// FindByUserIDAndStatus 分页查询某用户指定状态的帖子(空 status=全状态)
diff --git a/internal/service/repository.go b/internal/service/repository.go
index ca6a73c..c67bf1d 100644
--- a/internal/service/repository.go
+++ b/internal/service/repository.go
@@ -56,7 +56,7 @@ type spaceUserStore interface {
type spacePostStore interface {
FindByUserID(userID uint, offset, limit int) ([]model.Post, int64, error)
CountUserPosts(userID uint) (int64, error)
- GetUserStats(userID uint) (likes, favorites int64, err error)
+ GetUserStats(userID uint) (likes, favorites, reads int64, err error)
}
// postAdminStatStore AdminService 所需的帖子统计接口(ISP:2 个方法)
diff --git a/internal/service/space_service.go b/internal/service/space_service.go
index 3011250..de3c79f 100644
--- a/internal/service/space_service.go
+++ b/internal/service/space_service.go
@@ -29,8 +29,8 @@ func (s *SpaceService) CountUserPosts(uid uint) (int64, error) {
return s.postRepo.CountUserPosts(uid)
}
-// GetUserStats 获取用户文章统计数据(总获赞、总收藏)
-func (s *SpaceService) GetUserStats(uid uint) (likes, favorites int64, err error) {
+// GetUserStats 获取用户文章统计数据(总获赞、总收藏、总阅读)
+func (s *SpaceService) GetUserStats(uid uint) (likes, favorites, reads int64, err error) {
return s.postRepo.GetUserStats(uid)
}
diff --git a/templates/MetaLab-2026/html/posts/show.html b/templates/MetaLab-2026/html/posts/show.html
index 36e6262..bbf7566 100644
--- a/templates/MetaLab-2026/html/posts/show.html
+++ b/templates/MetaLab-2026/html/posts/show.html
@@ -934,8 +934,8 @@
dropdown.style.left = (rect.left + window.scrollX) + 'px';
dropdown.style.width = Math.max(rect.width, 200) + 'px';
- for (var i = 0; i < users.length; i++) {
- var u = users[i];
+ for (let i = 0; i < users.length; i++) {
+ let u = users[i];
var item = document.createElement('div');
item.className = 'mention-item';
item.innerHTML = '' + escapeHtml(u.username) + '' + escapeHtml(u.uid) + '';