|
|
@ -19,7 +19,7 @@ new Vue({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
//初始化websocket
|
|
|
|
//初始化websocket
|
|
|
|
initConn() {
|
|
|
|
initConn:function() {
|
|
|
|
let socket = new ReconnectingWebSocket(this.server+"?visitor_id="+this.visitor.visitor_id);//创建Socket实例
|
|
|
|
let socket = new ReconnectingWebSocket(this.server+"?visitor_id="+this.visitor.visitor_id);//创建Socket实例
|
|
|
|
socket.maxReconnectAttempts = 30;
|
|
|
|
socket.maxReconnectAttempts = 30;
|
|
|
|
this.socket = socket
|
|
|
|
this.socket = socket
|
|
|
@ -29,7 +29,7 @@ new Vue({
|
|
|
|
//心跳
|
|
|
|
//心跳
|
|
|
|
this.ping();
|
|
|
|
this.ping();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OnOpen() {
|
|
|
|
OnOpen:function() {
|
|
|
|
this.chatTitle="连接成功!"
|
|
|
|
this.chatTitle="连接成功!"
|
|
|
|
// let mes = {}
|
|
|
|
// let mes = {}
|
|
|
|
// mes.type = "userInit";
|
|
|
|
// mes.type = "userInit";
|
|
|
@ -37,7 +37,7 @@ new Vue({
|
|
|
|
// mes.data = this.visitor;
|
|
|
|
// mes.data = this.visitor;
|
|
|
|
// this.socket.send(JSON.stringify(mes));
|
|
|
|
// this.socket.send(JSON.stringify(mes));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OnMessage(e) {
|
|
|
|
OnMessage:function(e) {
|
|
|
|
const redata = JSON.parse(e.data);
|
|
|
|
const redata = JSON.parse(e.data);
|
|
|
|
if (redata.type == "kfOnline") {
|
|
|
|
if (redata.type == "kfOnline") {
|
|
|
|
let msg = redata.data
|
|
|
|
let msg = redata.data
|
|
|
@ -84,10 +84,10 @@ new Vue({
|
|
|
|
this.socket.close();
|
|
|
|
this.socket.close();
|
|
|
|
this.socketClosed=true;
|
|
|
|
this.socketClosed=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window.parent.postMessage(redata);
|
|
|
|
//window.parent.postMessage(redata);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//发送给客户
|
|
|
|
//发送给客户
|
|
|
|
chatToUser() {
|
|
|
|
chatToUser:function() {
|
|
|
|
this.messageContent=this.messageContent.trim("\r\n");
|
|
|
|
this.messageContent=this.messageContent.trim("\r\n");
|
|
|
|
if(this.messageContent==""||this.messageContent=="\r\n"){
|
|
|
|
if(this.messageContent==""||this.messageContent=="\r\n"){
|
|
|
|
this.$message({
|
|
|
|
this.$message({
|
|
|
@ -136,12 +136,12 @@ new Vue({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OnClose() {
|
|
|
|
OnClose:function() {
|
|
|
|
this.chatTitle="连接关闭!请重新打开页面";
|
|
|
|
this.chatTitle="连接关闭!请重新打开页面";
|
|
|
|
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
|
|
|
|
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//获取当前用户信息
|
|
|
|
//获取当前用户信息
|
|
|
|
getUserInfo(){
|
|
|
|
getUserInfo:function(){
|
|
|
|
let obj=this.getCache("visitor");
|
|
|
|
let obj=this.getCache("visitor");
|
|
|
|
var visitor_id=""
|
|
|
|
var visitor_id=""
|
|
|
|
if(obj){
|
|
|
|
if(obj){
|
|
|
@ -168,7 +168,7 @@ new Vue({
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//获取信息列表
|
|
|
|
//获取信息列表
|
|
|
|
getMesssagesByVisitorId(){
|
|
|
|
getMesssagesByVisitorId:function(){
|
|
|
|
let _this=this;
|
|
|
|
let _this=this;
|
|
|
|
$.ajax({
|
|
|
|
$.ajax({
|
|
|
|
type:"get",
|
|
|
|
type:"get",
|
|
|
@ -194,7 +194,7 @@ new Vue({
|
|
|
|
_this.msgList.push(content);
|
|
|
|
_this.msgList.push(content);
|
|
|
|
_this.scrollBottom();
|
|
|
|
_this.scrollBottom();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_this.$nextTick(() => {
|
|
|
|
_this.$nextTick(function(){
|
|
|
|
$(".chatBox").append("<div class=\"chatTime\">—— 以上是历史消息 ——</div>");
|
|
|
|
$(".chatBox").append("<div class=\"chatTime\">—— 以上是历史消息 ——</div>");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -209,7 +209,7 @@ new Vue({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//滚动到底部
|
|
|
|
//滚动到底部
|
|
|
|
scrollBottom:function(){
|
|
|
|
scrollBottom:function(){
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$nextTick(function(){
|
|
|
|
//debugger;
|
|
|
|
//debugger;
|
|
|
|
$('body').scrollTop($("body")[0].scrollHeight);
|
|
|
|
$('body').scrollTop($("body")[0].scrollHeight);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -242,10 +242,14 @@ new Vue({
|
|
|
|
var i=0;
|
|
|
|
var i=0;
|
|
|
|
if(len>0){
|
|
|
|
if(len>0){
|
|
|
|
_this.timer=setInterval(function(){
|
|
|
|
_this.timer=setInterval(function(){
|
|
|
|
if(i>=len){
|
|
|
|
if(i>=len||typeof msg[i]=="undefined"||msg[i]==null){
|
|
|
|
clearInterval(_this.timer);
|
|
|
|
clearInterval(_this.timer);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let content = msg[i];
|
|
|
|
let content = msg[i];
|
|
|
|
|
|
|
|
if(typeof content.content =="undefined"){
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
content.content = replaceContent(content.content);
|
|
|
|
content.content = replaceContent(content.content);
|
|
|
|
_this.msgList.push(content);
|
|
|
|
_this.msgList.push(content);
|
|
|
|
_this.scrollBottom();
|
|
|
|
_this.scrollBottom();
|
|
|
@ -259,7 +263,7 @@ new Vue({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
initCss(){
|
|
|
|
initCss:function(){
|
|
|
|
var _this=this;
|
|
|
|
var _this=this;
|
|
|
|
$(function () {
|
|
|
|
$(function () {
|
|
|
|
//$(".chatContext").css("max-height",$(window).height());
|
|
|
|
//$(".chatContext").css("max-height",$(window).height());
|
|
|
@ -283,7 +287,7 @@ new Vue({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//心跳
|
|
|
|
//心跳
|
|
|
|
ping(){
|
|
|
|
ping:function(){
|
|
|
|
let _this=this;
|
|
|
|
let _this=this;
|
|
|
|
let mes = {}
|
|
|
|
let mes = {}
|
|
|
|
mes.type = "ping";
|
|
|
|
mes.type = "ping";
|
|
|
@ -295,7 +299,7 @@ new Vue({
|
|
|
|
},10000);
|
|
|
|
},10000);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//初始化
|
|
|
|
//初始化
|
|
|
|
init(){
|
|
|
|
init:function(){
|
|
|
|
this.initCss();
|
|
|
|
this.initCss();
|
|
|
|
$("#app").click(function(){
|
|
|
|
$("#app").click(function(){
|
|
|
|
clearTimeout(titleTimer);
|
|
|
|
clearTimeout(titleTimer);
|
|
|
@ -309,12 +313,12 @@ new Vue({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//表情点击事件
|
|
|
|
//表情点击事件
|
|
|
|
faceIconClick(index){
|
|
|
|
faceIconClick:function(index){
|
|
|
|
$('.faceBox').hide();
|
|
|
|
$('.faceBox').hide();
|
|
|
|
this.messageContent+="face"+this.face[index].name;
|
|
|
|
this.messageContent+="face"+this.face[index].name;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//上传图片
|
|
|
|
//上传图片
|
|
|
|
uploadImg (url){
|
|
|
|
uploadImg:function (url){
|
|
|
|
let _this=this;
|
|
|
|
let _this=this;
|
|
|
|
$('#uploadImg').after('<input type="file" accept="image/gif,image/jpeg,image/jpg,image/png" id="uploadImgFile" name="file" style="display:none" >');
|
|
|
|
$('#uploadImg').after('<input type="file" accept="image/gif,image/jpeg,image/jpg,image/png" id="uploadImgFile" name="file" style="display:none" >');
|
|
|
|
$("#uploadImgFile").click();
|
|
|
|
$("#uploadImgFile").click();
|
|
|
@ -348,7 +352,7 @@ new Vue({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//上传文件
|
|
|
|
//上传文件
|
|
|
|
uploadFile (url){
|
|
|
|
uploadFile:function (url){
|
|
|
|
let _this=this;
|
|
|
|
let _this=this;
|
|
|
|
$('#uploadFile').after('<input type="file" id="uploadRealFile" name="file2" style="display:none" >');
|
|
|
|
$('#uploadFile').after('<input type="file" id="uploadRealFile" name="file2" style="display:none" >');
|
|
|
|
$("#uploadRealFile").click();
|
|
|
|
$("#uploadRealFile").click();
|
|
|
@ -384,7 +388,7 @@ new Vue({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//粘贴上传图片
|
|
|
|
//粘贴上传图片
|
|
|
|
onPasteUpload(event){
|
|
|
|
onPasteUpload:function(event){
|
|
|
|
let items = event.clipboardData && event.clipboardData.items;
|
|
|
|
let items = event.clipboardData && event.clipboardData.items;
|
|
|
|
let file = null
|
|
|
|
let file = null
|
|
|
|
if (items && items.length) {
|
|
|
|
if (items && items.length) {
|
|
|
@ -426,18 +430,28 @@ new Vue({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//提示音
|
|
|
|
//提示音
|
|
|
|
alertSound(){
|
|
|
|
alertSound:function(){
|
|
|
|
var b = document.getElementById("chatMessageAudio");
|
|
|
|
var b = document.getElementById("chatMessageAudio");
|
|
|
|
var p = b.play();
|
|
|
|
if (b.canPlayType('audio/mpeg;')) {
|
|
|
|
p && p.then(function(){}).catch(function(e){});
|
|
|
|
b.type= 'audio/mpeg';
|
|
|
|
|
|
|
|
b.src= '/static/images/alert2.ogg';
|
|
|
|
|
|
|
|
var p = b.play();
|
|
|
|
|
|
|
|
p && p.then(function () {
|
|
|
|
|
|
|
|
}).catch(function (e) {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sendSound(){
|
|
|
|
sendSound:function(){
|
|
|
|
var b = document.getElementById("chatMessageSendAudio");
|
|
|
|
var b = document.getElementById("chatMessageSendAudio");
|
|
|
|
var p = b.play();
|
|
|
|
if (b.canPlayType('audio/mpeg;')) {
|
|
|
|
p && p.then(function(){}).catch(function(e){});
|
|
|
|
b.type= 'audio/mpeg';
|
|
|
|
|
|
|
|
b.src= '/static/images/sent.ogg';
|
|
|
|
|
|
|
|
var p = b.play();
|
|
|
|
|
|
|
|
p && p.then(function(){}).catch(function(e){});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
mounted:function() {
|
|
|
|
document.addEventListener('paste', this.onPasteUpload)
|
|
|
|
document.addEventListener('paste', this.onPasteUpload)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
created: function () {
|
|
|
|
created: function () {
|
|
|
|