前端更兼容一点

pull/23/head
taoshihan1991 4 years ago
parent b7e82bf2c0
commit 652574f288

@ -131,6 +131,9 @@ server{
1. 需要先安装swag
2. 在根目录swag init -g go-fly.go
### 感谢赞助
2020年12月31日 **强 8.88元
2020年12月24日 **松 8.88元
2020年12月23日 **渊 10元

@ -66,10 +66,10 @@
</div>
<!--//客服代码-->
<audio id="chatMessageAudio">
<source id="chatMessageAudioSource" src="/static/images/alert2.ogg" type="audio/mpeg" />
<source id="chatMessageAudioSource" />
</audio>
<audio id="chatMessageSendAudio">
<source id="chatMessageSendAudioSource" src="/static/images/sent.ogg" type="audio/mpeg" />
<source id="chatMessageSendAudioSource" />
</audio>
</template>
</div>
@ -79,5 +79,5 @@
var KEFU_ID='{{.KEFU_ID}}';
var REFER='{{.Refer}}';
</script>
<script src="/static/js/chat-page.js?v=0.3.8"></script>
<script src="/static/js/chat-page.js?v=0.4.0"></script>
</html>

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

@ -0,0 +1,22 @@
package tools
import "testing"
func TestShowString(t *testing.T) {
ShowStringByte("hello,世界")
}
func TestReverse2(t *testing.T) {
cases := []struct {
in, want string
}{
{"Hello, world", "dlrow ,olleH"},
{"Hello, 世界", "界世 ,olleH"},
{"", ""},
}
for _, c := range cases {
got := Reverse2(c.in)
if got != c.want {
t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want)
}
}
}
Loading…
Cancel
Save