获取所有访客

pull/30/head
陶士涵 4 years ago
parent ab6b9d6bc7
commit 758b8b9ffd

@ -127,6 +127,7 @@ func SendNoticeToAllKefu() {
//获取当前的在线用户
func getOnlineUser(w *websocket.Conn) {
result := make([]map[string]string, 0)
log.Println(clientList)
for _, user := range clientList {
userInfo := make(map[string]string)
userInfo["uid"] = user.id
@ -190,7 +191,11 @@ func singleBroadcaster(){
case "kfConnect":
json.Unmarshal(msgData, &clientMsg)
kefuList[clientMsg.Id] = conn
SendKefuOnline(clientMsg, clientList[clientMsg.ToId].conn)
visitor,ok := clientList[clientMsg.ToId]
if visitor==nil||!ok{
return
}
SendKefuOnline(clientMsg, visitor.conn)
case "kfChatMessage":
json.Unmarshal(msgData, &clientMsg)
guest,ok:=clientList[clientMsg.ToId]

@ -3,16 +3,22 @@ package controller
import (
"github.com/gin-gonic/gin"
"github.com/taoshihan1991/imaptool/models"
"log"
)
func GetVisitor(c *gin.Context) {
visitorId:=c.Query("visitorId")
vistor:=models.FindVisitorByVistorId(visitorId)
log.Println(visitorId)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":vistor,
})
}
func GetVisitors(c *gin.Context) {
vistors:=models.FindVisitors()
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
"result":vistors,
})
}

@ -37,3 +37,8 @@ func FindVisitorByVistorId(visitorId string)Visitor{
DB.Where("visitor_id = ?", visitorId).First(&v)
return v
}
func FindVisitors()[]Visitor{
var visitors []Visitor
DB.Find(&visitors)
return visitors
}

@ -40,6 +40,7 @@ func main() {
engine.GET("/mysql",middleware.JwtApiMiddleware,middleware.CasbinACL, controller.MysqlGetConf)
engine.POST("/mysql",middleware.JwtApiMiddleware,middleware.CasbinACL, controller.MysqlSetConf)
engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor)
engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors)
//------------------old code-----------------------------
mux := &http.ServeMux{}
//根路径

@ -65,10 +65,10 @@
<el-row :gutter="5">
<el-col :span="6">
<div class="chatLeft">
<el-tabs v-model="leftTabActive">
<el-tabs v-model="leftTabActive" @tab-click="handleTabClick">
<el-tab-pane label="在线用户" name="first">
<el-row v-for="item in users" :key="item.uid" class="">
<div style="cursor:pointer" class="onlineUsers" v-bind:class="{'cur': item.uid==currentGuest }" v-on:click="talkTo(item.uid)">
<div style="cursor:pointer" class="onlineUsers" v-bind:class="{'cur': item.uid==currentGuest }" v-on:click="talkTo(item.uid,item.username)">
<el-col :span="4">
<el-avatar :size="40" :src="item.avator"></el-avatar>
</el-col>
@ -79,6 +79,16 @@
</el-row>
</el-tab-pane>
<el-tab-pane label="所有访客" name="second">
<el-row v-for="item in visitors" :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 :size="40" :src="item.avator"></el-avatar>
</el-col>
<el-col :span="16">
<{item.name}>
</el-col>
</div>
</el-row>
</el-tab-pane>
</el-tabs>
</div>
@ -159,7 +169,8 @@
client_ip:"",
city:"",
status:"",
}
},
visitors:[],
},
methods: {
//跳转
@ -244,14 +255,16 @@
}
},
//接手客户
talkTo(guestId) {
talkTo(guestId,name) {
this.currentGuest = guestId;
this.chatTitle=this.usersMap[guestId]+guestId+",正在处理中...";
this.chatTitle=name+"|"+guestId+",正在处理中...";
this.msgList = [];
let buf = [];
var i = this.msgListUser[guestId].length;
while (i--) {
buf[i] = this.msgListUser[guestId][i];
if(typeof this.msgListUser[guestId]!="undefined"){
var i = this.msgListUser[guestId].length;
while (i--) {
buf[i] = this.msgListUser[guestId][i];
}
}
this.msgList = buf;
@ -358,6 +371,30 @@
}
});
},
//处理tab切换
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'
});
}
}
});
}
},
},
created: function () {
this.getKefuInfo();

Loading…
Cancel
Save