Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6dcfd4e

Browse files
committed
页码过多,只展示20个页码
1 parent 2ffa269 commit 6dcfd4e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

http/http.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ var funcMap = template.FuncMap{
123123
}
124124
return total
125125
},
126+
"sub": func(num1, num2 int) int {
127+
return num1 - num2
128+
},
126129
"mod": func(num1, num2 int) int {
127130
if num1 == 0 {
128131
num1 = rand.Intn(500)

template/rich/balance.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@
3939
{{with $pageMax := divide .total .cmt_per_num}}
4040
<td width="92%" align="left">
4141
{{range $i, $v := genList $.total $.cmt_per_num}}
42-
<a href="/balance?p={{$v}}" class="{{if eq $v $.cur_p}}page_current{{else}}page_normal{{end}}">{{$v}}</a>
42+
{{if gt $pageMax 20}}
43+
{{if lt $i 10}}
44+
<a href="/balance?p={{$v}}" class="{{if eq $v $.cur_p}}page_current{{else}}page_normal{{end}}">{{$v}}</a>
45+
{{else if gt $i (sub $pageMax 11)}}
46+
<a href="/balance?p={{$v}}" class="{{if eq $v $.cur_p}}page_current{{else}}page_normal{{end}}">{{$v}}</a>
47+
{{else if eq $i 11}}
48+
<a href="#" class="page_normal disable_now">...</a>
49+
{{end}}
50+
{{else}}
51+
<a href="/balance?p={{$v}}" class="{{if eq $v $.cur_p}}page_current{{else}}page_normal{{end}}">{{$v}}</a>
52+
{{end}}
4353
{{end}}
4454
<input type="number" class="page_input" autocomplete="off" value="{{$.cur_p}}" min="1" max="{{$pageMax}}">
4555
</td>

0 commit comments

Comments
 (0)