fix: 评论配图整条链路补全 + 宠物切换条吸顶
## 评论图片传了等于没传 上次只做了一半:model 加了 Images 字段、前端做了上传 UI,但 handler 的 commentReq 没有 images、service 的 CreateComment 连 参数都没有,图片上传完就丢了;评论列表也从没渲染过图片。 补齐:请求体 → service 落库(JSON 数组) → 列表回显 → 点击大图预览。 实测带两张图的评论和纯文字评论各存各的,互不影响。 ## 宠物切换条吸顶 首页/计划/记录/报告四页的 pet-switch 原本在 scroll-view 里,滚下去 就找不到了。而切宠物是随时要用的动作——多宠用户看着 A 的数据想切到 B,还得先滚回顶部。 移出滚动区,放在导航栏下方做成固定的一条,带毛玻璃和分隔线。首页的 问候语留在滚动区里,滚走就滚走,反正它只在刚进页面时有意义。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -113,7 +113,8 @@ func (h *Handler) ListComments(c *gin.Context) {
|
||||
}
|
||||
|
||||
type commentReq struct {
|
||||
Content string `json:"content"`
|
||||
Content string `json:"content"`
|
||||
Images []string `json:"images"`
|
||||
}
|
||||
|
||||
// CreateComment POST /api/posts/:id/comments
|
||||
@@ -127,7 +128,7 @@ func (h *Handler) CreateComment(c *gin.Context) {
|
||||
response.FailParams(c, "评论内容不能为空")
|
||||
return
|
||||
}
|
||||
comment, err := h.svc.CreateComment(middleware.UserID(c), idParam(c, "id"), req.Content)
|
||||
comment, err := h.svc.CreateComment(middleware.UserID(c), idParam(c, "id"), req.Content, req.Images)
|
||||
if err != nil {
|
||||
respondErr(c, err)
|
||||
return
|
||||
|
||||
@@ -209,7 +209,7 @@ func (s *Service) ListComments(userID, postID string, offset, limit int) ([]mode
|
||||
}
|
||||
|
||||
// CreateComment 评论
|
||||
func (s *Service) CreateComment(userID, postID string, content string) (*model.Comment, error) {
|
||||
func (s *Service) CreateComment(userID, postID string, content string, images []string) (*model.Comment, error) {
|
||||
if _, err := s.GetPost(postID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -219,6 +219,10 @@ func (s *Service) CreateComment(userID, postID string, content string) (*model.C
|
||||
name = user.Nickname
|
||||
}
|
||||
comment := model.Comment{PostID: postID, UserID: userID, AuthorName: name, Content: content, Status: "published"}
|
||||
// 配图存 JSON 数组。空数组也要显式写,否则前端拿到 null 还要额外判空
|
||||
if b, err := json.Marshal(images); err == nil && len(images) > 0 {
|
||||
comment.Images = b
|
||||
}
|
||||
if err := s.db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&comment).Error; err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user