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

Skip to content

Commit 2ffa269

Browse files
committed
财富列表翻页
1 parent 28a7542 commit 2ffa269

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

http/controller/balance.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package controller
88

99
import (
10+
"github.com/polaris1119/goutils"
1011
"github.com/studygolang/studygolang/context"
1112
"github.com/studygolang/studygolang/http/middleware"
1213
"github.com/studygolang/studygolang/logic"
@@ -24,18 +25,23 @@ func (self UserRichController) RegisterRoute(g *echo.Group) {
2425
}
2526

2627
func (UserRichController) MyBalance(ctx echo.Context) error {
28+
p := goutils.MustInt(ctx.QueryParam("p"), 1)
2729
me := ctx.Get("user").(*model.Me)
28-
balanceDetails := logic.DefaultUserRich.FindBalanceDetail(context.EchoContext(ctx), me)
30+
balanceDetails := logic.DefaultUserRich.FindBalanceDetail(context.EchoContext(ctx), me, p)
31+
total := logic.DefaultUserRich.Total(context.EchoContext(ctx), me.Uid)
2932

3033
data := map[string]interface{}{
3134
"details": balanceDetails,
35+
"total": int(total),
36+
"cur_p": p,
3237
}
3338
return render(ctx, "rich/balance.html", data)
3439
}
3540

3641
func (UserRichController) Add(ctx echo.Context) error {
42+
p := goutils.MustInt(ctx.QueryParam("p"), 1)
3743
me := ctx.Get("user").(*model.Me)
38-
balanceDetails := logic.DefaultUserRich.FindBalanceDetail(context.EchoContext(ctx), me, model.MissionTypeAdd)
44+
balanceDetails := logic.DefaultUserRich.FindBalanceDetail(context.EchoContext(ctx), me, p, model.MissionTypeAdd)
3945

4046
rechargeAmount := logic.DefaultUserRich.FindRecharge(context.EchoContext(ctx), me)
4147

logic/user_rich.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ package logic
99
import (
1010
"errors"
1111
"fmt"
12-
"github.com/studygolang/studygolang/model"
13-
"github.com/studygolang/studygolang/util"
1412
"net/url"
1513
"time"
1614

15+
"github.com/studygolang/studygolang/model"
16+
"github.com/studygolang/studygolang/util"
17+
1718
. "github.com/studygolang/studygolang/db"
1819

1920
"github.com/garyburd/redigo/redis"
@@ -152,7 +153,7 @@ func (self UserRichLogic) IncrUserRich(user *model.User, typ, award int, desc st
152153
session.Commit()
153154
}
154155

155-
func (UserRichLogic) FindBalanceDetail(ctx context.Context, me *model.Me, types ...int) []*model.UserBalanceDetail {
156+
func (UserRichLogic) FindBalanceDetail(ctx context.Context, me *model.Me, p int, types ...int) []*model.UserBalanceDetail {
156157
objLog := GetLogger(ctx)
157158

158159
balanceDetails := make([]*model.UserBalanceDetail, 0)
@@ -161,7 +162,7 @@ func (UserRichLogic) FindBalanceDetail(ctx context.Context, me *model.Me, types
161162
session.And("type=?", types[0])
162163
}
163164

164-
err := session.Desc("id").Find(&balanceDetails)
165+
err := session.Desc("id").Limit(CommentPerNum, (p-1)*CommentPerNum).Find(&balanceDetails)
165166
if err != nil {
166167
objLog.Errorln("UserRichLogic FindBalanceDetail error:", err)
167168
return nil

template/rich/balance.html

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,34 @@
3131
{{.me.Copper}} <img src="/static/img/copper_48.png" alt="" width="16px">
3232
</div>
3333
</div>
34+
{{if gt .total .cmt_per_num}}
35+
<div class="cell balance-page">
36+
<table cellpadding="0" cellspacing="0" border="0" width="100%">
37+
<tbody>
38+
<tr>
39+
{{with $pageMax := divide .total .cmt_per_num}}
40+
<td width="92%" align="left">
41+
{{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>
43+
{{end}}
44+
<input type="number" class="page_input" autocomplete="off" value="{{$.cur_p}}" min="1" max="{{$pageMax}}">
45+
</td>
46+
<td width="8%" align="right">
47+
<table cellpadding="0" cellspacing="0" border="0" width="100%">
48+
<tbody>
49+
<tr data-cur="{{$.cur_p}}" data-max="{{$pageMax}}">
50+
<td width="50%" align="center" class="super normal button nav-page prev-page {{if eq $.cur_p 1}}disable_now{{end}}" style="border-right: none;" title="上一页"></td>
51+
<td width="50%" align="center" class="super normal_page_right button nav-page next-page {{if eq $.cur_p $pageMax}}disable_now{{end}}" title="下一页"></td>
52+
</tr>
53+
</tbody>
54+
</table>
55+
</td>
56+
{{end}}
57+
</tr>
58+
</tbody>
59+
</table>
60+
</div>
61+
{{end}}
3462
<div>
3563
<table cellpadding="5" cellspacing="0" border="0" width="100%" class="data table-hover">
3664
<tr>
@@ -94,9 +122,54 @@ <h2>获得初始资本</h2>
94122
{{define "css"}}
95123
<link rel="stylesheet" type="text/css" href="{{.static_domain}}/static/dist/css/table_data.min.css">
96124
<style type="text/css">
125+
.balance-page { background-image: url('/static/img/shadow_light.png'); background-size: 20px 20px; background-repeat: repeat-x; }
97126
.positive { color: #0aa31c; }
98127
.negative { color: #ff3c00; }
128+
.nav-page { border-top-right-radius: 0px; border-bottom-right-radius: 0px; }
99129
</style>
100130
{{end}}
101131
{{define "js"}}
132+
<script>
133+
$(function(){
134+
$('.prev-page').on('click', function() {
135+
let curPage = $(this).parent().data('cur');
136+
if (curPage > 1) {
137+
location.href='/balance?p='+(curPage-1);
138+
}
139+
});
140+
141+
$('.next-page').on('click', function() {
142+
let curPage = $(this).parent().data('cur'),
143+
pageMax = $(this).parent().data('max');
144+
if (curPage < pageMax) {
145+
location.href='/balance?p='+(curPage+1);
146+
}
147+
});
148+
149+
$('.nav-page').on('mouseover', function() {
150+
if (!$(this).hasClass('disable_now')) {
151+
$(this).addClass('hover_now');
152+
}
153+
});
154+
155+
$('.nav-page').on('mouseleave', function() {
156+
if (!$(this).hasClass('disable_now')) {
157+
$(this).removeClass('hover_now');
158+
$(this).removeClass('active_now')
159+
}
160+
});
161+
162+
$('.nav-page').on('mousedown', function() {
163+
if (!$(this).hasClass('disable_now')) {
164+
$(this).addClass('active_now');
165+
}
166+
});
167+
168+
$('.page_input').on('keydown', function() {
169+
if (event.keyCode == 13) {
170+
location.href = '/balance?p=' + this.value
171+
}
172+
});
173+
});
174+
</script>
102175
{{end}}

0 commit comments

Comments
 (0)