~~~
以下代码 默认都是 分页只出来5个 我想显示更多点 请问怎么改呢, 单独改试过 最终都有点小问题 改不好 比如改显示10条
func Paginator(page int64, prepage int64, nums int64) map[string]interface{} {
var firstpage int64 //前一页地址
var lastpage int64 //后一页地址
//根据nums总数,和prepage每页数量 生成分页总数
totalpages := int64(math.Ceil(float64(nums) / float64(prepage))) //page总数
if page > totalpages {
//如果当前页 > 总页数 初始为总页数
page = totalpages
}
if page < 1 {
page = 1 //初始为1
}
var pages []int64
switch {
case page >= totalpages-5 && totalpages > 5: //最后5页
start := totalpages - 5 + 1
firstpage = page - 1
lastpage = int64(math.Min(float64(totalpages), float64(page+1)))
pages = make([]int64, 5)
for i, _ := range pages {
pages[i] = start + int64(i)
}
case page >= 3 && totalpages > 5:
start := page - 3 + 1
pages = make([]int64, 5)
firstpage = page - 3
for i, _ := range pages {
pages[i] = start + int64(i)
}
firstpage = page - 1
lastpage = page + 1
default:
pages = make([]int64, int64(math.Min(5, float64(totalpages))))
for i, _ := range pages {
pages[i] = int64(i) + 1
}
firstpage = int64(math.Max(float64(1), float64(page-1)))
lastpage = page + 1
//fmt.Println(pages)
}
paginatorMap := make(map[string]interface{})
paginatorMap["pages"] = pages //返回数组 共5个 如1,2,3,,5
//paginatorMap["pages"] = common.Int64ToString(pages[0]) + "&cdn=123&uss=777" //返回数组 共5个 如1,2,3,,5
paginatorMap["totalcount"] = nums //总数量
paginatorMap["totalpages"] = totalpages //当前总共多少页
paginatorMap["firstpage"] = firstpage //上一页
//paginatorMap["firstpage"] = common.Int64ToString(firstpage) //上一页
paginatorMap["lastpage"] = lastpage //下一页
paginatorMap["currpage"] = page //当前页
return paginatorMap
}
~~~
更多评论