diff --git a/controller/chat.go b/controller/chat.go index 75f0a5b..7c6f4d7 100644 --- a/controller/chat.go +++ b/controller/chat.go @@ -43,6 +43,7 @@ type KfMessage struct { Kf_name string `json:"kf_name"` Avatar string `json:"avatar"` Kf_id string `json:"kf_id"` + Kf_group string `json:"kf_group"` Time string `json:"time"` Guest_id string `json:"guest_id"` Content string `json:"content"` @@ -84,44 +85,25 @@ func ChatServer(w *websocket.Conn) { json.Unmarshal(msgData,&userMsg) //用户id对应的连接 clientList[userMsg.From_id] = w - SendUserAllNotice() - + clientNameList[userMsg.From_id]=userMsg.From_name //客服上线 case "kfOnline": json.Unmarshal(msgData,&kfMsg) //客服id对应的连接 kefuList[kfMsg.Kf_id] = w - sendMsg := TypeMessage{ - Type: "kfOnline", - Data: KfMessage{ - Kf_name: kfMsg.Kf_name, - Avatar: kfMsg.Avatar, - Kf_id: kfMsg.Kf_id, - Time: time.Now().Format("2006-01-02 15:04:05"), - Content: "客服上线", - }, - } - jsonStrByte, _ := json.Marshal(sendMsg) //发送给客户 if len(clientList)==0{ break } for _, conn := range clientList { - websocket.Message.Send(conn, string(jsonStrByte)) + SendKefuOnline(kfMsg,conn) } //发送给客服通知 - 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) + SendOnekfuAllNotice(w) + //客服接手 + case "kfConnect": + json.Unmarshal(msgData,&kfMsg) + SendKefuOnline(kfMsg,clientList[kfMsg.Guest_id]) case "kfChatMessage": json.Unmarshal(msgData,&kfMsg) conn:=clientList[kfMsg.Guest_id] @@ -158,6 +140,7 @@ func ChatServer(w *websocket.Conn) { } } } +//发送给所有客服客户上线 func SendUserAllNotice(){ if len(kefuList)!=0{ //发送给客服通知 @@ -166,6 +149,7 @@ func SendUserAllNotice(){ for uid, _ := range clientList { userInfo := make(map[string]string) userInfo["uid"] = uid + userInfo["username"]=clientNameList[uid] result = append(result, userInfo) } msg:=NoticeMessage{ @@ -177,8 +161,40 @@ func SendUserAllNotice(){ } } } -func SendKefuOnline(){} +//发送给客户客服上线 +func SendKefuOnline(kfMsg KfMessage,conn *websocket.Conn){ + sendMsg := TypeMessage{ + Type: "kfOnline", + Data: KfMessage{ + Kf_name: kfMsg.Kf_name, + Avatar: kfMsg.Avatar, + Kf_id: kfMsg.Kf_id, + Kf_group: kfMsg.Kf_group, + Time: time.Now().Format("2006-01-02 15:04:05"), + Content: "客服上线", + }, + } + jsonStrByte, _ := json.Marshal(sendMsg) + websocket.Message.Send(conn, string(jsonStrByte)) +} +//发送给所有客服客户上线 +func SendOnekfuAllNotice(conn *websocket.Conn){ + result := make([]map[string]string, 0) + for uid, _ := range clientList { + userInfo := make(map[string]string) + userInfo["uid"] = uid + userInfo["username"]=clientNameList[uid] + result = append(result, userInfo) + } + msg:=NoticeMessage{ + Type: "notice", + Data:result, + } + str,_:=json.Marshal(msg);sendStr:=string(str) + websocket.Message.Send(conn,sendStr) +} func SendUserChat(){} func SendKefuChat(){} var clientList = make(map[string]*websocket.Conn) +var clientNameList = make(map[string]string) var kefuList = make(map[string]*websocket.Conn) \ No newline at end of file diff --git a/static/html/chat_main.html b/static/html/chat_main.html index 3eb8858..8ca18a4 100644 --- a/static/html/chat_main.html +++ b/static/html/chat_main.html @@ -60,7 +60,7 @@ - 访客:<{v.uid}> + <{v.username}> @@ -91,7 +91,7 @@ kfConfig.kf_id = "kf_1"; kfConfig.kf_name = "客服丽丽"; kfConfig.avatar = "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4217138672,2588039002&fm=26&gp=0.jpg"; - kfConfig.group = "1"; + kfConfig.kf_group = "1"; var app=new Vue({ el: '#app', @@ -182,7 +182,7 @@ //发送给客户我在线 let mes = {} - mes.type = "kfOnline"; + mes.type = "kfConnect"; kfConfig.guest_id=guestId; mes.data = kfConfig; this.socket.send(JSON.stringify(mes)); diff --git a/static/html/login.html b/static/html/login.html index 5cc5414..d54c938 100644 --- a/static/html/login.html +++ b/static/html/login.html @@ -39,6 +39,52 @@ -webkit-box-shadow: 0 1px 2px 0 rgba(101,129,156,.08); box-shadow: 0 1px 2px 0 rgba(101,129,156,.08); } + + + .chatContext{ + background: #fff;border: solid 1px #e6e6e6;boder-top:none;padding:5px 10px; + position: fixed; + right: 2px; + bottom: 10px; + min-height: 300px; + } + .chatBox{ + min-height: 200px; + } + .chatUser{ + line-height: 24px; + font-size: 12px; + white-space: nowrap; + color: #999; + } + .chatContent{ + text-align: left; + background-color: rgb(166,212,242); + color: #000; + border: 1px solid rgb(152, 199, 230); + padding: 8px 15px; + min-height: 35px; + word-break: break-all; + position: relative; + } + .chatContent:after { + content: ''; + position: absolute; + left: -10px; + top: 13px; + width: 0; + height: 0; + border-style: dashed; + border-color: transparent; + overflow: hidden; + border-width: 10px; + border-top-style: solid; + border-top-color: rgb(166,212,242); + } + .chatBoxMe .el-col-3{float: right;text-align: right;} + .chatBoxMe .chatUser{text-align: right} + .chatBoxMe .chatContent:after{left:auto;right: -10px;} + .chatArea{margin: 10px 0;} @@ -95,12 +141,39 @@

© 2020

+ + +
+
+ + + +
<{v.name}>
+
<{v.content}>
+
+
+
+ + 发送 +
+ + + + + diff --git a/static/html/main.html b/static/html/main.html index 748e21e..ebd5f52 100644 --- a/static/html/main.html +++ b/static/html/main.html @@ -133,1124 +133,5 @@ }); - - -
咨询客服
- -