- studio_page_controller.go PostsPage 中 GetOverview 调用不再用 _ 忽略 error
- 错误时记录日志,模板侧已有 {{if .Overview}} 空值保护,页面正常降级渲染
119 lines
3.2 KiB
Go
119 lines
3.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"metazone.cc/metalab/internal/common"
|
|
"metazone.cc/metalab/internal/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// OverviewPage 创作中心首页(数据概览)
|
|
func (ctrl *StudioController) OverviewPage(c *gin.Context) {
|
|
uid, _, ok := common.GetGinUser(c)
|
|
if !ok {
|
|
common.RedirectToLogin(c)
|
|
return
|
|
}
|
|
|
|
overview, err := ctrl.postService.GetOverview(uid)
|
|
if err != nil {
|
|
c.HTML(http.StatusOK, "studio/overview.html", common.BuildPageData(c, gin.H{
|
|
"Title": "创作中心",
|
|
"Error": "加载数据失败",
|
|
"ActiveTab": "overview",
|
|
"ExtraCSS": "/static/css/studio.css",
|
|
}))
|
|
return
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "studio/overview.html", common.BuildPageData(c, gin.H{
|
|
"Title": "创作中心",
|
|
"Overview": overview,
|
|
"StatusNames": common.PostStatusDisplayNames,
|
|
"ActiveTab": "overview",
|
|
"ExtraCSS": "/static/css/studio.css",
|
|
}))
|
|
}
|
|
|
|
// PostsPage 内容管理页
|
|
func (ctrl *StudioController) PostsPage(c *gin.Context) {
|
|
uid, _, ok := common.GetGinUser(c)
|
|
if !ok {
|
|
common.RedirectToLogin(c)
|
|
return
|
|
}
|
|
|
|
status := c.Query("status")
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
|
|
|
posts, total, err := ctrl.postService.ListByUser(uid, status, page, pageSize)
|
|
if err != nil {
|
|
c.HTML(http.StatusOK, "studio/posts.html", common.BuildPageData(c, gin.H{
|
|
"Title": "内容管理 - 创作中心",
|
|
"Error": "加载失败",
|
|
"ActiveTab": "posts",
|
|
"ExtraCSS": "/static/css/studio.css",
|
|
}))
|
|
return
|
|
}
|
|
|
|
overview, err2 := ctrl.postService.GetOverview(uid)
|
|
if err2 != nil {
|
|
log.Printf("[PostsPage] GetOverview failed for user %d: %v", uid, err2)
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "studio/posts.html", common.BuildPageData(c, gin.H{
|
|
"Title": "内容管理 - 创作中心",
|
|
"Posts": posts,
|
|
"Total": total,
|
|
"Page": page,
|
|
"PageSize": pageSize,
|
|
"TotalPages": common.PageCount(total, pageSize),
|
|
"CurrentStatus": status,
|
|
"Overview": overview,
|
|
"StatusNames": common.PostStatusDisplayNames,
|
|
"ActiveTab": "posts",
|
|
"ExtraCSS": "/static/css/studio.css",
|
|
}))
|
|
}
|
|
|
|
// DraftsPage 草稿箱页面
|
|
func (ctrl *StudioController) DraftsPage(c *gin.Context) {
|
|
uid, _, ok := common.GetGinUser(c)
|
|
if !ok {
|
|
common.RedirectToLogin(c)
|
|
return
|
|
}
|
|
|
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
|
|
|
posts, total, err := ctrl.postService.ListByUser(uid, model.PostStatusDraft, page, pageSize)
|
|
if err != nil {
|
|
c.HTML(http.StatusOK, "studio/drafts.html", common.BuildPageData(c, gin.H{
|
|
"Title": "草稿箱 - 创作中心",
|
|
"Error": "加载失败",
|
|
"ActiveTab": "drafts",
|
|
"ExtraCSS": "/static/css/studio.css",
|
|
}))
|
|
return
|
|
}
|
|
|
|
c.HTML(http.StatusOK, "studio/drafts.html", common.BuildPageData(c, gin.H{
|
|
"Title": "草稿箱 - 创作中心",
|
|
"Posts": posts,
|
|
"Total": total,
|
|
"Page": page,
|
|
"PageSize": pageSize,
|
|
"TotalPages": common.PageCount(total, pageSize),
|
|
"StatusNames": common.PostStatusDisplayNames,
|
|
"ActiveTab": "drafts",
|
|
"ExtraCSS": "/static/css/studio.css",
|
|
}))
|
|
}
|