You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
581 B
33 lines
581 B
2 years ago
|
package page
|
||
|
|
||
|
// 服务端用
|
||
|
|
||
|
const (
|
||
|
DefaultFrontPage = 1
|
||
|
MinFrontPageSize = 10
|
||
|
MaxFrontPageSize = 100
|
||
|
)
|
||
|
|
||
|
type PaginationFront struct {
|
||
|
Page int32 `json:"page"`
|
||
|
PerPage int32 `json:"per_page"`
|
||
|
Total int32 `json:"total"`
|
||
|
}
|
||
|
|
||
|
func FrontToBackend[T Integer](frontPage, frontPerPage T) (page, pageSize T) {
|
||
|
if frontPage < DefaultFrontPage {
|
||
|
frontPage = DefaultPage
|
||
|
}
|
||
|
|
||
|
if frontPerPage <= MinFrontPageSize {
|
||
|
frontPerPage = MinFrontPageSize
|
||
|
}
|
||
|
|
||
|
if frontPerPage >= MaxFrontPageSize {
|
||
|
frontPerPage = MaxPageSize
|
||
|
}
|
||
|
page = frontPage
|
||
|
pageSize = frontPerPage
|
||
|
return
|
||
|
}
|