增加多语言

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

@ -53,7 +53,7 @@
<div class="clear"></div>
</div>
<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 class="footContact clear">
<a href="https://github.com/taoshihan1991/go-fly" target="_blank">GO-FLY1.0.0客服陶士涵提供技术支持</a>
@ -73,6 +73,8 @@
<script>
var KEFU_ID='{{.KEFU_ID}}';
var REFER='{{.Refer}}';
var LANG=checkLang();
</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>
</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:["<{","}>"],
data: {
window:window,
//server:getWsBaseUrl()+"/chat_server",
server:getWsBaseUrl()+"/ws_visitor",
socket:null,
msgList:[],
messageContent:"",
chatTitle:"正在连接...",
chatTitle:GOFLY_LANG[LANG]['connecting'],
visitor:{},
face:[],
showKfonline:false,
socketClosed:false,
timer:null,
sendDisabled:false,
flyLang:GOFLY_LANG[LANG],
},
methods: {
//初始化websocket
@ -30,12 +30,7 @@ new Vue({
this.ping();
},
OnOpen:function() {
this.chatTitle="连接成功!"
// let mes = {}
// mes.type = "userInit";
// this.visitor.refer=REFER;
// mes.data = this.visitor;
// this.socket.send(JSON.stringify(mes));
this.chatTitle=GOFLY_LANG[LANG]['connectok'];
},
OnMessage:function(e) {
const redata = JSON.parse(e.data);
@ -45,7 +40,7 @@ new Vue({
return;
}
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>");
this.scrollBottom();
this.showKfonline=true;
@ -91,14 +86,12 @@ new Vue({
},
//发送给客户
chatToUser:function() {
this.messageContent=this.messageContent.trim("\r\n");
if(this.messageContent==""||this.messageContent=="\r\n"){
this.$message({
message: '不能发送空白信息',
type: 'warning'
});
var messageContent=this.messageContent.trim("\r\n");
if(messageContent==""||messageContent=="\r\n"){
this.messageContent="";
return;
}
this.messageContent=messageContent;
if(this.socketClosed){
this.$message({
message: '连接关闭!请重新打开页面',
@ -214,7 +207,7 @@ new Vue({
_this.scrollBottom();
}
_this.$nextTick(function(){
$(".chatBox").append("<div class=\"chatTime\">—— 以上是历史消息 ——</div>");
$(".chatBox").append("<div class=\"chatTime\">"+GOFLY_LANG[LANG]['historymes']+"</div>");
});
}
if(data.code!=200){

@ -96,11 +96,6 @@ function bigPic(src,isVisitor){
window.open(src);
return;
}
// $("#bigPic img").attr("src",src);
// $("#bigPic").show();
// $("#bigPic img").click(function(){
// $("#bigPic").hide();
// });
}
function filter (obj){
var imgType = ["image/jpeg","image/png","image/jpg","image/gif"];
@ -116,4 +111,26 @@ function filter (obj){
function sleep(time) {
var startTime = new Date().getTime() + parseInt(time, 10);
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