feat: 统一 Admin 主列表分页 (#64)
This commit is contained in:
+35
-19
@@ -563,7 +563,7 @@ func (h *Handler) TaskList(c *gin.Context) {
|
||||
Keyword: c.Query("q"),
|
||||
}
|
||||
|
||||
result, err := service.ListTasksView(h.db, filter)
|
||||
result, err := service.ListTasksView(h.db, filter, service.ParsePage(c.Query("page")))
|
||||
if err != nil {
|
||||
fail(c, http.StatusInternalServerError,
|
||||
"读取任务列表失败,数据没有被改动。刷新页面重试;一直失败请把这句话报给维护者。")
|
||||
@@ -577,6 +577,16 @@ func (h *Handler) TaskList(c *gin.Context) {
|
||||
statusLine = msg + " · " + statusLine
|
||||
}
|
||||
|
||||
values := url.Values{}
|
||||
if filter.Type != "" {
|
||||
values.Set("type", string(filter.Type))
|
||||
}
|
||||
if filter.Status != "" {
|
||||
values.Set("status", string(filter.Status))
|
||||
}
|
||||
if strings.TrimSpace(filter.Keyword) != "" {
|
||||
values.Set("q", filter.Keyword)
|
||||
}
|
||||
c.HTML(http.StatusOK, "task/list", page(c, "tasks", "采集采购", gin.H{
|
||||
"Rows": result.Rows,
|
||||
"Keyword": filter.Keyword,
|
||||
@@ -586,6 +596,8 @@ func (h *Handler) TaskList(c *gin.Context) {
|
||||
"TypeOptions": service.TaskTypeOptions(),
|
||||
"StatusOptions": service.TaskStatusOptions(),
|
||||
"IsFiltered": result.IsFiltered,
|
||||
"CurrentPage": result.Page,
|
||||
"Pagination": service.NewPaginationView(result.Page, result.TotalPages, values.Encode()),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -648,6 +660,9 @@ func (h *Handler) taskRedirect(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)
|
||||
}
|
||||
@@ -672,28 +687,16 @@ func (h *Handler) ClientList(c *gin.Context) {
|
||||
keyword := c.Query("name")
|
||||
actor := currentUser(c)
|
||||
|
||||
views, err := service.ListClientViewsForUser(h.db, actor, keyword, h.onlineThreshold)
|
||||
result, err := service.ListClientPageForUser(h.db, actor, keyword, h.onlineThreshold,
|
||||
service.ParsePage(c.Query("page")))
|
||||
if err != nil {
|
||||
fail(c, http.StatusInternalServerError,
|
||||
"读取客户端列表失败,数据没有被改动。请稍后重试,或查看 data/logs/ 里的日志。")
|
||||
return
|
||||
}
|
||||
|
||||
online := 0
|
||||
for _, v := range views {
|
||||
if v.Status == "在线" {
|
||||
online++
|
||||
}
|
||||
}
|
||||
status := fmt.Sprintf("共 %d 台客户端 · 在线 %d · 离线 %d",
|
||||
len(views), online, len(views)-online)
|
||||
if len(views) == 0 {
|
||||
if actor != nil && actor.IsAdmin() {
|
||||
status = "还没有客户端。客户端第一次调用领取接口时会自动登记。"
|
||||
} else {
|
||||
status = "当前没有绑定给你的客户端,请联系管理员。"
|
||||
}
|
||||
}
|
||||
status := fmt.Sprintf("共 %d 台客户端 · 在线 %d · 离线 %d · 第 %d/%d 页",
|
||||
result.Total, result.Online, result.Offline, result.Page, result.TotalPages)
|
||||
|
||||
purchasers := []model.User{}
|
||||
if actor != nil && actor.IsAdmin() {
|
||||
@@ -705,9 +708,16 @@ func (h *Handler) ClientList(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
values := url.Values{}
|
||||
if strings.TrimSpace(keyword) != "" {
|
||||
values.Set("name", keyword)
|
||||
}
|
||||
c.HTML(http.StatusOK, "client/list", page(c, "clients", "客户端列表", gin.H{
|
||||
"Keyword": keyword, "Rows": views, "Status": status,
|
||||
"Keyword": keyword, "Rows": result.Rows, "Status": status,
|
||||
"Purchasers": purchasers, "Message": c.Query("msg"), "Error": c.Query("error"),
|
||||
"CurrentPage": result.Page,
|
||||
"Pagination": service.NewPaginationView(result.Page, result.TotalPages, values.Encode()),
|
||||
"IsFiltered": strings.TrimSpace(keyword) != "",
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -754,6 +764,12 @@ func (h *Handler) clientActionFailure(c *gin.Context, err error, fallback string
|
||||
|
||||
func redirectClients(c *gin.Context, message, errorMessage string) {
|
||||
query := url.Values{}
|
||||
if name := c.PostForm("name"); name != "" {
|
||||
query.Set("name", name)
|
||||
}
|
||||
if page := c.PostForm("page"); page != "" {
|
||||
query.Set("page", page)
|
||||
}
|
||||
if message != "" {
|
||||
query.Set("msg", message)
|
||||
}
|
||||
@@ -785,5 +801,5 @@ func (h *Handler) ClientDelete(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
log.Printf("clients_deleted count=%d", n)
|
||||
c.Redirect(http.StatusSeeOther, "/clients")
|
||||
redirectClients(c, fmt.Sprintf("已删除 %d 台客户端", n), "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user