定时请求在线用户

pull/23/head
taoshihan1991 4 years ago
parent 0ea5292d57
commit 253cfff66c

@ -246,30 +246,6 @@ func SendVisitorNotice(c *gin.Context) {
"msg": "ok", "msg": "ok",
}) })
} }
func SendCloseMessage(c *gin.Context) {
visitorId := c.Query("visitor_id")
if visitorId == "" {
c.JSON(200, gin.H{
"code": 400,
"msg": "visitor_id不能为空",
})
return
}
msg := TypeMessage{
Type: "close",
Data: visitorId,
}
str, _ := json.Marshal(msg)
for _, visitor := range clientList {
if visitorId == visitor.id {
visitor.conn.WriteMessage(websocket.TextMessage, str)
}
}
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
})
}
func SendCloseMessageV2(c *gin.Context) { func SendCloseMessageV2(c *gin.Context) {
visitorId := c.Query("visitor_id") visitorId := c.Query("visitor_id")
if visitorId == "" { if visitorId == "" {

@ -35,8 +35,6 @@ func InitApiRouter(engine *gin.Engine) {
engine.GET("/message_notice", controller.SendVisitorNotice) engine.GET("/message_notice", controller.SendVisitorNotice)
//发送单条消息 //发送单条消息
engine.POST("/message", middleware.Ipblack, controller.SendMessage) engine.POST("/message", middleware.Ipblack, controller.SendMessage)
//发送关闭消息
engine.GET("/message_close", controller.SendCloseMessage)
//上传文件 //上传文件
engine.POST("/uploadimg", middleware.Ipblack, controller.UploadImg) engine.POST("/uploadimg", middleware.Ipblack, controller.UploadImg)
//上传文件 //上传文件

@ -72,7 +72,10 @@ var app=new Vue({
if(_this.socket!=null){ if(_this.socket!=null){
_this.socket.send(JSON.stringify(mes)); _this.socket.send(JSON.stringify(mes));
} }
},5000) },20000)
setInterval(function(){
_this.getOnlineVisitors();
},600000);
}, },
//初始化websocket //初始化websocket
initConn() { initConn() {
@ -429,6 +432,9 @@ var app=new Vue({
//处理tab切换 //处理tab切换
handleTabClick(tab, event){ handleTabClick(tab, event){
let _this=this; let _this=this;
if(tab.name=="first"){
this.getOnlineVisitors();
}
if(tab.name=="second"){ if(tab.name=="second"){
this.getVisitorPage(1); this.getVisitorPage(1);
} }

Loading…
Cancel
Save