feat: 统一 Admin 主列表分页 (#64)
This commit is contained in:
@@ -20,8 +20,9 @@ import (
|
||||
func (h *Handler) PddList(c *gin.Context) {
|
||||
keyword := c.Query("q")
|
||||
status := service.ParseCollectStatus(c.Query("status"))
|
||||
pageNum := service.ParsePage(c.Query("page"))
|
||||
|
||||
result, err := service.ListPddProducts(h.db, keyword, status)
|
||||
result, err := service.ListPddProducts(h.db, keyword, status, pageNum)
|
||||
if err != nil {
|
||||
fail(c, http.StatusInternalServerError,
|
||||
"读取 PDD 商品列表失败,数据没有被改动。刷新页面重试;一直失败请把这句话报给维护者。")
|
||||
@@ -35,6 +36,18 @@ func (h *Handler) PddList(c *gin.Context) {
|
||||
statusLine = msg + " · " + statusLine
|
||||
}
|
||||
|
||||
values := url.Values{}
|
||||
if keyword != "" {
|
||||
values.Set("q", keyword)
|
||||
}
|
||||
if status != "" {
|
||||
values.Set("status", string(status))
|
||||
}
|
||||
detailValues := url.Values{}
|
||||
for key, entries := range values {
|
||||
detailValues[key] = append([]string(nil), entries...)
|
||||
}
|
||||
detailValues.Set("page", strconv.Itoa(result.Page))
|
||||
c.HTML(http.StatusOK, "pdd/list", page(c, "pdd", "PDD 商品", gin.H{
|
||||
"Rows": result.Rows,
|
||||
"Keyword": keyword,
|
||||
@@ -43,6 +56,9 @@ func (h *Handler) PddList(c *gin.Context) {
|
||||
"StatusOptions": service.CollectStatusOptions(),
|
||||
"HasAnyProducts": result.Total > 0,
|
||||
"IsFiltered": result.IsFiltered,
|
||||
"CurrentPage": result.Page,
|
||||
"Pagination": service.NewPaginationView(result.Page, result.TotalPages, values.Encode()),
|
||||
"DetailURL": "/pdd/detail?" + detailValues.Encode(),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -71,6 +87,8 @@ func (h *Handler) PddDetail(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "pdd/edit_modal", gin.H{
|
||||
"D": detail,
|
||||
"CSRFToken": csrfToken(c),
|
||||
"Keyword": c.Query("q"), "StatusFilter": c.Query("status"),
|
||||
"CurrentPage": service.ParsePage(c.Query("page")),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -156,6 +174,9 @@ func (h *Handler) pddRedirect(c *gin.Context, msg string) {
|
||||
if q := c.PostForm("q"); q != "" {
|
||||
params.Set("q", q)
|
||||
}
|
||||
if p := c.PostForm("page"); p != "" {
|
||||
params.Set("page", p)
|
||||
}
|
||||
if msg != "" {
|
||||
params.Set("msg", msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user