客服在线聊天
This commit is contained in:
parent
658b715140
commit
b44fbd5b69
|
@ -79,6 +79,7 @@
|
|||
</template>
|
||||
<script>
|
||||
import * as websocketUtils from 'utils/websocketUtils.js';
|
||||
const maxReconnectMaxCn = 30;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
@ -142,6 +143,7 @@
|
|||
onlineEmoji:{"100.gif":"AbNQgA.gif","101.gif":"AbN3ut.gif","102.gif":"AbNM3d.gif","103.gif":"AbN8DP.gif","104.gif":"AbNljI.gif","105.gif":"AbNtUS.gif","106.gif":"AbNGHf.gif","107.gif":"AbNYE8.gif","108.gif":"AbNaCQ.gif","109.gif":"AbNN4g.gif","110.gif":"AbN0vn.gif","111.gif":"AbNd3j.gif","112.gif":"AbNsbV.gif","113.gif":"AbNwgs.gif","114.gif":"AbNrD0.gif","115.gif":"AbNDuq.gif","116.gif":"AbNg5F.gif","117.gif":"AbN6ET.gif","118.gif":"AbNcUU.gif","119.gif":"AbNRC4.gif","120.gif":"AbNhvR.gif","121.gif":"AbNf29.gif","122.gif":"AbNW8J.gif","123.gif":"AbNob6.gif","124.gif":"AbN5K1.gif","125.gif":"AbNHUO.gif","126.gif":"AbNIDx.gif","127.gif":"AbN7VK.gif","128.gif":"AbNb5D.gif","129.gif":"AbNX2d.gif","130.gif":"AbNLPe.gif","131.gif":"AbNjxA.gif","132.gif":"AbNO8H.gif","133.gif":"AbNxKI.gif","134.gif":"AbNzrt.gif","135.gif":"AbU9Vf.gif","136.gif":"AbUSqP.gif","137.gif":"AbUCa8.gif","138.gif":"AbUkGQ.gif","139.gif":"AbUFPg.gif","140.gif":"AbUPIS.gif","141.gif":"AbUZMn.gif","142.gif":"AbUExs.gif","143.gif":"AbUA2j.gif","144.gif":"AbUMIU.gif","145.gif":"AbUerq.gif","146.gif":"AbUKaT.gif","147.gif":"AbUmq0.gif","148.gif":"AbUuZV.gif","149.gif":"AbUliF.gif","150.gif":"AbU1G4.gif","151.gif":"AbU8z9.gif","152.gif":"AbU3RJ.gif","153.gif":"AbUYs1.gif","154.gif":"AbUJMR.gif","155.gif":"AbUadK.gif","156.gif":"AbUtqx.gif","157.gif":"AbUUZ6.gif","158.gif":"AbUBJe.gif","159.gif":"AbUdIO.gif","160.gif":"AbU0iD.gif","161.gif":"AbUrzd.gif","162.gif":"AbUDRH.gif","163.gif":"AbUyQA.gif","164.gif":"AbUWo8.gif","165.gif":"AbU6sI.gif","166.gif":"AbU2eP.gif","167.gif":"AbUcLt.gif","168.gif":"AbU4Jg.gif","169.gif":"AbURdf.gif","170.gif":"AbUhFS.gif","171.gif":"AbU5WQ.gif","172.gif":"AbULwV.gif","173.gif":"AbUIzj.gif","174.gif":"AbUTQs.gif","175.gif":"AbU7yn.gif","176.gif":"AbUqe0.gif","177.gif":"AbUHLq.gif","178.gif":"AbUOoT.gif","179.gif":"AbUvYF.gif","180.gif":"AbUjFU.gif","181.gif":"AbaSSJ.gif","182.gif":"AbUxW4.gif","183.gif":"AbaCO1.gif","184.gif":"Abapl9.gif","185.gif":"Aba9yR.gif","186.gif":"AbaFw6.gif","187.gif":"Abaiex.gif","188.gif":"AbakTK.gif","189.gif":"AbaZfe.png","190.gif":"AbaEFO.gif","191.gif":"AbaVYD.gif","192.gif":"AbamSH.gif","193.gif":"AbaKOI.gif","194.gif":"Abanld.gif","195.gif":"Abau6A.gif","196.gif":"AbaQmt.gif","197.gif":"Abal0P.gif","198.gif":"AbatpQ.gif","199.gif":"Aba1Tf.gif","200.png":"Aba8k8.png","201.png":"AbaGtS.png","202.png":"AbaJfg.png","203.png":"AbaNlj.png","204.png":"Abawmq.png","205.png":"AbaU6s.png","206.png":"AbaaXn.png","207.png":"Aba000.png","208.png":"AbarkT.png","209.png":"AbastU.png","210.png":"AbaB7V.png","211.png":"Abafn1.png","212.png":"Abacp4.png","213.png":"AbayhF.png","214.png":"Abag1J.png","215.png":"Aba2c9.png","216.png":"AbaRXR.png","217.png":"Aba476.png","218.png":"Abah0x.png","219.png":"Abdg58.png"},
|
||||
webSocketTask:null,
|
||||
timer: null,
|
||||
reconnectCn: 1
|
||||
};
|
||||
},
|
||||
onLoad(d) {
|
||||
|
@ -172,18 +174,23 @@
|
|||
});
|
||||
},
|
||||
mounted() {
|
||||
this.timer = setInterval(() => {
|
||||
this.getTimeOrListItem1();
|
||||
this.connect();
|
||||
}, 3000);
|
||||
// this.timer = setInterval(() => {
|
||||
// this.getTimeOrListItem1();
|
||||
// }, 3000);
|
||||
},
|
||||
onUnload() {
|
||||
// uni.closeSocket({
|
||||
// success: () => {
|
||||
// console.info("退出成功")
|
||||
// },
|
||||
// })
|
||||
this.reconnectCn = 101;
|
||||
uni.closeSocket({
|
||||
success: () => {
|
||||
console.info("退出成功")
|
||||
},
|
||||
code:500,
|
||||
complete:(res)=>{
|
||||
console.log("主动断开",res);
|
||||
}
|
||||
})
|
||||
// uni.closeSocket()
|
||||
uni.hideLoading();
|
||||
clearInterval(this.timer);
|
||||
this.timer = null;
|
||||
|
@ -269,7 +276,7 @@
|
|||
})
|
||||
// wss://sausers.blxinchuang.com/wss/chatSocket/
|
||||
// websocketUtils.getWsBaseUrl()
|
||||
this.webSocketTask = uni.connectSocket({
|
||||
uni.connectSocket({
|
||||
url: websocketUtils.getWsBaseUrl() + userId,
|
||||
data() {
|
||||
return {
|
||||
|
@ -291,13 +298,34 @@
|
|||
}
|
||||
});
|
||||
// 监听WebSocket连接打开事件
|
||||
this.webSocketTask.onOpen((res) => {
|
||||
uni.onSocketOpen((res) => {
|
||||
uni.hideLoading()
|
||||
console.info("监听WebSocket连接打开事件", res)
|
||||
});
|
||||
// 监听WebSocket错误
|
||||
uni.onSocketError((res) => {
|
||||
that.connecting = false
|
||||
that.connected = false
|
||||
uni.hideLoading()
|
||||
console.info("监听WebSocket错误" + res)
|
||||
});
|
||||
uni.onSocketMessage(function (res) {
|
||||
console.log('收到服务器内容:' + JSON.stringify(res));
|
||||
setTimeout(() => {
|
||||
that.hideDrawer();
|
||||
that.getTimeOrListItem1();
|
||||
}, 50);
|
||||
});
|
||||
uni.onSocketClose((res) => {
|
||||
that.connected = false
|
||||
that.startRecive = false
|
||||
that.msg = false
|
||||
console.log('onClose', res)
|
||||
if(this.reconnectCn<maxReconnectMaxCn){
|
||||
this.reconnectCn = this.reconnectCn + 1;
|
||||
this.connect();
|
||||
}
|
||||
});
|
||||
},
|
||||
close() {
|
||||
uni.closeSocket()
|
||||
|
@ -320,7 +348,7 @@
|
|||
}
|
||||
this.ListItem.push(d);
|
||||
});
|
||||
this.ListItem = this.ListItem.reverse();;
|
||||
this.ListItem = this.ListItem.reverse();
|
||||
setTimeout(() => {
|
||||
uni.pageScrollTo({
|
||||
scrollTop: 99999,
|
||||
|
@ -385,10 +413,10 @@
|
|||
userId: userId
|
||||
}
|
||||
// that.ListItem.push(data);
|
||||
setTimeout(() => {
|
||||
that.hideDrawer();
|
||||
that.getTimeOrListItem1();
|
||||
}, 50);
|
||||
// setTimeout(() => {
|
||||
// that.hideDrawer();
|
||||
// that.getTimeOrListItem1();
|
||||
// }, 500);
|
||||
},
|
||||
fail(err) {
|
||||
that.connect();
|
||||
|
|
Loading…
Reference in New Issue