From 90b36f2a90d38c55dec8f51d693e2e29525f5dff Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Thu, 4 Jun 2020 14:31:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=9C=8D=E4=B8=8A=E7=BA=BF=E7=BB=99?= =?UTF-8?q?=E5=AE=A2=E6=9C=8D=E5=8F=91=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/chat.go | 14 ++++++++++++ static/html/chat_main.html | 46 +++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/controller/chat.go b/controller/chat.go index 048a93b..ece224e 100644 --- a/controller/chat.go +++ b/controller/chat.go @@ -86,10 +86,24 @@ func ChatServer(w *websocket.Conn) { }, } jsonStrByte, _ := json.Marshal(sendMsg) + //发送给客户 log.Println("发送给客户",clientList,string(jsonStrByte)) for _, conn := range clientList { websocket.Message.Send(conn, string(jsonStrByte)) } + //发送给客服通知 + result := make([]map[string]string, 0) + for uid, _ := range clientList { + userInfo := make(map[string]string) + userInfo["uid"] = uid + result = append(result, userInfo) + } + msg:=NoticeMessage{ + Type: "notice", + Data:result, + } + str,_:=json.Marshal(msg);sendStr:=string(str) + websocket.Message.Send(w,sendStr) case "chatMessage": } diff --git a/static/html/chat_main.html b/static/html/chat_main.html index 274c1b0..8a9df7d 100644 --- a/static/html/chat_main.html +++ b/static/html/chat_main.html @@ -58,7 +58,7 @@ - + 访客:<{v.uid}> @@ -67,21 +67,21 @@
- +
内容
内容
- +
内容
内容
- - 发送 + + 发送
@@ -99,9 +99,11 @@ delimiters:["<{","}>"], data: { fullscreenLoading:true, - onlineUsers:[], + users:[], server:"ws://127.0.0.1:8080/chat_server", socket:null, + messageContent:"", + currentGuest:"", }, methods: { //跳转 @@ -110,12 +112,12 @@ }, getOnlineUsers(){ let _this=this; - $.get('/chat_users',function (rs) { - _this.onlineUsers=rs.result - _this.fullscreenLoading=false; - }).then(()=>{ - _this.fullscreenLoading=false; - }); + // $.get('/chat_users',function (rs) { + // _this.users=rs.result + // _this.fullscreenLoading=false; + // }).then(()=>{ + // _this.fullscreenLoading=false; + // }); }, //初始化websocket initConn(){ @@ -142,18 +144,26 @@ type: 'success', duration: 0, }); - this.onlineUsers=redata.data; + this.users=redata.data; + this.currentGuest=redata.data[0].uid; } }, //接手客户 talkTo(guestId){ + this.currentGuest=guestId; + }, + //发送给客户 + chatToUser(){ + let mes={}; let data={}; - data.type="kfOnline"; - data.uid="kf_1"; - data.name="客服丽丽"; + mes.type="messageType"; + data.content=this.messageContent; + data.kf_id="kf_1"; + data.guest_id=this.currentGuest; + data.kf_name="客服丽丽"; data.avatar="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4217138672,2588039002&fm=26&gp=0.jpg"; - data.group="1"; - socket.send(JSON.stringify(data)); + mes.data=data; + this.socket.send(JSON.stringify(mes)); }, }, created: function () {