12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package response
- import "hongze/hongze_yb/utils"
- type PagingItem struct {
- IsStart bool `description:"是否首页" json:"is_start"`
- IsEnd bool `description:"是否最后一页" json:"is_end"`
- PreviousIndex int `description:"上一页页码" json:"previous_index"`
- NextIndex int `description:"下一页页码" json:"next_index"`
- CurrentIndex int `description:"当前页页码" json:"current_index"`
- Pages int `description:"总页数" json:"pages"`
- Totals int `description:"总数据量" json:"totals"`
- PageSize int `description:"每页数据条数" json:"page_size"`
- }
- func GetPaging(currentIndex, pageSize, total int) (item *PagingItem) {
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- item = new(PagingItem)
- item.PageSize = pageSize
- item.Totals = total
- item.CurrentIndex = currentIndex
- if total <= 0 {
- item.IsStart = true
- item.IsEnd = true
- return
- }
- pages := utils.PageCount(total, pageSize)
- item.Pages = pages
- if pages <= 1 {
- item.IsStart = true
- item.IsEnd = true
- item.PreviousIndex = 1
- item.NextIndex = 1
- return
- }
- if pages == currentIndex {
- item.IsStart = false
- item.IsEnd = true
- item.PreviousIndex = currentIndex - 1
- item.NextIndex = currentIndex
- return
- }
- if currentIndex == 1 {
- item.IsStart = true
- item.IsEnd = false
- item.PreviousIndex = 1
- item.NextIndex = currentIndex + 1
- return
- }
- item.IsStart = false
- item.IsEnd = false
- item.PreviousIndex = currentIndex - 1
- item.NextIndex = currentIndex + 1
- return
- }
|