master
taoshihan 2 months ago
parent e98db6fe24
commit 8406ba74c5

@ -13,7 +13,7 @@ CREATE TABLE `user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
TRUNCATE TABLE `user`; TRUNCATE TABLE `user`;
INSERT INTO `user` (`id`, `name`, `password`, `nickname`, `created_at`, `updated_at`, `deleted_at`, `avator`) VALUE INSERT INTO `user` (`id`, `name`, `password`, `nickname`, `created_at`, `updated_at`, `deleted_at`, `avator`) VALUE
(1, 'kefu2', '202cb962ac59075b964b07152d234b70', 'Open Source LiveChat Software', '2020-06-27 19:32:41', '2020-07-04 09:32:20', NULL, '/static/images/4.jpg'); (1, 'kefu2', '202cb962ac59075b964b07152d234b70', 'Open Source LiveChat Support', '2020-06-27 19:32:41', '2020-07-04 09:32:20', NULL, '/static/images/4.jpg');
DROP TABLE IF EXISTS `visitor`; DROP TABLE IF EXISTS `visitor`;
CREATE TABLE `visitor` ( CREATE TABLE `visitor` (
@ -72,7 +72,7 @@ CREATE TABLE `role` (
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `role` (`id`, `name`, `method`, `path`) VALUES INSERT INTO `role` (`id`, `name`, `method`, `path`) VALUES
(1, '普通客服', '*', '*'); (1, 'Customer Support', '*', '*');
DROP TABLE IF EXISTS `welcome`; DROP TABLE IF EXISTS `welcome`;
CREATE TABLE `welcome` ( CREATE TABLE `welcome` (
@ -87,9 +87,9 @@ CREATE TABLE `welcome` (
KEY `keyword` (`keyword`) KEY `keyword` (`keyword`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `welcome` (`id`, `user_id`, `content`, `is_default`, `ctime`, `keyword`) VALUES INSERT INTO `welcome` (`id`, `user_id`, `content`, `is_default`, `ctime`, `keyword`) VALUES
(NULL, 'kefu2', '我暂时离线,留言已转发到我的邮箱,稍后回复~', 1, '2020-08-24 02:57:49','offline'); (NULL, 'kefu2', 'I am currently offline. Your message has been forwarded to my email and I will reply soon.', 1, '2020-08-24 02:57:49','offline');
INSERT INTO `welcome` (`id`, `user_id`, `content`, `is_default`, `ctime`, `keyword`) VALUES INSERT INTO `welcome` (`id`, `user_id`, `content`, `is_default`, `ctime`, `keyword`) VALUES
(NULL, 'kefu2', '请问有什么可以帮您?', 0, '2020-08-24 02:57:49','welcome'); (NULL, 'kefu2', 'How may I help you today?', 0, '2020-08-24 02:57:49','welcome');
DROP TABLE IF EXISTS `ipblack`; DROP TABLE IF EXISTS `ipblack`;
CREATE TABLE `ipblack` ( CREATE TABLE `ipblack` (
@ -110,29 +110,32 @@ CREATE TABLE `config` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `conf_key` (`conf_key`) UNIQUE KEY `conf_key` (`conf_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '公告信息', 'AllNotice', '开源智能客服系统为您服务'); INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '离线消息', 'OfflineMessage', '我现在离线,稍后回复您!'); (NULL, 'Announcement', 'AllNotice', 'Open source customer support system at your service');
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '欢迎消息', 'WelcomeMessage', '有什么可以帮您?'); INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '邮箱地址(SMTP地址)', 'NoticeEmailSmtp', ''); (NULL, 'Offline Message', 'OfflineMessage', 'I am currently offline and will reply to you later!');
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '邮箱账户', 'NoticeEmailAddress', ''); INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES (NULL, '邮箱密码(SMTP密码)', 'NoticeEmailPassword', ''); (NULL, 'Welcome Message', 'WelcomeMessage', 'How may I help you?');
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES
(NULL, 'Email Address (SMTP)', 'NoticeEmailSmtp', '');
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES
(NULL, 'Email Account', 'NoticeEmailAddress', '');
INSERT INTO `config` (`id`, `conf_name`, `conf_key`, `conf_value`) VALUES
(NULL, 'Email Password (SMTP)', 'NoticeEmailPassword', '');
DROP TABLE IF EXISTS `about`; DROP TABLE IF EXISTS `about`;
CREATE TABLE `about` ( CREATE TABLE `about` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title_cn` varchar(255) NOT NULL DEFAULT '',
`title_en` varchar(255) NOT NULL DEFAULT '', `title_en` varchar(255) NOT NULL DEFAULT '',
`keywords_cn` varchar(255) NOT NULL DEFAULT '',
`keywords_en` varchar(255) NOT NULL DEFAULT '', `keywords_en` varchar(255) NOT NULL DEFAULT '',
`desc_cn` varchar(1024) NOT NULL DEFAULT '',
`desc_en` varchar(1024) NOT NULL DEFAULT '', `desc_en` varchar(1024) NOT NULL DEFAULT '',
`css_js` text NOT NULL, `css_js` text NOT NULL,
`html_cn` text NOT NULL,
`html_en` text NOT NULL, `html_en` text NOT NULL,
`page` varchar(50) NOT NULL DEFAULT '', `page` varchar(50) NOT NULL DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `page` (`page`) UNIQUE KEY `page` (`page`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `reply_group`; DROP TABLE IF EXISTS `reply_group`;
CREATE TABLE `reply_group` ( CREATE TABLE `reply_group` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
@ -141,7 +144,9 @@ CREATE TABLE `reply_group` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `user_id` (`user_id`) KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `reply_group` (`id`, `group_name`, `user_id`) VALUES (NULL, '常见问题', 'kefu2'); INSERT INTO `reply_group` (`id`, `group_name`, `user_id`) VALUES
(NULL, 'Frequently Asked Questions', 'kefu2');
DROP TABLE IF EXISTS `reply_item`; DROP TABLE IF EXISTS `reply_item`;
CREATE TABLE `reply_item` ( CREATE TABLE `reply_item` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
@ -153,7 +158,7 @@ CREATE TABLE `reply_item` (
KEY `user_id` (`user_id`), KEY `user_id` (`user_id`),
KEY `group_id` (`group_id`) KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `reply_item` (`id`, `content`, `group_id`, `user_id`, `item_name`) VALUES (NULL, '在这里[官网]link[https://gofly.sopans.com]!','1','kefu2', '官方地址在哪?');
DROP TABLE IF EXISTS `land_page`; DROP TABLE IF EXISTS `land_page`;
CREATE TABLE `land_page` ( CREATE TABLE `land_page` (
`id` int(11) NOT NULL, `id` int(11) NOT NULL,
@ -164,16 +169,22 @@ CREATE TABLE `land_page` (
`page_id` varchar(50) NOT NULL DEFAULT '', `page_id` varchar(50) NOT NULL DEFAULT '',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
DROP TABLE IF EXISTS `language`; DROP TABLE IF EXISTS `language`;
CREATE TABLE `language` ( CREATE TABLE `language` (
`id` int(11) NOT NULL, `id` int(11) NOT NULL,
`country` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '', `country` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`short_key` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' `short_key` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (1, '中文简体', 'zh-cn'); INSERT INTO `language` (`id`, `country`, `short_key`) VALUES
INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (2, '正體中文', 'zh-tw'); (1, 'Simplified Chinese', 'zh-cn');
INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (3, 'English', 'en_us'); INSERT INTO `language` (`id`, `country`, `short_key`) VALUES
INSERT INTO `language` (`id`, `country`, `short_key`) VALUES (4, '日本語', 'ja_jp'); (2, 'Traditional Chinese', 'zh-tw');
INSERT INTO `language` (`id`, `country`, `short_key`) VALUES
(3, 'English', 'en-us');
INSERT INTO `language` (`id`, `country`, `short_key`) VALUES
(4, 'Japanese', 'ja-jp');
DROP TABLE IF EXISTS `user_client`; DROP TABLE IF EXISTS `user_client`;
CREATE TABLE `user_client` ( CREATE TABLE `user_client` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,

@ -1,16 +1,15 @@
<html lang="cn"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" /> <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta name="keywords" content="Golang Open Source LiveChat Software"/> <meta name="keywords" content="Golang Open Source LiveChat Software"/>
<meta name="description" content="Golang Open Source LiveChat Software"/> <meta name="description" content="Golang Open Source LiveChat Software"/>
<title>Golang Open Source LiveChat Software</title> <title>Live Chat Support</title>
<link rel="stylesheet" href="/static/cdn/element-ui/2.15.1/theme-chalk/index.min.css"> <link rel="stylesheet" href="/static/cdn/element-ui/2.15.1/theme-chalk/index.min.css">
<script src="/static/cdn/vue/2.6.11/vue.min.js"></script> <script src="/static/cdn/vue/2.6.11/vue.min.js"></script>
<script src="/static/cdn/element-ui/2.15.1/index.js"></script> <script src="/static/cdn/element-ui/2.15.1/index.js"></script>
<script src="/static/cdn/jquery/3.6.0/jquery.min.js"></script> <script src="/static/cdn/jquery/3.6.0/jquery.min.js"></script>
<script src="/assets/js/functions.js?v=fgffdwersdccvcbv"></script> <script src="/assets/js/functions.js?v=fgffdwersdccvcbv"></script>
<script src="/assets/js/reconnecting-websocket.min.js"></script> <script src="/assets/js/reconnecting-websocket.min.js"></script>
<link rel="stylesheet" href="/static/css/common.css?v=sdsderfrgfgdfdf" /> <link rel="stylesheet" href="/static/css/common.css?v=sdsderfrgfgdfdf" />
@ -20,20 +19,20 @@
<body class="visitorBody"> <body class="visitorBody">
<div id="app" class="chatCenter"> <div id="app" class="chatCenter">
<template> <template>
<!--客服代码--> <!--Customer Service Code-->
<div class="chatEntTitle" v-show="!isIframe"> <div class="chatEntTitle" v-show="!isIframe">
<el-badge type="success" is-dot class="item"> <el-badge type="success" is-dot class="item">
<el-avatar class="chatEntTitleLogo" :size="35" :src="kefuInfo.avatar"></el-avatar> <el-avatar class="chatEntTitleLogo" :size="35" :src="kefuInfo.avatar"></el-avatar>
</el-badge> </el-badge>
<div> <div>
<div><{kefuInfo.nickname}></div> <div>Live Chat Support</div>
</div> </div>
</div> </div>
<div class="chatEntBox"> <div class="chatEntBox">
<div class="chatContext chatVisitorPage"> <div class="chatContext chatVisitorPage">
<div class="chatBox"> <div class="chatBox">
<div class="chatNotice" v-on:click="getHistoryMessage" v-show="showLoadMore"> <div class="chatNotice" v-on:click="getHistoryMessage" v-show="showLoadMore">
<a href="javascript:;" class="chatNoticeContent" style="color: #07a9fe;">点击加载更多记录</a> <a href="javascript:;" class="chatNoticeContent" style="color: #07a9fe;">Load more messages</a>
</div> </div>
<el-row :gutter="2" v-for="v in msgList" v-bind:class="{'chatBoxMe': v.is_kefu==false}"> <el-row :gutter="2" v-for="v in msgList" v-bind:class="{'chatBoxMe': v.is_kefu==false}">
<div class="chatTime" v-bind:class="{'chatTimeHide': v.show_time==false}"><span><{v.time}></span></div> <div class="chatTime" v-bind:class="{'chatTimeHide': v.show_time==false}"><span><{v.time}></span></div>
@ -52,20 +51,19 @@
</div> </div>
</div> </div>
<div class="chatBoxSend"> <div class="chatBoxSend">
<div class="visitorIconBox"> <div class="visitorIconBox">
<el-tooltip content="发送表情" placement="top"> <el-tooltip content="Send emoji" placement="top">
<div class="iconBtn iconfont icon-xiaolian" style="margin-left:10px;font-size: 24px;cursor: pointer;" @click.stop="showFaceIcon==true?showFaceIcon=false:showFaceIcon=true"></div> <div class="iconBtn iconfont icon-xiaolian" style="margin-left:10px;font-size: 24px;cursor: pointer;" @click.stop="showFaceIcon==true?showFaceIcon=false:showFaceIcon=true"></div>
</el-tooltip> </el-tooltip>
<el-tooltip content="上传图片" placement="top"> <el-tooltip content="Upload image" placement="top">
<div class="iconBtn el-icon-picture" id="uploadImg" v-on:click="uploadImg('/uploadimg')" style="font-size: 24px;"></div> <div class="iconBtn el-icon-picture" id="uploadImg" v-on:click="uploadImg('/uploadimg')" style="font-size: 24px;"></div>
</el-tooltip> </el-tooltip>
<el-tooltip content="上传附件" placement="top"> <el-tooltip content="Upload file" placement="top">
<div class="iconBtn el-icon-upload" id="uploadFile" v-on:click="uploadFile('/uploadfile')" style="font-size: 26px;"></div> <div class="iconBtn el-icon-upload" id="uploadFile" v-on:click="uploadFile('/uploadfile')" style="font-size: 26px;"></div>
</el-tooltip> </el-tooltip>
<div style="display: none" :title="flyLang.emotions" class="icono-smile visitorIconBtns visitorFaceBtn"></div> <div style="display: none" title="Emoji" class="icono-smile visitorIconBtns visitorFaceBtn"></div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
@ -77,30 +75,23 @@
</div> </div>
<el-input show-word-limit maxlength="100" :rows="2" type="textarea" resize="none" class="visitorEditorArea" @focus="scrollBottom;showIconBtns=false" @blur="scrollBottom;showIconBtns=false" v-model="messageContent" v-on:keyup.enter.native="chatToUser"> <el-input show-word-limit maxlength="100" :rows="2" type="textarea" resize="none" class="visitorEditorArea" @focus="scrollBottom;showIconBtns=false" @blur="scrollBottom;showIconBtns=false" v-model="messageContent" v-on:keyup.enter.native="chatToUser">
</el-input> </el-input>
<el-button type="primary" size="mini" class="visitorEditorBtn" :disabled="sendDisabled||messageContent==''" v-on:click="chatToUser();showIconBtns=false"><{flyLang.sent}></el-button> <el-button type="primary" size="mini" class="visitorEditorBtn" :disabled="sendDisabled||messageContent==''" v-on:click="chatToUser();showIconBtns=false">Send</el-button>
</div> </div>
</div> </div>
<div class="chatArticle"> <div class="chatArticle">
<h3 class="hotQuestionTitle">公告通知 <h3 class="hotQuestionTitle">Announcements</h3>
</h3>
<div class="allNotice" v-html><{kefuInfo.allNotice}></div> <div class="allNotice" v-html><{kefuInfo.allNotice}></div>
</div> </div>
<audio id="chatMessageAudio"></audio>
<!--//客服代码--> <audio id="chatMessageSendAudio"></audio>
<audio id="chatMessageAudio">
</audio>
<audio id="chatMessageSendAudio">
</audio>
</template> </template>
</div> </div>
</body> </body>
<script> <script>
var KEFU_ID='{{.KEFU_ID}}'; var KEFU_ID='{{.KEFU_ID}}';
var REFER='{{.Refer}}'; var REFER='{{.Refer}}';
var LANG=checkLang();
</script> </script>
<script src="/assets/js/chat-lang.js?v=0.3.7"></script>
<script> <script>
KEFU_ID=KEFU_ID!=""? KEFU_ID:"kefu2"; KEFU_ID=KEFU_ID!=""? KEFU_ID:"kefu2";
new Vue({ new Vue({
@ -113,7 +104,7 @@
msgList:[], msgList:[],
msgListNum:[], msgListNum:[],
messageContent:"", messageContent:"",
chatTitle:GOFLY_LANG[LANG]['connecting'], chatTitle:"Connecting...",
visitor:{}, visitor:{},
face:[], face:[],
showKfonline:false, showKfonline:false,
@ -121,7 +112,6 @@
focusSendConn:false, focusSendConn:false,
timer:null, timer:null,
sendDisabled:false, sendDisabled:false,
flyLang:GOFLY_LANG[LANG],
showIconBtns:false, showIconBtns:false,
showFaceIcon:false, showFaceIcon:false,
isIframe:false, isIframe:false,
@ -134,19 +124,16 @@
}, },
}, },
methods: { methods: {
//初始化websocket
initConn:function() { 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);
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;
this.socket.onclose = this.OnClose; this.socket.onclose = this.OnClose;
//心跳
this.ping(); this.ping();
}, },
OnOpen:function() { OnOpen:function() {
console.log("ws:onopen"); console.log("ws:onopen");
//获取欢迎
this.getNotice(); this.getNotice();
this.socketClosed=false; this.socketClosed=false;
this.focusSendConn=false; this.focusSendConn=false;
@ -162,7 +149,7 @@
return; return;
} }
this.visitor.to_id=msg.id; this.visitor.to_id=msg.id;
this.showTitle(msg.name+","+GOFLY_LANG[LANG]['chating']); this.showTitle(msg.name+", is chatting with you");
this.scrollBottom(); this.scrollBottom();
this.showKfonline=true; this.showKfonline=true;
} }
@ -202,27 +189,26 @@
notification.close(); notification.close();
}); });
this.scrollBottom(); this.scrollBottom();
flashTitle();//标题闪烁 flashTitle();
clearInterval(this.timer); clearInterval(this.timer);
this.alertSound();//提示音 this.alertSound();
} }
if (redata.type == "close") { if (redata.type == "close") {
this.chatTitle=GOFLY_LANG[LANG]['closemes']; this.chatTitle="The conversation has ended";
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>"); $(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
this.scrollBottom(); this.scrollBottom();
this.socket.close(); this.socket.close();
//this.socketClosed=true;
this.focusSendConn=true; this.focusSendConn=true;
} }
if (redata.type == "force_close") { if (redata.type == "force_close") {
this.chatTitle=GOFLY_LANG[LANG]['forceclosemes']; this.chatTitle="The conversation was terminated by the agent";
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>"); $(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
this.scrollBottom(); this.scrollBottom();
this.socket.close(); this.socket.close();
this.socketClosed=true; this.socketClosed=true;
} }
if (redata.type == "auto_close") { if (redata.type == "auto_close") {
this.chatTitle=GOFLY_LANG[LANG]['autoclosemes']; this.chatTitle="The conversation timed out due to inactivity";
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>"); $(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
this.scrollBottom(); this.scrollBottom();
this.socket.close(); this.socket.close();
@ -230,7 +216,6 @@
} }
window.parent.postMessage(redata,"*"); window.parent.postMessage(redata,"*");
}, },
//发送给客户
chatToUser:function() { chatToUser:function() {
var messageContent=this.messageContent.trim("\r\n"); var messageContent=this.messageContent.trim("\r\n");
messageContent=messageContent.replace("\n",""); messageContent=messageContent.replace("\n","");
@ -242,7 +227,7 @@
this.messageContent=messageContent; this.messageContent=messageContent;
if(this.socketClosed){ if(this.socketClosed){
this.$message({ this.$message({
message: '连接关闭!请重新打开页面', message: 'Connection closed! Please refresh the page',
type: 'warning' type: 'warning'
}); });
return; return;
@ -266,7 +251,6 @@
mes.from_id = this.visitor.visitor_id; mes.from_id = this.visitor.visitor_id;
mes.to_id = this.visitor.to_id; mes.to_id = this.visitor.to_id;
mes.content = this.messageContent; mes.content = this.messageContent;
//发送消息
$.post("/2/message",mes,function(res){ $.post("/2/message",mes,function(res){
_this.sendDisabled=false; _this.sendDisabled=false;
if(res.code!=200){ if(res.code!=200){
@ -286,23 +270,16 @@
OnClose:function() { OnClose:function() {
console.log("ws:onclose"); console.log("ws:onclose");
this.focusSendConn=true; this.focusSendConn=true;
//this.socketClosed=true;
// this.chatTitle="连接关闭!请重新打开页面";
// $(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
// this.scrollBottom();
}, },
//获取当前用户信息
getUserInfo:function(){ getUserInfo:function(){
let obj=this.getCache("visitor"); let obj=this.getCache("visitor_"+KEFU_ID);
var visitor_id="" var visitor_id=""
var to_id=KEFU_ID; var to_id=KEFU_ID;
if(obj){ if(obj){
visitor_id=obj.visitor_id; visitor_id=obj.visitor_id;
//to_id=obj.to_id;
} }
let _this=this; let _this=this;
var extra=getQuery("extra"); var extra=getQuery("extra");
//发送消息
$.post("/visitor_login",{visitor_id:visitor_id,refer:REFER,to_id:to_id,extra:extra},function(res){ $.post("/visitor_login",{visitor_id:visitor_id,refer:REFER,to_id:to_id,extra:extra},function(res){
if(res.code!=200){ if(res.code!=200){
_this.$message({ _this.$message({
@ -314,16 +291,10 @@
} }
_this.visitor=res.result; _this.visitor=res.result;
_this.getHistoryMessage(); _this.getHistoryMessage();
_this.setCache("visitor",res.result); _this.setCache("visitor_"+KEFU_ID,res.result);
//_this.getMesssagesByVisitorId();
_this.initConn(); _this.initConn();
}); });
// }else{
// this.visitor=obj;
// this.initConn();
// }
}, },
//获取信息列表
getHistoryMessage:function(){ getHistoryMessage:function(){
let params={ let params={
page:this.messages.page, page:this.messages.page,
@ -359,20 +330,17 @@
_this.messages.page++; _this.messages.page++;
}); });
}, },
//滚动到底部
scrollBottom:function(){ scrollBottom:function(){
var _this=this; var _this=this;
this.$nextTick(function(){ this.$nextTick(function(){
$('.chatVisitorPage').scrollTop($(".chatVisitorPage")[0].scrollHeight); $('.chatVisitorPage').scrollTop($(".chatVisitorPage")[0].scrollHeight);
}); });
}, },
//获取日期 getNowDate : function() {
getNowDate : function() {// 获取日期
var d = new Date(new Date()); var d = new Date(new Date());
return d.getFullYear() + '-' + this.digit(d.getMonth() + 1) + '-' + this.digit(d.getDate()) return d.getFullYear() + '-' + this.digit(d.getMonth() + 1) + '-' + this.digit(d.getDate())
+ ' ' + this.digit(d.getHours()) + ':' + this.digit(d.getMinutes()) + ':' + this.digit(d.getSeconds()); + ' ' + this.digit(d.getHours()) + ':' + this.digit(d.getMinutes()) + ':' + this.digit(d.getSeconds());
}, },
//补齐数位
digit : function (num) { digit : function (num) {
return num < 10 ? '0' + (num | 0) : num; return num < 10 ? '0' + (num | 0) : num;
}, },
@ -380,19 +348,19 @@
if(navigator.cookieEnabled&&typeof window.localStorage !== 'undefined'){ if(navigator.cookieEnabled&&typeof window.localStorage !== 'undefined'){
localStorage.setItem(key, JSON.stringify(obj)); localStorage.setItem(key, JSON.stringify(obj));
} }
},getCache : function (key){ },
getCache : function (key){
if(navigator.cookieEnabled&&typeof window.localStorage !== 'undefined') { if(navigator.cookieEnabled&&typeof window.localStorage !== 'undefined') {
return JSON.parse(localStorage.getItem(key)); return JSON.parse(localStorage.getItem(key));
} }
}, },
//获取自动欢迎语句
getNotice : function (){ getNotice : function (){
let _this=this; let _this=this;
$.get("/notice?kefu_id="+KEFU_ID,function(res) { $.get("/notice?kefu_id="+KEFU_ID,function(res) {
var code=res.code; var code=res.code;
if(code!=200) return; if(code!=200) return;
_this.kefuInfo=res.result; _this.kefuInfo=res.result;
_this.showTitle(_this.kefuInfo.nickname+" 为您服务"); _this.showTitle(_this.kefuInfo.nickname+" is ready to help");
if(!_this.kefuInfo.welcome) return; if(!_this.kefuInfo.welcome) return;
var msg={ var msg={
content:replaceContent(_this.kefuInfo.welcome), content:replaceContent(_this.kefuInfo.welcome),
@ -409,31 +377,18 @@
initCss:function(){ initCss:function(){
var _this=this; var _this=this;
$(function () { $(function () {
//$(".chatContext").css("max-height",$(window).height());
// if (top.location != location){
// $(".chatContext").css("max-height",$(window).height()-65);
// }
//展示表情
var faces=placeFace(); var faces=placeFace();
$.each(faceTitles, function (index, item) { $.each(faceTitles, function (index, item) {
_this.face.push({"name":item,"path":faces[item]}); _this.face.push({"name":item,"path":faces[item]});
}); });
var windheight = $(window).height(); var windheight = $(window).height();
$(window).resize(function(){ $(window).resize(function(){
var docheight = $(window).height(); /*唤起键盘时当前窗口高度*/ var docheight = $(window).height();
//_this.scrollBottom();
$('body').scrollTop(99999999); $('body').scrollTop(99999999);
// if(docheight < windheight){ /**/
// $(".chatBoxSend").css("position","static");
// }else{
// $(".chatBoxSend").css("position","fixed");
// }
}); });
}); });
}, },
//心跳
ping:function(){ ping:function(){
let _this=this; let _this=this;
let mes = {} let mes = {}
@ -445,7 +400,6 @@
} }
},10000); },10000);
}, },
//初始化
init:function(){ init:function(){
var _this=this; var _this=this;
this.initCss(); this.initCss();
@ -455,7 +409,6 @@
$('.faceBox').hide(); $('.faceBox').hide();
}); });
window.onfocus = function () { window.onfocus = function () {
//_this.scrollBottom();
clearFlashTitle(); clearFlashTitle();
window.parent.postMessage({type:"focus"},"*"); window.parent.postMessage({type:"focus"},"*");
if(_this.socketClosed){ if(_this.socketClosed){
@ -467,14 +420,11 @@
_this.initConn(); _this.initConn();
_this.scrollBottom(); _this.scrollBottom();
} }
}, },
//表情点击事件
faceIconClick:function(index){ faceIconClick:function(index){
$('.faceBox').hide(); $('.faceBox').hide();
this.messageContent+="face"+this.face[index].name; this.messageContent+="face"+this.face[index].name;
}, },
//上传图片
uploadImg:function (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" >');
@ -482,7 +432,7 @@
$("#uploadImgFile").change(function (e) { $("#uploadImgFile").change(function (e) {
var formData = new FormData(); var formData = new FormData();
var file = $("#uploadImgFile")[0].files[0]; var file = $("#uploadImgFile")[0].files[0];
formData.append("imgfile",file); //传给后台的file的key值是可以自己定义的 formData.append("imgfile",file);
filter(file) && $.ajax({ filter(file) && $.ajax({
url: url || '', url: url || '',
type: "post", type: "post",
@ -508,7 +458,6 @@
}); });
}); });
}, },
//上传文件
uploadFile:function (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" >');
@ -516,7 +465,7 @@
$("#uploadRealFile").change(function (e) { $("#uploadRealFile").change(function (e) {
var formData = new FormData(); var formData = new FormData();
var file = $("#uploadRealFile")[0].files[0]; var file = $("#uploadRealFile")[0].files[0];
formData.append("realfile",file); //传给后台的file的key值是可以自己定义的 formData.append("realfile",file);
console.log(formData); console.log(formData);
$.ajax({ $.ajax({
url: url || '', url: url || '',
@ -527,7 +476,6 @@
dataType: 'JSON', dataType: 'JSON',
mimeType: "multipart/form-data", mimeType: "multipart/form-data",
success: function (res) { success: function (res) {
if(res.code!=200){ if(res.code!=200){
_this.$message({ _this.$message({
message: res.msg, message: res.msg,
@ -550,12 +498,10 @@
}); });
}); });
}, },
//粘贴上传图片
onPasteUpload:function(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) {
// 检索剪切板items
for (var i = 0; i < items.length; i++) { for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) { if (items[i].type.indexOf('image') !== -1) {
file = items[i].getAsFile() file = items[i].getAsFile()
@ -592,7 +538,6 @@
} }
}); });
}, },
//提示音
alertSound:function(){ alertSound:function(){
alertSound("chatMessageAudio",'/static/images/alert2.ogg'); alertSound("chatMessageAudio",'/static/images/alert2.ogg');
}, },
@ -641,13 +586,7 @@
created: function () { created: function () {
this.init(); this.init();
this.getUserInfo(); this.getUserInfo();
//加载历史记录
//this.msgList=this.getHistory();
//滚动底部
//this.scrollBottom();
} }
}) })
</script> </script>
</html> </html>
Loading…
Cancel
Save