增加多语言

pull/23/head
taoshihan1991 4 years ago
parent d04cf67040
commit 8c981daf68

@ -53,7 +53,7 @@
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="btnArea"> <div class="btnArea">
<el-button :disabled="sendDisabled" type="primary" class="chatBoxSendBtn" size="small" v-on:click="chatToUser">{{.SendBtn}}</el-button> <el-button :disabled="sendDisabled||messageContent==''" type="primary" class="chatBoxSendBtn" size="small" v-on:click="chatToUser"><{flyLang.sent}></el-button>
</div> </div>
<div class="footContact clear"> <div class="footContact clear">
<a href="https://github.com/taoshihan1991/go-fly" target="_blank">GO-FLY1.0.0客服陶士涵提供技术支持</a> <a href="https://github.com/taoshihan1991/go-fly" target="_blank">GO-FLY1.0.0客服陶士涵提供技术支持</a>
@ -73,6 +73,8 @@
<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="/static/js/chat-lang.js?v=1.0.0"></script>
<script src="/static/js/chat-page.js?v=1.0.0"></script> <script src="/static/js/chat-page.js?v=1.0.0"></script>
</html> </html>

@ -0,0 +1,16 @@
var GOFLY_LANG={
"cn":{
"sent":"发送",
"connecting":"正在连接...",
"connectok":"连接成功!",
"chating":"正在与您沟通!",
"historymes":"—— 以上是历史消息 ——",
},
"en":{
"sent":"sent",
"connecting":"connecting...",
"connectok":"connection succeeded!",
"chating":"chating with you!",
"historymes":"—— above is old messages ——",
},
};

@ -4,18 +4,18 @@ new Vue({
delimiters:["<{","}>"], delimiters:["<{","}>"],
data: { data: {
window:window, window:window,
//server:getWsBaseUrl()+"/chat_server",
server:getWsBaseUrl()+"/ws_visitor", server:getWsBaseUrl()+"/ws_visitor",
socket:null, socket:null,
msgList:[], msgList:[],
messageContent:"", messageContent:"",
chatTitle:"正在连接...", chatTitle:GOFLY_LANG[LANG]['connecting'],
visitor:{}, visitor:{},
face:[], face:[],
showKfonline:false, showKfonline:false,
socketClosed:false, socketClosed:false,
timer:null, timer:null,
sendDisabled:false, sendDisabled:false,
flyLang:GOFLY_LANG[LANG],
}, },
methods: { methods: {
//初始化websocket //初始化websocket
@ -30,12 +30,7 @@ new Vue({
this.ping(); this.ping();
}, },
OnOpen:function() { OnOpen:function() {
this.chatTitle="连接成功!" this.chatTitle=GOFLY_LANG[LANG]['connectok'];
// let mes = {}
// mes.type = "userInit";
// this.visitor.refer=REFER;
// mes.data = this.visitor;
// this.socket.send(JSON.stringify(mes));
}, },
OnMessage:function(e) { OnMessage:function(e) {
const redata = JSON.parse(e.data); const redata = JSON.parse(e.data);
@ -45,7 +40,7 @@ new Vue({
return; return;
} }
this.visitor.to_id=msg.id; this.visitor.to_id=msg.id;
this.chatTitle=msg.name+",正在与您沟通!" this.chatTitle=msg.name+","+GOFLY_LANG[LANG]['chating'];
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>"); $(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
this.scrollBottom(); this.scrollBottom();
this.showKfonline=true; this.showKfonline=true;
@ -91,14 +86,12 @@ new Vue({
}, },
//发送给客户 //发送给客户
chatToUser:function() { chatToUser:function() {
this.messageContent=this.messageContent.trim("\r\n"); var messageContent=this.messageContent.trim("\r\n");
if(this.messageContent==""||this.messageContent=="\r\n"){ if(messageContent==""||messageContent=="\r\n"){
this.$message({ this.messageContent="";
message: '不能发送空白信息',
type: 'warning'
});
return; return;
} }
this.messageContent=messageContent;
if(this.socketClosed){ if(this.socketClosed){
this.$message({ this.$message({
message: '连接关闭!请重新打开页面', message: '连接关闭!请重新打开页面',
@ -214,7 +207,7 @@ new Vue({
_this.scrollBottom(); _this.scrollBottom();
} }
_this.$nextTick(function(){ _this.$nextTick(function(){
$(".chatBox").append("<div class=\"chatTime\">—— 以上是历史消息 ——</div>"); $(".chatBox").append("<div class=\"chatTime\">"+GOFLY_LANG[LANG]['historymes']+"</div>");
}); });
} }
if(data.code!=200){ if(data.code!=200){

@ -96,11 +96,6 @@ function bigPic(src,isVisitor){
window.open(src); window.open(src);
return; return;
} }
// $("#bigPic img").attr("src",src);
// $("#bigPic").show();
// $("#bigPic img").click(function(){
// $("#bigPic").hide();
// });
} }
function filter (obj){ function filter (obj){
var imgType = ["image/jpeg","image/png","image/jpg","image/gif"]; var imgType = ["image/jpeg","image/png","image/jpg","image/gif"];
@ -116,4 +111,26 @@ function filter (obj){
function sleep(time) { function sleep(time) {
var startTime = new Date().getTime() + parseInt(time, 10); var startTime = new Date().getTime() + parseInt(time, 10);
while(new Date().getTime() < startTime) {} while(new Date().getTime() < startTime) {}
}; }
function checkLang(){
var langs=["cn","en"];
var lang=getQuery("lang");
if(lang!=""&&langs.indexOf(lang) > 0 ){
return lang;
}
return "cn";
}
function getQuery(key) {
var query = window.location.search.substring(1);
var key_values = query.split("&");
var params = {};
key_values.map(function (key_val){
var key_val_arr = key_val.split("=");
params[key_val_arr[0]] = key_val_arr[1];
});
if(typeof params[key]!="undefined"){
return params[key];
}
return "";
}
;
Loading…
Cancel
Save