From 833598b90cb3144e2310398bdd090fedd295eaee Mon Sep 17 00:00:00 2001 From: "630892807@qq.com" <630892807@qq.com> Date: Sun, 14 Mar 2021 19:26:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=91=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/message.go | 36 ++++++++++++++++++------------------ static/js/chat-page.js | 20 +++++++++++--------- ws/visitor.go | 2 +- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/controller/message.go b/controller/message.go index 6d097a1..7a3aaf6 100644 --- a/controller/message.go +++ b/controller/message.go @@ -155,7 +155,7 @@ func SendMessageV2(c *gin.Context) { } models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, content, cType) - var msg TypeMessage + //var msg TypeMessage if cType == "kefu" { guest, ok := ws.ClientList[vistorInfo.VisitorId] @@ -191,20 +191,21 @@ func SendMessageV2(c *gin.Context) { // }) // return //} - msg = TypeMessage{ - Type: "message", - Data: ws.ClientMessage{ - Avator: vistorInfo.Avator, - Id: vistorInfo.VisitorId, - Name: vistorInfo.Name, - ToId: kefuInfo.Name, - Content: content, - Time: time.Now().Format("2006-01-02 15:04:05"), - IsKefu: "no", - }, - } - str, _ := json.Marshal(msg) - ws.OneKefuMessage(kefuInfo.Name, str) + //msg = TypeMessage{ + // Type: "message", + // Data: ws.ClientMessage{ + // Avator: vistorInfo.Avator, + // Id: vistorInfo.VisitorId, + // Name: vistorInfo.Name, + // ToId: kefuInfo.Name, + // Content: content, + // Time: time.Now().Format("2006-01-02 15:04:05"), + // IsKefu: "no", + // }, + //} + //str, _ := json.Marshal(msg) + //ws.OneKefuMessage(kefuInfo.Name, str) + ws.KefuMessage(vistorInfo.VisitorId, content, kefuInfo) go ws.SendServerJiang(vistorInfo.Name+"说", content, c.Request.Host) go SendAppGetuiPush(kefuInfo.Name, vistorInfo.Name, content) kefus, ok := ws.KefuList[kefuInfo.Name] @@ -214,9 +215,8 @@ func SendMessageV2(c *gin.Context) { } go ws.VisitorAutoReply(vistorInfo, kefuInfo, content) c.JSON(200, gin.H{ - "code": 200, - "msg": "ok", - "result": msg, + "code": 200, + "msg": "ok", }) } diff --git a/static/js/chat-page.js b/static/js/chat-page.js index 2913f37..ae3cfa4 100644 --- a/static/js/chat-page.js +++ b/static/js/chat-page.js @@ -116,6 +116,16 @@ new Vue({ } this.sendDisabled=true; let _this=this; + + let content = {} + content.avator=_this.visitor.avator; + content.content = replaceContent(_this.messageContent); + content.name = _this.visitor.name; + content.is_kefu = true; + content.time = _this.getNowDate(); + _this.msgList.push(content); + _this.scrollBottom(); + let mes = {}; mes.type = "visitor"; mes.content = this.messageContent; @@ -126,21 +136,13 @@ new Vue({ $.post("/2/message",mes,function(res){ _this.sendDisabled=false; if(res.code!=200){ + _this.msgList.pop(); _this.$message({ message: res.msg, type: 'error' }); return; } - let content = {} - content.avator=_this.visitor.avator; - content.content = replaceContent(_this.messageContent); - content.name = _this.visitor.name; - content.is_kefu = true; - content.time = res.result.data.time; - _this.msgList.push(content); - //_this.saveHistory(content); - _this.scrollBottom(); _this.messageContent = ""; clearInterval(_this.timer); _this.sendSound(); diff --git a/ws/visitor.go b/ws/visitor.go index 6bcd32a..1ede96f 100644 --- a/ws/visitor.go +++ b/ws/visitor.go @@ -155,7 +155,7 @@ func VisitorAutoReply(vistorInfo models.Visitor, kefuInfo models.User, content s kefus, ok := KefuList[kefuInfo.Name] reply := models.FindReplyItemByUserIdTitle(kefuInfo.Name, content) if reply.Content != "" { - time.Sleep(2 * time.Second) + time.Sleep(1 * time.Second) VisitorMessage(vistorInfo.VisitorId, reply.Content, kefuInfo) KefuMessage(vistorInfo.VisitorId, reply.Content, kefuInfo) models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, reply.Content, "kefu")