mirror of
https://github.com/acepanel/panel.git
synced 2026-02-06 02:37:16 +08:00
feat: 优化分页函数
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user