|
|
@ -102,11 +102,11 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
//跳转
|
|
|
|
//跳转
|
|
|
|
openUrl(url){
|
|
|
|
openUrl(url) {
|
|
|
|
window.location.href=url;
|
|
|
|
window.location.href = url;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getOnlineUsers(){
|
|
|
|
getOnlineUsers() {
|
|
|
|
let _this=this;
|
|
|
|
let _this = this;
|
|
|
|
// $.get('/chat_users',function (rs) {
|
|
|
|
// $.get('/chat_users',function (rs) {
|
|
|
|
// _this.users=rs.result
|
|
|
|
// _this.users=rs.result
|
|
|
|
// _this.fullscreenLoading=false;
|
|
|
|
// _this.fullscreenLoading=false;
|
|
|
@ -115,105 +115,95 @@
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//初始化websocket
|
|
|
|
//初始化websocket
|
|
|
|
initConn(){
|
|
|
|
initConn() {
|
|
|
|
let socket=new ReconnectingWebSocket(this.server);//创建Socket实例
|
|
|
|
let socket = new ReconnectingWebSocket(this.server);//创建Socket实例
|
|
|
|
this.socket = socket
|
|
|
|
this.socket = socket
|
|
|
|
this.socket.onmessage = this.OnMessage;
|
|
|
|
this.socket.onmessage = this.OnMessage;
|
|
|
|
this.socket.onopen = this.OnOpen;
|
|
|
|
this.socket.onopen = this.OnOpen;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OnOpen(){
|
|
|
|
OnOpen() {
|
|
|
|
let data={};
|
|
|
|
let data = {};
|
|
|
|
let mes={}
|
|
|
|
let mes = {}
|
|
|
|
mes.type="kfOnline";
|
|
|
|
mes.type = "kfOnline";
|
|
|
|
data.kf_id="kf_1";
|
|
|
|
data.kf_id = "kf_1";
|
|
|
|
data.kf_name="客服丽丽";
|
|
|
|
data.kf_name = "客服丽丽";
|
|
|
|
data.avatar="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4217138672,2588039002&fm=26&gp=0.jpg";
|
|
|
|
data.avatar = "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4217138672,2588039002&fm=26&gp=0.jpg";
|
|
|
|
data.group="1";
|
|
|
|
data.group = "1";
|
|
|
|
mes.data=data;
|
|
|
|
mes.data = data;
|
|
|
|
this.socket.send(JSON.stringify(mes));
|
|
|
|
this.socket.send(JSON.stringify(mes));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OnMessage(e){
|
|
|
|
OnMessage(e) {
|
|
|
|
const redata = JSON.parse(e.data);
|
|
|
|
const redata = JSON.parse(e.data);
|
|
|
|
if (redata.type=="notice"){
|
|
|
|
if (redata.type == "notice") {
|
|
|
|
this.$notify({
|
|
|
|
this.$notify({
|
|
|
|
title: "通知",
|
|
|
|
title: "通知",
|
|
|
|
message: "新客户访问",
|
|
|
|
message: "新客户访问",
|
|
|
|
type: 'success',
|
|
|
|
type: 'success',
|
|
|
|
duration: 0,
|
|
|
|
duration: 0,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.users=redata.data;
|
|
|
|
this.users = redata.data;
|
|
|
|
this.currentGuest=redata.data[0].uid;
|
|
|
|
this.currentGuest = redata.data[0].uid;
|
|
|
|
|
|
|
|
for(i=0;i<redata.data.length;i++){
|
|
|
|
|
|
|
|
if (typeof (this.msgListUser[redata.data[i].uid]) == "undefined") {
|
|
|
|
|
|
|
|
this.msgListUser[redata.data[i].uid] = [];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (redata.type=="chatMessage"){
|
|
|
|
if (redata.type == "chatMessage") {
|
|
|
|
let msg=redata.data
|
|
|
|
let msg = redata.data
|
|
|
|
let content={}
|
|
|
|
let content = {}
|
|
|
|
content.avatar=msg.from_avatar;
|
|
|
|
content.avatar = msg.from_avatar;
|
|
|
|
content.name=msg.from_name;
|
|
|
|
content.name = msg.from_name;
|
|
|
|
content.content=msg.content;
|
|
|
|
content.content = msg.content;
|
|
|
|
content.is_kefu=false;
|
|
|
|
content.is_kefu = false;
|
|
|
|
content.time=msg.time;
|
|
|
|
content.time = msg.time;
|
|
|
|
if(msg.from_id==this.currentGuest){
|
|
|
|
if (msg.from_id == this.currentGuest) {
|
|
|
|
this.msgList.push(content);
|
|
|
|
this.msgList.push(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (typeof(this.msgListUser[msg.from_id])=="undefined"){
|
|
|
|
if (typeof (this.msgListUser[msg.from_id]) == "undefined") {
|
|
|
|
this.msgListUser[msg.from_id]=[];
|
|
|
|
this.msgListUser[msg.from_id] = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.msgListUser[msg.from_id].push(content);
|
|
|
|
this.msgListUser[msg.from_id].push(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//接手客户
|
|
|
|
//接手客户
|
|
|
|
talkTo(guestId){
|
|
|
|
talkTo(guestId) {
|
|
|
|
this.currentGuest=guestId;
|
|
|
|
this.currentGuest = guestId;
|
|
|
|
this.msgList=[];
|
|
|
|
this.msgList = [];
|
|
|
|
this.msgList=this.clone(this.msgListUser[guestId]);
|
|
|
|
let buf = [];
|
|
|
|
|
|
|
|
var i = this.msgListUser[guestId].length;
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
|
|
|
|
buf[i] = this.msgListUser[guestId][i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.msgList = buf;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//发送给客户
|
|
|
|
//发送给客户
|
|
|
|
chatToUser(){
|
|
|
|
chatToUser() {
|
|
|
|
let mes={};
|
|
|
|
let mes = {};
|
|
|
|
let data={};
|
|
|
|
let data = {};
|
|
|
|
mes.type="kfChatMessage";
|
|
|
|
mes.type = "kfChatMessage";
|
|
|
|
data.content=this.messageContent;
|
|
|
|
data.content = this.messageContent;
|
|
|
|
data.kf_id="kf_1";
|
|
|
|
data.kf_id = "kf_1";
|
|
|
|
data.guest_id=this.currentGuest;
|
|
|
|
data.guest_id = this.currentGuest;
|
|
|
|
data.kf_name="客服丽丽";
|
|
|
|
data.kf_name = "客服丽丽";
|
|
|
|
data.avatar="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4217138672,2588039002&fm=26&gp=0.jpg";
|
|
|
|
data.avatar = "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4217138672,2588039002&fm=26&gp=0.jpg";
|
|
|
|
mes.data=data;
|
|
|
|
mes.data = data;
|
|
|
|
this.socket.send(JSON.stringify(mes));
|
|
|
|
this.socket.send(JSON.stringify(mes));
|
|
|
|
this.messageContent="";
|
|
|
|
this.messageContent = "";
|
|
|
|
|
|
|
|
|
|
|
|
let content={}
|
|
|
|
let content = {}
|
|
|
|
content.avatar=data.avatar;
|
|
|
|
content.avatar = data.avatar;
|
|
|
|
content.name=data.kf_name;
|
|
|
|
content.name = data.kf_name;
|
|
|
|
content.content=data.content;
|
|
|
|
content.content = data.content;
|
|
|
|
content.is_kefu=true;
|
|
|
|
content.is_kefu = true;
|
|
|
|
content.time=data.time;
|
|
|
|
content.time = data.time;
|
|
|
|
this.msgList.push(content);
|
|
|
|
this.msgList.push(content);
|
|
|
|
if (typeof(this.msgListUser[this.currentGuest])=="undefined"){
|
|
|
|
if (typeof (this.msgListUser[this.currentGuest]) == "undefined") {
|
|
|
|
this.msgListUser[this.currentGuest]=[];
|
|
|
|
this.msgListUser[this.currentGuest] = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.msgListUser[this.currentGuest].push(content);
|
|
|
|
this.msgListUser[this.currentGuest].push(content);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
clone(Obj){
|
|
|
|
|
|
|
|
var buf;
|
|
|
|
|
|
|
|
if(Obj instanceof Array){
|
|
|
|
|
|
|
|
buf=[];
|
|
|
|
|
|
|
|
var i=Obj.length;
|
|
|
|
|
|
|
|
while(i--){
|
|
|
|
|
|
|
|
buf[i]=clone(Obj[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
}else if(Obj instanceof Object){
|
|
|
|
|
|
|
|
buf={};
|
|
|
|
|
|
|
|
for(var k in Obj){
|
|
|
|
|
|
|
|
buf[k]=clone(Obj[k]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
return Obj;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
created: function () {
|
|
|
|
created: function () {
|
|
|
|
this.getOnlineUsers();
|
|
|
|
this.getOnlineUsers();
|
|
|
|