增加全量游客tab

This commit is contained in:
goder-zhang 2026-03-05 14:57:10 +00:00
parent 561b009072
commit d01cf601b7
3 changed files with 100 additions and 3 deletions

View File

@ -285,10 +285,13 @@ func GetKefusVisitorOnlines(c *gin.Context) {
kefuName, _ := c.Get("kefu_name")
users := make([]*VisitorOnline, 0)
visitorIds := make([]string, 0)
isAdmin := models.IsAdmin(kefuName.(string))
for uid, visitor := range ws.ClientList {
if visitor.To_id != kefuName {
if !isAdmin {
continue
}
}
userInfo := new(VisitorOnline)
userInfo.Uid = uid
userInfo.Username = visitor.Name

View File

@ -53,6 +53,12 @@ func FindVisitors(page uint, pagesize uint) []Visitor {
DB.Offset(offset).Limit(pagesize).Order("status desc, updated_at desc").Find(&visitors)
return visitors
}
func IsAdmin(kefuName string) bool {
kefuInfo := FindUser(kefuName)
return kefuInfo.Role == 1
}
func FindVisitorsByKefuId(page uint, pagesize uint, kefuId string) []Visitor {
offset := (page - 1) * pagesize
if offset <= 0 {
@ -61,7 +67,11 @@ func FindVisitorsByKefuId(page uint, pagesize uint, kefuId string) []Visitor {
var visitors []Visitor
//sql := fmt.Sprintf("select * from visitor where id>=(select id from visitor where to_id='%s' order by updated_at desc limit %d,1) and to_id='%s' order by updated_at desc limit %d ", kefuId, offset, kefuId, pagesize)
//DB.Raw(sql).Scan(&visitors)
DB.Where("to_id=?", kefuId).Offset(offset).Limit(pagesize).Order("updated_at desc").Find(&visitors)
db := DB
if !IsAdmin(kefuId) {
db = db.Where("to_id=?", kefuId)
}
db.Offset(offset).Limit(pagesize).Order("status desc,updated_at desc").Find(&visitors)
return visitors
}
func FindVisitorsOnline() []Visitor {
@ -101,7 +111,11 @@ func CountVisitors() uint {
// 查询条数
func CountVisitorsByKefuId(kefuId string) uint {
var count uint
DB.Model(&Visitor{}).Where("to_id=?", kefuId).Count(&count)
db := DB
if !IsAdmin(kefuId) {
db = db.Where("to_id=?", kefuId)
}
db.Count(&count)
return count
}

View File

@ -74,6 +74,27 @@
:total="visitorCount">
</el-pagination>
</el-tab-pane>
<el-tab-pane label="All Visitors" name="third">
<el-row v-for="item in allVisitors" :key="item.uid" class="">
<div style="cursor:pointer" class="onlineUsers" v-bind:class="{'cur': item.visitor_id==currentGuest }" v-on:click="talkTo(item.visitor_id,item.name)">
<el-col :span="4">
<el-avatar v-bind:class="{'imgGray': item.status==0 }" :size="40" :src="item.avator"></el-avatar>
</el-col>
<el-col style="height:40px;overflow: hidden" :span="16" v-bind:class="{'imgGray': item.status==0 }">
<{item.name}>
</el-col>
</div>
</el-row>
<el-pagination
v-show="allVisitorCount>allVisitorPageSize"
background
@current-change="allVisitorPage"
:current-page="allVisitorCurrentPage"
layout="prev,pager, next"
:page-size="allVisitorPageSize"
:total="allVisitorCount">
</el-pagination>
</el-tab-pane>
</el-tabs>
</div>
</el-col>
@ -350,6 +371,10 @@
visitorCount:0,
visitorCurrentPage:1,
visitorPageSize:10,
allVisitors:[],
allVisitorCount:0,
allVisitorCurrentPage:1,
allVisitorPageSize:10,
face:[],
transKefuDialog:false,
otherKefus:[],
@ -576,6 +601,13 @@
break;
}
}
// 更新所有访客列表的在线状态
for(let i=0;i<this.allVisitors.length;i++){
if(this.allVisitors[i].visitor_id==retData.uid){
this.allVisitors[i].status=1;
break;
}
}
if(this.visitor.visitor_id==retData.uid){
this.getVistorInfo(retData.uid)
}
@ -595,6 +627,13 @@
break;
}
}
// 更新所有访客列表的在线状态
for(let i=0;i<this.allVisitors.length;i++){
if(this.allVisitors[i].visitor_id==vid){
this.allVisitors[i].status=0;
break;
}
}
},
//处理当前在线用户列表
handleOnlineUsers:function (retData) {
@ -617,6 +656,15 @@
this.visitors[i].status=1;
}
}
// 更新所有访客列表的在线状态
for(let i=0;i<this.allVisitors.length;i++){
let vid=this.allVisitors[i].visitor_id;
if(typeof this.usersMap[vid]=="undefined"){
this.allVisitors[i].status=0;
}else{
this.allVisitors[i].status=1;
}
}
},
//处理正在输入
@ -850,6 +898,9 @@
if(tab.name=="second"){
this.getVisitorPage(1);
}
if(tab.name=="third"){
this.getAllVisitorPage(1);
}
if(tab.name=="blackList"){
}
},
@ -882,6 +933,35 @@
}
});
},
//所有访客分页展示
allVisitorPage(page){
this.getAllVisitorPage(page);
},
//获取所有访客分页
getAllVisitorPage(page){
let _this=this;
$.ajax({
type:"get",
url:"/aicss/visitors",
data:{page:page},
headers:{
"aicss-token":localStorage.getItem("aicss-token")
},
success: function(data) {
if(data.result.list!=null){
_this.allVisitors=data.result.list;
_this.allVisitorCount=data.result.count;
_this.allVisitorPageSize=data.result.pagesize;
}
if(data.code!=200){
_this.$message({
message: data.msg,
type: 'error'
});
}
}
});
},
replaceContent(content){
return replaceContent(content)
},