feat: 统一 Admin 主列表分页 (#64)

This commit is contained in:
chengma
2026-08-09 21:51:20 +08:00
parent 5c9ebd968c
commit 155dd3b4a2
23 changed files with 549 additions and 120 deletions
+26 -10
View File
@@ -238,26 +238,42 @@ type PddProductView struct {
// PddListResult 是列表页要的全部数据。
type PddListResult struct {
Rows []PddProductView
Total int // 全部未删除记录数,不受筛选影响
Counts map[model.CollectStatus]int
IsFiltered bool
Rows []PddProductView
Total int // 全部未删除记录数,不受筛选影响
FilteredTotal int // 当前筛选下的总数,用于页数和筛选状态
Page int
TotalPages int
Counts map[model.CollectStatus]int
IsFiltered bool
}
// ListPddProducts 查列表并把每一行翻成界面文字。
func ListPddProducts(db *sql.DB, keyword string, status model.CollectStatus) (*PddListResult, error) {
rows, err := repository.ListPddProducts(db, keyword, status)
func ListPddProducts(db *sql.DB, keyword string, status model.CollectStatus, requestedPage int) (*PddListResult, error) {
page := requestedPage
if page < 1 {
page = 1
}
rows, filteredTotal, err := repository.ListPddProducts(db, keyword, status, PageSize, (page-1)*PageSize)
if err != nil {
return nil, err
}
totalPages := TotalPages(filteredTotal)
clampedPage := ClampPage(page, totalPages)
if clampedPage != page {
page = clampedPage
rows, _, err = repository.ListPddProducts(db, keyword, status, PageSize, (page-1)*PageSize)
if err != nil {
return nil, err
}
}
counts, err := repository.CountPddProductsByStatus(db)
if err != nil {
return nil, err
}
result := &PddListResult{
Rows: make([]PddProductView, 0, len(rows)),
Counts: counts,
Rows: make([]PddProductView, 0, len(rows)), Counts: counts,
FilteredTotal: filteredTotal, Page: page, TotalPages: totalPages,
IsFiltered: strings.TrimSpace(keyword) != "" || status != "",
}
for _, n := range counts {
@@ -312,9 +328,9 @@ func (r *PddListResult) StatusLine() string {
}
line := strings.Join(parts, " · ")
if r.IsFiltered {
line = fmt.Sprintf("筛选出 %d 条 / %s", len(r.Rows), line)
line = fmt.Sprintf("筛选出 %d 条 / %s", r.FilteredTotal, line)
}
return line
return fmt.Sprintf("%s · 第 %d/%d 页", line, r.Page, r.TotalPages)
}
// ---------- 弹窗 ----------