2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-06 02:37:16 +08:00

feat: 优化分页函数

This commit is contained in:
耗子
2024-06-19 00:47:57 +08:00
parent 49b72aa656
commit ae9e39d0fe
13 changed files with 98 additions and 412 deletions

View File

@@ -75,24 +75,11 @@ func (r *PluginController) List(ctx http.Context) http.Response {
})
}
page := ctx.Request().QueryInt("page", 1)
limit := ctx.Request().QueryInt("limit", 10)
startIndex := (page - 1) * limit
endIndex := page * limit
if startIndex > len(pluginArr) {
return Success(ctx, http.Json{
"total": 0,
"items": []plugin{},
})
}
if endIndex > len(pluginArr) {
endIndex = len(pluginArr)
}
pagedPlugins := pluginArr[startIndex:endIndex]
paged, total := Paginate(ctx, pluginArr)
return Success(ctx, http.Json{
"total": len(pluginArr),
"items": pagedPlugins,
"total": total,
"items": paged,
})
}