master
nikkiing 1 year ago
parent 89cf3e6dc2
commit 80d23bb340
  1. 15
      pagination/v1/pagination.go
  2. 11
      pagination/v1/pagination_front.go

@ -7,9 +7,10 @@ import (
// 服务端用 // 服务端用
const ( const (
DefaultPage = 1 DefaultPage = 1
MinPageSize = 10 MinPageSize = 1
MaxPageSize = 1000 DefaultPageSize = 10
MaxPageSize = 1000
) )
type Pagination struct { type Pagination struct {
@ -29,6 +30,10 @@ func PageToSlice[T Integer](page, pageSize, total T) (begin, end T) {
page = DefaultPage page = DefaultPage
} }
if pageSize <= 0 {
pageSize = DefaultPageSize
}
if pageSize <= MinPageSize { if pageSize <= MinPageSize {
pageSize = MinPageSize pageSize = MinPageSize
} }
@ -58,6 +63,10 @@ func PageToOffset[T Integer](page, pageSize T) (offset, limit T) {
page = DefaultPage page = DefaultPage
} }
if pageSize <= 0 {
pageSize = DefaultPageSize
}
if pageSize <= MinPageSize { if pageSize <= MinPageSize {
pageSize = MinPageSize pageSize = MinPageSize
} }

@ -3,9 +3,10 @@ package page
// 服务端用 // 服务端用
const ( const (
DefaultFrontPage = 1 DefaultFrontPage = 1
MinFrontPageSize = 10 DefaultFrontPageSize = 10
MaxFrontPageSize = 100 MinFrontPageSize = 1
MaxFrontPageSize = 100
) )
type PaginationFront struct { type PaginationFront struct {
@ -19,6 +20,10 @@ func FrontToBackend[T Integer](frontPage, frontPerPage T) (page, pageSize T) {
frontPage = DefaultPage frontPage = DefaultPage
} }
if frontPerPage <= 0 {
frontPerPage = DefaultFrontPageSize
}
if frontPerPage <= MinFrontPageSize { if frontPerPage <= MinFrontPageSize {
frontPerPage = MinFrontPageSize frontPerPage = MinFrontPageSize
} }

Loading…
Cancel
Save