聊天室

This commit is contained in:
曹磊 2024-08-30 15:29:02 +08:00
parent 2a74d067db
commit a95b78aefd
1 changed files with 48 additions and 32 deletions

View File

@ -79,6 +79,8 @@
</template>
<script>
import * as websocketUtils from 'utils/websocketUtils.js';
import { compile } from "vue";
const maxReconnectMaxCn = 30;
export default {
data() {
return {
@ -140,7 +142,9 @@
],
//
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) {
@ -163,17 +167,29 @@
}
},
mounted() {
this.timer = setInterval(() => {
this.getTimeOrListItem1()
}, 3000);
// this.timer = setInterval(() => {
// this.getTimeOrListItem1();
// }, 3000);
},
onUnload() {
// uni.closeSocket({
// success: () => {
// console.info("退")
// },
// })
// this.webSocketTask.close({
// code:500,
// complete:(res)=>{
// console.log("",res);
// }
// });
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;
@ -246,11 +262,11 @@
connect() {
let that = this;
let userId = that.$queue.getData('userId');
if (that.connected || that.connecting) {
uni.showModal({
content: '正在连接或者已经连接,请勿重复连接',
showCancel: false
})
if (that.connected && that.connecting) {
// uni.showModal({
// content: '',
// showCancel: false
// })
return false
}
that.connecting = true
@ -279,8 +295,8 @@
}
});
uni.onSocketOpen((res) => {
that.connecting = false
that.connected = true
// that.connecting = false
// that.connected = true
uni.hideLoading()
// uni.showToast({
// icon: 'none',
@ -292,25 +308,28 @@
that.connecting = false
that.connected = false
uni.hideLoading()
uni.showModal({
content: '网络较差,请稍后再试',
showCancel: false
})
// uni.showModal({
// content: '',
// showCancel: false
// })
console.log('onError', err);
});
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() {
@ -319,6 +338,7 @@
//
getTimeOrListItem1() {
console.log("im:getTimeOrListItem1");
this.$Request.get('/app/chat/selectChatContent?page=1&limit=1000&chatConversationId=' + this.chatConversationId).then(
res => {
this.ListItem = [];
@ -333,7 +353,7 @@
}
this.ListItem.push(d);
});
this.ListItem = this.ListItem.reverse();;
this.ListItem = this.ListItem.reverse();
setTimeout(() => {
uni.pageScrollTo({
scrollTop: 99999,
@ -368,7 +388,6 @@
if (!phone) {
phone = this.$queue.getData('userName');
}
console.log("this.byUserId",this.byUserId)
// if(this.textMsg!=''){
// const isRich = this.isRichText(this.textMsg); // true
// if(isRich==true){
@ -377,20 +396,16 @@
// this.content=this.textMsg
// }
// }
// console.log('this.content=============>',isRich)
let data = {
content: this.content,
messageType: type,
userId: this.byUserId,
chatConversationId: this.chatConversationId,
}
if(data.messageType==2){
data.width="100"
}
console.log("data",data)
data = JSON.stringify(data);
let that = this;
@ -410,15 +425,16 @@
type: type,
userId: userId
}
console.log(data,'data99999999999999999')
// console.log(data,'data99999999999999999')
// that.ListItem.push(data);
setTimeout(() => {
that.hideDrawer();
that.getTimeOrListItem1();
}, 50);
console.log(that.content);
// setTimeout(() => {
// that.hideDrawer();
// that.getTimeOrListItem1();
// }, 500);
// console.log(that.content);
},
fail(err) {
that.connect();
console.log(err);
}
})