增加所有访客分页

pull/30/head
taoshihan1991 4 years ago
parent eb4a28380a
commit 1fc929a63e

@ -7,6 +7,9 @@ import (
"io/ioutil"
"os"
)
var(
PageSize uint=2
)
const Dir = "config/"
const AccountConf = Dir + "account.json"
const MysqlConf = Dir + "mysql.json"

@ -2,7 +2,9 @@ package controller
import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models"
"strconv"
)
func GetVisitor(c *gin.Context) {
@ -15,11 +17,17 @@ func GetVisitor(c *gin.Context) {
})
}
func GetVisitors(c *gin.Context) {
vistors:=models.FindVisitors()
page,_:=strconv.Atoi(c.Query("page"))
vistors:=models.FindVisitors(uint(page))
count:=models.CountVisitors()
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":vistors,
"result":gin.H{
"list":vistors,
"count":count,
"pagesize":config.PageSize,
},
})
}
func GetVisitorMessage(c *gin.Context) {

@ -1,5 +1,7 @@
package models
import "github.com/taoshihan1991/imaptool/config"
type Visitor struct {
Model
Name string `json:"name"`
@ -37,9 +39,13 @@ func FindVisitorByVistorId(visitorId string)Visitor{
DB.Where("visitor_id = ?", visitorId).First(&v)
return v
}
func FindVisitors()[]Visitor{
func FindVisitors(page uint)[]Visitor{
offset:=(page-1)*config.PageSize
if offset<0{
offset=0
}
var visitors []Visitor
DB.Order("status desc, updated_at desc").Find(&visitors)
DB.Offset(offset).Limit(config.PageSize).Order("status desc, updated_at desc").Find(&visitors)
return visitors
}
func FindVisitorsOnline()[]Visitor{
@ -51,4 +57,10 @@ func UpdateVisitorStatus(visitorId string,status uint){
visitor:=Visitor{
}
DB.Model(&visitor).Where("visitor_id = ?",visitorId).Update("status", status)
}
//查询条数
func CountVisitors()uint{
var count uint
DB.Model(&Visitor{}).Count(&count)
return count
}

@ -93,6 +93,14 @@
</el-col>
</div>
</el-row>
<el-pagination
background
@current-change="visitorPage"
:current-page="visitorCurrentPage"
layout="prev,pager, next"
:page-size="visitorPageSize"
:total="visitorCount">
</el-pagination>
</el-tab-pane>
</el-tabs>
</div>
@ -176,6 +184,9 @@
status:"",
},
visitors:[],
visitorCount:0,
visitorCurrentPage:1,
visitorPageSize:10,
},
methods: {
//跳转
@ -399,26 +410,38 @@
handleTabClick(tab, event){
let _this=this;
if(tab.name=="second"){
$.ajax({
type:"get",
url:"/visitors",
headers:{
"token":localStorage.getItem("token")
},
success: function(data) {
if(data.result!=null){
_this.visitors=data.result;
}
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}
}
});
this.getVisitorPage(1);
}
},
//所有访客分页展示
visitorPage(page){
this.getVisitorPage(page);
},
//获取访客分页
getVisitorPage(page){
let _this=this;
$.ajax({
type:"get",
url:"/visitors",
data:{page:page},
headers:{
"token":localStorage.getItem("token")
},
success: function(data) {
if(data.result.list!=null){
_this.visitors=data.result.list;
_this.visitorCount=data.result.count;
_this.visitorPageSize=data.result.pagesize;
}
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}
}
});
},
//滚到底部
scrollBottom(){
this.$nextTick(() => {

Loading…
Cancel
Save