fix: 在当前会话页面刷新报错问题

feature/im-0602-ch
ch 3 years ago
parent 99f950804b
commit ae4a4284c9

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-05-18 14:54:47
* @LastEditors: ch
* @LastEditTime: 2022-06-13 22:18:23
* @LastEditTime: 2022-06-14 10:52:01
* @Description: file content
*/
import { CreateUUID, FormatDate, ToAsyncAwait } from "@/common/utils";
@ -282,6 +282,11 @@ class MsbIm {
if (item.lastMessage) {
item.lastMessage.payload = JSON.parse(item.lastMessage.payload || {});
}
let historyData = this.sessionData;
let hisIndex = historyData.findIndex((i) => i.id === item.id);
if (hisIndex < 0) {
item.messageList = [];
}
// let historyData = this.sessionData;
// let hisIndex = historyData.findIndex((i) => i.id === item.id);
// if (hisIndex >= 0) {
@ -303,6 +308,7 @@ class MsbIm {
async getHistoryMsg() {
const curSessionIdx = this.sessionData.findIndex((i) => i.id === this.curSessionId);
const curSession = this.sessionData[curSessionIdx];
console.log(curSession, this.curSessionId,'this.curSessionId');
const msgList = curSession.messageList || [];
const par = {
traceId: CreateUUID(),

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-26 14:32:03
* @LastEditors: ch
* @LastEditTime: 2022-06-10 19:09:45
* @LastEditTime: 2022-06-14 11:10:03
* @Description: file content
-->
<template>
@ -109,14 +109,7 @@ export default {
this.orderId = this.$Route.query.orderId;
this.sessionId = this.$Route.query.sessionId;
if(this.sessionId){
if(!this.msgData?.length){
this.getHistoryMsg();
}
this.readMsg();
}else{
this.createSessionMain();
}
this.socketInit();
if(this.goodsId){
this.getGoodsInfo();
}
@ -132,6 +125,23 @@ export default {
},
methods:{
socketInit(){
if(!Im.isOpen){
setTimeout(()=>{
this.socketInit();
}, 100)
return false;
}
if(this.sessionId){
if(!this.msgData?.length){
this.getHistoryMsg();
}
this.readMsg();
}else{
this.createSessionMain();
}
},
/**
* 创建会话主体
* 如果是从商品或订单进来需要创建会话
@ -161,6 +171,12 @@ export default {
* 获取历史消息
*/
async getHistoryMsg(){
if(!this.curSessionData.id){
setTimeout(()=>{
this.getHistoryMsg();
}, 500)
return false;
}
this.loading = true;
const {error, result} = await ToAsyncAwait(Im.getHistoryMsg());
if(error){
@ -180,6 +196,7 @@ export default {
}));
if(error){
uni.$u.toast(error.errMsg || error.message);
console.log(error);
return false
}

Loading…
Cancel
Save