|
|
|
|
@ -52,7 +52,7 @@
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { myCache } from '../../utils/utils.js';
|
|
|
|
|
import { getcartNum,getmessageNum,myCache } from '../../utils/utils.js';
|
|
|
|
|
import dateTime from '@/common/dateTime.js';
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
@ -75,28 +75,39 @@
|
|
|
|
|
], // u-swipe-action样式
|
|
|
|
|
imgurl:uni.$http.baseUrl,
|
|
|
|
|
grouplist:[],
|
|
|
|
|
socketTask: null,
|
|
|
|
|
isConnected: false, // WebSocket连接状态
|
|
|
|
|
socketmsg:[],//接收信息
|
|
|
|
|
heartbeatInterval: null, // 心跳包20秒连接一次
|
|
|
|
|
heartbeatTimeout: 20000, // 心跳间隔时间,例如每20秒发送一次
|
|
|
|
|
// isConnected: false, // WebSocket是否打开
|
|
|
|
|
// heartbeatInterval: null, // 心跳包20秒连接一次
|
|
|
|
|
// heartbeatTimeout: 20000, // 心跳间隔时间,例如每20秒发送一次
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
},
|
|
|
|
|
onShow(){
|
|
|
|
|
|
|
|
|
|
this.openId = myCache('openId');
|
|
|
|
|
var user = myCache('user');
|
|
|
|
|
this.userid = user.userid? user.userid:'';
|
|
|
|
|
this.userName=user.nickName?user.nickName:"";
|
|
|
|
|
this.userheadimg=user.avatar?user.avatar:require("@/static/image/girl.png");
|
|
|
|
|
this.phone = user.userphone;
|
|
|
|
|
// 如果心跳包在发送,先停止,再启动
|
|
|
|
|
if(this.heartbeatInterval){
|
|
|
|
|
clearInterval(this.heartbeatInterval); // 停止心跳包发送
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从缓存聊天群里获取聊天群列表
|
|
|
|
|
this.loadData();
|
|
|
|
|
|
|
|
|
|
var that=this;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if(!that.isConnected){
|
|
|
|
|
// 重新连接socket
|
|
|
|
|
that.reconnect();
|
|
|
|
|
}
|
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
|
|
that.setmsgnum();
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
that.setmsgnum();
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
console.log('onPullDownRefresh');
|
|
|
|
|
@ -104,73 +115,47 @@
|
|
|
|
|
uni.stopPullDownRefresh()
|
|
|
|
|
},500);
|
|
|
|
|
},
|
|
|
|
|
onBackPress(options) {
|
|
|
|
|
if (options.from === 'backbutton') {
|
|
|
|
|
// 来自顶部菜单的返回按钮
|
|
|
|
|
// 在这里处理你的逻辑
|
|
|
|
|
console.log('返回按钮被点击');
|
|
|
|
|
// this.closeWebSocket();
|
|
|
|
|
// uni.onSocketClose(function (res) {
|
|
|
|
|
// console.log('WebSocket 已关闭!');
|
|
|
|
|
// });
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
beforeDestroy() {
|
|
|
|
|
console.log('界面关闭socket,beforeDestroy');
|
|
|
|
|
// 在组件销毁前,确保关闭 WebSocket 连接
|
|
|
|
|
// this.closeWebSocket();
|
|
|
|
|
// clearInterval(this.heartbeatInterval); // 停止心跳包发送
|
|
|
|
|
},
|
|
|
|
|
beforeRouteLeave(to, from, next) {
|
|
|
|
|
console.log('界面关闭socket,beforeRouteLeave');
|
|
|
|
|
next();
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
handleLongPress(info,index) {
|
|
|
|
|
console.log(index);
|
|
|
|
|
this.$refs.swipeRef[index].open();
|
|
|
|
|
},
|
|
|
|
|
// 删除
|
|
|
|
|
actionClick(info,index) {
|
|
|
|
|
console.log(info,index);
|
|
|
|
|
var that=this;
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: "确定要删除此聊天记录吗?",
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
confirmText: '确定',
|
|
|
|
|
success: ress => {
|
|
|
|
|
if (ress.confirm) {
|
|
|
|
|
that.$refs.swipeRef[index].close();
|
|
|
|
|
myCache(info.id,"");
|
|
|
|
|
that.grouplist.splice(index, 1);
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
myCache("chatlist-"+this.userid,that.grouplist);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
// 定时心跳包
|
|
|
|
|
startHeartbeat() {
|
|
|
|
|
var that=this;
|
|
|
|
|
console.log("startHeartbeat")
|
|
|
|
|
this.heartbeatInterval = setInterval(() => {
|
|
|
|
|
if (this.socketTask) {
|
|
|
|
|
this.socketTask.send({
|
|
|
|
|
if(this.isConnected){
|
|
|
|
|
uni.sendSocketMessage({
|
|
|
|
|
data: JSON.stringify({
|
|
|
|
|
'cmd': 1,//心跳
|
|
|
|
|
'data': {
|
|
|
|
|
'accessToken':uni.getStorageSync("token")
|
|
|
|
|
},
|
|
|
|
|
}) // 发送心跳包数据
|
|
|
|
|
}), // 发送心跳包数据,
|
|
|
|
|
success(re) {
|
|
|
|
|
console.log(re);
|
|
|
|
|
console.log('消息发送成功!')
|
|
|
|
|
},
|
|
|
|
|
fail(err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
console.log('消息发送失败!');
|
|
|
|
|
that.reconnect();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, this.heartbeatTimeout);
|
|
|
|
|
},
|
|
|
|
|
// 开始重连
|
|
|
|
|
reconnect () {
|
|
|
|
|
if (!this.isConnected) {
|
|
|
|
|
clearTimeout(this.heartbeatInterval);
|
|
|
|
|
this.heartbeatInterval = setTimeout(() => {
|
|
|
|
|
console.log('开始重连...');
|
|
|
|
|
this.socketinit();
|
|
|
|
|
},this.heartbeatTimeout);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// ws接收消息
|
|
|
|
|
socketinit(){
|
|
|
|
|
var that = this;
|
|
|
|
|
that.socketTask=uni.connectSocket({
|
|
|
|
|
uni.connectSocket({
|
|
|
|
|
url: "wss://www.sanduolantoyoga.com/yoga-imserver/",
|
|
|
|
|
header: {
|
|
|
|
|
// 'content-type': 'application/json',
|
|
|
|
|
@ -189,8 +174,8 @@
|
|
|
|
|
|
|
|
|
|
uni.onSocketOpen(resopen => {
|
|
|
|
|
console.log('WebSocket连接已打开!');
|
|
|
|
|
that.isConnected = true;
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
this.isConnected = true;
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
uni.sendSocketMessage({
|
|
|
|
|
data: JSON.stringify({
|
|
|
|
|
"cmd": 0,//心跳
|
|
|
|
|
@ -253,41 +238,59 @@
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 连接关闭后重新连接
|
|
|
|
|
uni.onSocketClose(res => {
|
|
|
|
|
console.log('WebSocket连接已关闭!',res);
|
|
|
|
|
this.isConnected = false;
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
// 重新连接socket
|
|
|
|
|
this.reconnect();
|
|
|
|
|
});
|
|
|
|
|
// 连接失败后重新连接
|
|
|
|
|
uni.onSocketError(err => {
|
|
|
|
|
console.error('WebSocket连接打开失败,请检查:', err);
|
|
|
|
|
this.isConnected = false;
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
// 重新连接socket
|
|
|
|
|
this.reconnect();
|
|
|
|
|
});
|
|
|
|
|
// 接收信息
|
|
|
|
|
uni.onSocketMessage(res => {
|
|
|
|
|
console.log('收到WebSocket服务器消息:');
|
|
|
|
|
if(res.data){
|
|
|
|
|
var rs=JSON.parse(res.data);
|
|
|
|
|
console.log(rs);
|
|
|
|
|
console.log("onSocketMessage",rs);
|
|
|
|
|
if(rs.cmd==3){
|
|
|
|
|
// 私聊
|
|
|
|
|
if(rs.data){
|
|
|
|
|
var data=rs.data;
|
|
|
|
|
if(data.recvId&&(data.recvId).toString()==(that.userid).toString()){
|
|
|
|
|
if(data.recvId&&data.recvId==that.userid){
|
|
|
|
|
// 是这个用户的接收的私聊信息
|
|
|
|
|
// 加入聊天记录
|
|
|
|
|
// 消息类型 0:文字 1:图片 2:文件 3:语音 4:视频 10, "撤回" 11, "已读 "12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
if(data.type==0||data.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){
|
|
|
|
|
if(data.type==0){
|
|
|
|
|
data.content=decodeURIComponent(data.content);
|
|
|
|
|
}
|
|
|
|
|
if(data.type==0||data.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){
|
|
|
|
|
var ifexist=0,chatinfo=null;
|
|
|
|
|
that.grouplist.forEach((cell,index)=>{
|
|
|
|
|
if(cell.fromuser==data.sendId&&cell.userid==data.recvId&&cell.sort=="privatechat"){
|
|
|
|
|
ifexist=1;
|
|
|
|
|
|
|
|
|
|
var id="privatechat-" + data.recvId +"-" + data.sendId;
|
|
|
|
|
var index=this.ifadd(id);
|
|
|
|
|
var chatinfo=null;
|
|
|
|
|
if(index>-1){
|
|
|
|
|
that.grouplist[index].sl=(that.grouplist[index].sl?that.grouplist[index].sl+1:1);
|
|
|
|
|
that.grouplist[index].content=data.content;
|
|
|
|
|
that.grouplist[index].datetime=data.sendTime;
|
|
|
|
|
that.grouplist[index].type=data.type;
|
|
|
|
|
that.grouplist[index].minId=data.id;
|
|
|
|
|
that.grouplist[index].ifload=1;
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
chatinfo= JSON.parse(JSON.stringify(that.grouplist[index]));
|
|
|
|
|
console.log(chatinfo)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if(ifexist==0){
|
|
|
|
|
else{
|
|
|
|
|
// 未保存缓存
|
|
|
|
|
// 接收到socket后更新聊天列表记录
|
|
|
|
|
var chatlastinfo={
|
|
|
|
|
id: "privatechat-" + data.recvId +"-" + data.sendId,
|
|
|
|
|
chatinfo={
|
|
|
|
|
id: id,
|
|
|
|
|
content: data.content,
|
|
|
|
|
minId: data.id,
|
|
|
|
|
sl:1,
|
|
|
|
|
@ -297,13 +300,16 @@
|
|
|
|
|
userid: data.recvId,
|
|
|
|
|
fromuser: data.sendId,
|
|
|
|
|
img: "",
|
|
|
|
|
sort:"privatechat"
|
|
|
|
|
sort:"privatechat",
|
|
|
|
|
ifload:0
|
|
|
|
|
};
|
|
|
|
|
that.updateChatList(chatlastinfo);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
that.updateChatList(chatinfo);
|
|
|
|
|
this.grouplist.push(chatinfo);
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
this.getPrivateInfo(chatinfo);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// 10, "撤回" 11, "已读 " 12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
@ -320,29 +326,31 @@
|
|
|
|
|
// 是这个用户的接收的群聊信息
|
|
|
|
|
// 加入聊天记录
|
|
|
|
|
// 消息类型 0:文字 1:图片 2:文件 3:语音 4:视频 10, "撤回" 11, "已读 "12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
if(data.type==0||data.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){
|
|
|
|
|
|
|
|
|
|
if(data.type==0){
|
|
|
|
|
data.content=decodeURIComponent(data.content);
|
|
|
|
|
}
|
|
|
|
|
if(data.type==0||data.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){
|
|
|
|
|
var ifexist=0,idx=null;
|
|
|
|
|
that.grouplist.forEach((cell,index)=>{
|
|
|
|
|
if(cell.groupId==data.groupId&&cell.sort=="groupchat"){
|
|
|
|
|
ifexist=1;
|
|
|
|
|
idx=index;
|
|
|
|
|
|
|
|
|
|
var id="groupchat-" + data.groupId;
|
|
|
|
|
var index=this.ifadd(id);
|
|
|
|
|
var chatinfo=null;
|
|
|
|
|
if(index>-1){
|
|
|
|
|
that.grouplist[index].sl=(that.grouplist[index].sl?that.grouplist[index].sl+1:1);
|
|
|
|
|
that.grouplist[index].content=data.content;
|
|
|
|
|
that.grouplist[index].datetime=data.sendTime;
|
|
|
|
|
that.grouplist[index].fromuser=data.sendId;
|
|
|
|
|
that.grouplist[index].type=data.type;
|
|
|
|
|
that.grouplist[index].minId=data.id;
|
|
|
|
|
that.grouplist[index].ifload=1;
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
chatinfo= JSON.parse(JSON.stringify(that.grouplist[index]));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if(ifexist==0){
|
|
|
|
|
else{
|
|
|
|
|
// 未保存缓存
|
|
|
|
|
// 接收到socket后更新聊天列表记录
|
|
|
|
|
var chatlastinfo={
|
|
|
|
|
id: "groupchat-" + data.groupId,
|
|
|
|
|
chatinfo={
|
|
|
|
|
id: id,
|
|
|
|
|
groupId: data.groupId,
|
|
|
|
|
content: data.content,
|
|
|
|
|
minId: data.id,
|
|
|
|
|
@ -355,17 +363,19 @@
|
|
|
|
|
img: "",
|
|
|
|
|
sendId: data.sendId,
|
|
|
|
|
sendNickName: data.sendNickName,
|
|
|
|
|
sort:"groupchat"
|
|
|
|
|
sort:"groupchat",
|
|
|
|
|
ifload:0
|
|
|
|
|
};
|
|
|
|
|
that.getGroupInfo(chatlastinfo);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
that.getGroupInfo(that.grouplist[idx]);
|
|
|
|
|
this.grouplist.push(chatinfo);
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
this.getGroupInfo(chatinfo);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// 10, "撤回" 11, "已读 " 12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -373,32 +383,56 @@
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
uni.onSocketClose(res => {
|
|
|
|
|
console.log('WebSocket连接已关闭!',res);
|
|
|
|
|
that.isConnected = false;
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
clearInterval(that.heartbeatInterval); // 停止心跳包发送
|
|
|
|
|
},
|
|
|
|
|
// 消息
|
|
|
|
|
setmsgnum(){
|
|
|
|
|
var messageNum=getmessageNum();
|
|
|
|
|
if(messageNum>0){
|
|
|
|
|
// 底部菜单消息角标
|
|
|
|
|
uni.setTabBarBadge({
|
|
|
|
|
//显示未读消息条数
|
|
|
|
|
index: 3,
|
|
|
|
|
text: messageNum+''
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
uni.onSocketError(err => {
|
|
|
|
|
console.error('WebSocket连接打开失败,请检查:', err);
|
|
|
|
|
that.isConnected = false;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
uni.removeTabBarBadge({
|
|
|
|
|
index: 3
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handleLongPress(info,index) {
|
|
|
|
|
console.log(index);
|
|
|
|
|
this.$refs.swipeRef[index].open();
|
|
|
|
|
},
|
|
|
|
|
// 删除
|
|
|
|
|
actionClick(info,index) {
|
|
|
|
|
console.log(info,index);
|
|
|
|
|
var that=this;
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: "确定要删除此聊天记录吗?",
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
confirmText: '确定',
|
|
|
|
|
success: ress => {
|
|
|
|
|
if (ress.confirm) {
|
|
|
|
|
that.$refs.swipeRef[index].close();
|
|
|
|
|
myCache(info.id,"");
|
|
|
|
|
that.grouplist.splice(index, 1);
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
clearInterval(that.heartbeatInterval); // 停止心跳包发送
|
|
|
|
|
myCache("chatlist-"+this.userid,that.grouplist);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
// 关闭WebSocket连接
|
|
|
|
|
closeWebSocket() {
|
|
|
|
|
uni.closeSocket();
|
|
|
|
|
this.isConnected = false;
|
|
|
|
|
this.$forceUpdate()
|
|
|
|
|
},
|
|
|
|
|
// 消息是否存在列表中
|
|
|
|
|
ifadd(id){
|
|
|
|
|
var ret=0;
|
|
|
|
|
var ret=-1;
|
|
|
|
|
this.grouplist.forEach((cell,ii)=>{
|
|
|
|
|
if(cell.id==id){
|
|
|
|
|
ret=ii+1;
|
|
|
|
|
ret=ii;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return ret;
|
|
|
|
|
@ -416,6 +450,8 @@
|
|
|
|
|
this.grouplist[index]["sl"]=0;
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
// 去聊天室
|
|
|
|
|
if(chat.sort=="privatechat"){
|
|
|
|
|
// 私聊
|
|
|
|
|
@ -455,6 +491,7 @@
|
|
|
|
|
reason: chat.reason,
|
|
|
|
|
customerService: chat.customerService,
|
|
|
|
|
instructor: chat.instructor,
|
|
|
|
|
ownerId: chat.ownerId,
|
|
|
|
|
productId: chat.productId,
|
|
|
|
|
productName: chat.productName
|
|
|
|
|
}
|
|
|
|
|
@ -483,8 +520,9 @@
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
that.reorder();
|
|
|
|
|
myCache("chatlist-"+this.userid,that.grouplist);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
|
|
// socket接收实时消息
|
|
|
|
|
this.socketinit();
|
|
|
|
|
},
|
|
|
|
|
@ -524,7 +562,8 @@
|
|
|
|
|
img: "",
|
|
|
|
|
sendId: cell.sendId,
|
|
|
|
|
sendNickName: cell.sendNickName,
|
|
|
|
|
sort:"groupchat"
|
|
|
|
|
sort:"groupchat",
|
|
|
|
|
ifload:1
|
|
|
|
|
};
|
|
|
|
|
this.getGroupInfo(chatlastinfo,index);
|
|
|
|
|
});
|
|
|
|
|
@ -549,9 +588,11 @@
|
|
|
|
|
userid: cell.recvId,
|
|
|
|
|
fromuser: cell.sendId,
|
|
|
|
|
img: "",
|
|
|
|
|
sort:"privatechat"
|
|
|
|
|
sort:"privatechat",
|
|
|
|
|
ifload:1
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
this.updateChatList(chatlastinfo,index);
|
|
|
|
|
this.getPrivateInfo(chatlastinfo);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
@ -602,6 +643,8 @@
|
|
|
|
|
// 重新排序
|
|
|
|
|
this.reorder();
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
@ -628,13 +671,28 @@
|
|
|
|
|
// 重新排序
|
|
|
|
|
this.reorder();
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 获取私聊信息
|
|
|
|
|
async getPrivateInfo(info) {
|
|
|
|
|
if(info.ifload==0){
|
|
|
|
|
info[info.fromuser]=(info.fromuser!=this.userid? await this.getFriend(info.fromuser):{});
|
|
|
|
|
info.name=info[info.fromuser]?info[info.fromuser].name:"匿名";
|
|
|
|
|
info.img=info[info.fromuser]?info[info.fromuser].img:require("@/static/image/girl.png");
|
|
|
|
|
this.updateChatList(info);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.updateChatList(info);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 获取群信息
|
|
|
|
|
async getGroupInfo(info) {
|
|
|
|
|
if(info.ifload==0){
|
|
|
|
|
const {data: res} = await uni.$http.get('/api/group/find/'+info.groupId);
|
|
|
|
|
if(res.data){
|
|
|
|
|
var data = res.data;
|
|
|
|
|
@ -647,96 +705,58 @@
|
|
|
|
|
info.remarkGroupName=data.remarkGroupName;
|
|
|
|
|
info.customerService=data.customerService;
|
|
|
|
|
info.instructor=data.instructor;
|
|
|
|
|
info.ownerId=data.ownerId;
|
|
|
|
|
info.productId=data.productId;
|
|
|
|
|
info.productName=data.productName;
|
|
|
|
|
info[data.ownerId]=(data.ownerId!=this.userid? await this.getFriend(data.ownerId):{});
|
|
|
|
|
info[data.customerService]=(data.customerService!= this.userid? await this.getFriend(data.customerService):{});
|
|
|
|
|
info[data.instructor]=(data.instructor!=this.userid? await this.getFriend(data.instructor):{});
|
|
|
|
|
this.updateChatGroupList(info);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async updateChatGroupList(info){
|
|
|
|
|
var name=info.name,img=info.img||require("@/static/image/girl.png");
|
|
|
|
|
const {data: res} = await uni.$http.get("/api/friend/find/"+info.sendId);
|
|
|
|
|
if(res.data){
|
|
|
|
|
var data=res.data;
|
|
|
|
|
name=data.nickName?data.nickName:"匿名";
|
|
|
|
|
img=data.headImage?data.headImage:require("@/static/image/girl.png");
|
|
|
|
|
var idx=this.ifadd(info.id);
|
|
|
|
|
if(!idx){
|
|
|
|
|
this.grouplist.push(info);
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.grouplist[idx-1].content=info.content;
|
|
|
|
|
this.grouplist[idx-1].datetime=info.datetime;
|
|
|
|
|
this.grouplist[idx-1].fromuser=info.fromuser;
|
|
|
|
|
this.grouplist[idx-1].type=info.type;
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
this.updateChatGroupList(info);
|
|
|
|
|
}
|
|
|
|
|
// 重新排序 保存缓存
|
|
|
|
|
this.reorder();
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
// 聊天框消息缓存
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
|
if(!msgchat){
|
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
|
let firstmsg = [{
|
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
|
"fromuser": info.fromuser, // 发送人
|
|
|
|
|
"headimg": img, // 发送人
|
|
|
|
|
"toname": this.userName, // 接收人
|
|
|
|
|
"touser": this.userid, // 接收人姓名
|
|
|
|
|
"content": info.content,
|
|
|
|
|
"time": info.type==3?5:0,
|
|
|
|
|
"ifaudio":info.type==3? true:false,
|
|
|
|
|
"fromtime": info.datetime,
|
|
|
|
|
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
|
|
|
|
|
"id": info.id,
|
|
|
|
|
"minId": info.minId,
|
|
|
|
|
"sendId": info.sendId,
|
|
|
|
|
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
|
|
|
|
|
}];
|
|
|
|
|
console.log("firstmsg",firstmsg)
|
|
|
|
|
myCache(info.id,firstmsg);
|
|
|
|
|
},
|
|
|
|
|
async getFriend(id){
|
|
|
|
|
var name="匿名",img=require("@/static/image/girl.png");
|
|
|
|
|
const {data: res} = await uni.$http.get("/api/friend/find/"+id);
|
|
|
|
|
if(res.data){
|
|
|
|
|
name=res.data.nickName?res.data.nickName:"匿名";
|
|
|
|
|
img=res.data.headImage?res.data.headImage:require("@/static/image/girl.png");
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// 聊天框信息 保存缓存
|
|
|
|
|
let firstmsg = {
|
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
|
"fromuser": info.fromuser, // 发送人
|
|
|
|
|
"headimg": img, // 发送人
|
|
|
|
|
"toname": this.userName, // 接收人
|
|
|
|
|
"touser": this.userid, // 接收人姓名
|
|
|
|
|
"content": info.content,
|
|
|
|
|
"time": info.type==3?5:0,
|
|
|
|
|
"ifaudio":info.type==3? true:false,
|
|
|
|
|
"fromtime": info.datetime,
|
|
|
|
|
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
|
|
|
|
|
"id": info.id,
|
|
|
|
|
"minId": info.minId,
|
|
|
|
|
"sendId": info.sendId,
|
|
|
|
|
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
|
|
|
|
|
return {
|
|
|
|
|
name:name,
|
|
|
|
|
img:img
|
|
|
|
|
};
|
|
|
|
|
msgchat.push(firstmsg);
|
|
|
|
|
myCache(info.id,msgchat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
name="匿名";
|
|
|
|
|
img="../../static/image/girl.png";
|
|
|
|
|
},
|
|
|
|
|
async updateChatGroupList(info){
|
|
|
|
|
// 获取发送人的信息
|
|
|
|
|
var name= "匿名",img= require("@/static/image/girl.png");
|
|
|
|
|
var idx=this.ifadd(info.id);
|
|
|
|
|
if(!idx){
|
|
|
|
|
if(idx<0){
|
|
|
|
|
name=info[info.sendId]?info[info.sendId].name:"匿名";
|
|
|
|
|
img=info[info.sendId]?info[info.sendId].img:require("@/static/image/girl.png");
|
|
|
|
|
// 新增一条
|
|
|
|
|
this.grouplist.push(info);
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.grouplist[idx-1].content=info.content;
|
|
|
|
|
this.grouplist[idx-1].datetime=info.datetime;
|
|
|
|
|
this.grouplist[idx-1].fromuser=info.fromuser;
|
|
|
|
|
this.grouplist[idx-1].type=info.type;
|
|
|
|
|
name=this.grouplist[idx][info.sendId].name?this.grouplist[idx][info.sendId].name:"匿名";
|
|
|
|
|
img=this.grouplist[idx][info.sendId].img?this.grouplist[idx][info.sendId].img:require("@/static/image/girl.png");
|
|
|
|
|
this.grouplist[idx].content=info.content;
|
|
|
|
|
this.grouplist[idx].datetime=info.datetime;
|
|
|
|
|
this.grouplist[idx].fromuser=info.fromuser;
|
|
|
|
|
this.grouplist[idx].type=info.type;
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
// 重新排序
|
|
|
|
|
// 重新排序 保存缓存
|
|
|
|
|
this.reorder();
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
|
|
|
|
|
// 聊天框消息缓存
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
|
if(!msgchat){
|
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
|
@ -747,11 +767,11 @@
|
|
|
|
|
"toname": this.userName, // 接收人
|
|
|
|
|
"touser": this.userid, // 接收人姓名
|
|
|
|
|
"content": info.content,
|
|
|
|
|
"time": info.type==3?5:0,
|
|
|
|
|
"time": info.type==3?(info.time?info.time:5):0,
|
|
|
|
|
"ifaudio":info.type==3? true:false,
|
|
|
|
|
"fromtime": info.datetime,
|
|
|
|
|
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
|
|
|
|
|
"id": info.id,
|
|
|
|
|
"id": info.minId,
|
|
|
|
|
"minId": info.minId,
|
|
|
|
|
"sendId": info.sendId,
|
|
|
|
|
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
|
|
|
|
|
@ -759,6 +779,8 @@
|
|
|
|
|
myCache(info.id,firstmsg);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// 是否已经加入到聊天记录中
|
|
|
|
|
if(this.ifchatadd(info.id,info.minId)){
|
|
|
|
|
// 聊天框信息 保存缓存
|
|
|
|
|
let firstmsg = {
|
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
|
@ -767,11 +789,11 @@
|
|
|
|
|
"toname": this.userName, // 接收人
|
|
|
|
|
"touser": this.userid, // 接收人姓名
|
|
|
|
|
"content": info.content,
|
|
|
|
|
"time": info.type==3?5:0,
|
|
|
|
|
"time": info.type==3?(info.time?info.time:5):0,
|
|
|
|
|
"ifaudio":info.type==3? true:false,
|
|
|
|
|
"fromtime": info.datetime,
|
|
|
|
|
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
|
|
|
|
|
"id": info.id,
|
|
|
|
|
"id": info.minId,
|
|
|
|
|
"minId": info.minId,
|
|
|
|
|
"sendId": info.sendId,
|
|
|
|
|
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
|
|
|
|
|
@ -779,46 +801,53 @@
|
|
|
|
|
msgchat.push(firstmsg);
|
|
|
|
|
myCache(info.id,msgchat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async updateChatList(info){
|
|
|
|
|
const {data: res} = await uni.$http.get("/api/friend/find/"+info.fromuser);
|
|
|
|
|
if(res.data){
|
|
|
|
|
var data=res.data;
|
|
|
|
|
info.name=data.nickName?data.nickName:"匿名";
|
|
|
|
|
info.img=data.headImage?data.headImage:require("@/static/image/girl.png");
|
|
|
|
|
var name= "匿名",img= require("@/static/image/girl.png");
|
|
|
|
|
// 此消息是否已经存在列表中
|
|
|
|
|
var idx=this.ifadd(info.id);
|
|
|
|
|
if(!idx){
|
|
|
|
|
if(idx<0){
|
|
|
|
|
// 获取发送人的信息
|
|
|
|
|
name=info[info.fromuser]?info[info.fromuser].name:"匿名";
|
|
|
|
|
img=info[info.fromuser]?info[info.fromuser].img:require("@/static/image/girl.png");
|
|
|
|
|
info.img=img;
|
|
|
|
|
info.name=name;
|
|
|
|
|
this.grouplist.push(info);
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// this.grouplist[idx-1].sl=(this.grouplist[idx-1].sl?this.grouplist[idx-1].sl+1:1);
|
|
|
|
|
this.grouplist[idx-1].content=info.content;
|
|
|
|
|
this.grouplist[idx-1].datetime=info.datetime;
|
|
|
|
|
this.grouplist[idx-1].fromuser=info.fromuser;
|
|
|
|
|
this.grouplist[idx-1].type=info.type;
|
|
|
|
|
name=this.grouplist[idx].name?this.grouplist[idx].name:"匿名";
|
|
|
|
|
img=this.grouplist[idx].img?this.grouplist[idx].img:require("@/static/image/girl.png");
|
|
|
|
|
this.grouplist[idx].content=info.content;
|
|
|
|
|
this.grouplist[idx].datetime=info.datetime;
|
|
|
|
|
this.grouplist[idx].fromuser=info.fromuser;
|
|
|
|
|
this.grouplist[idx].type=info.type;
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
// 重新排序 保存缓存
|
|
|
|
|
this.reorder();
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
// 未读消息数量获取
|
|
|
|
|
this.setmsgnum();
|
|
|
|
|
|
|
|
|
|
// 聊天框消息缓存
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
|
if(!msgchat){
|
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
|
let firstmsg = [{
|
|
|
|
|
"fromname": info.name, // 发送人
|
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
|
"fromuser": info.fromuser, // 发送人
|
|
|
|
|
"headimg": info.img, // 发送人
|
|
|
|
|
"headimg": img, // 发送人
|
|
|
|
|
"toname": this.userName, // 接收人
|
|
|
|
|
"touser": this.userid, // 接收人姓名
|
|
|
|
|
"content": info.content,
|
|
|
|
|
"time": info.type==3?5:0,
|
|
|
|
|
"time": info.type==3?(info.time?info.time:5):0,
|
|
|
|
|
"ifaudio":info.type==3? true:false,
|
|
|
|
|
"fromtime": info.datetime,
|
|
|
|
|
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
|
|
|
|
|
"id": info.id,
|
|
|
|
|
"id": info.minId,
|
|
|
|
|
"minId": info.minId,
|
|
|
|
|
"recvId": info.recvId,
|
|
|
|
|
"sendId": info.sendId,
|
|
|
|
|
@ -827,19 +856,20 @@
|
|
|
|
|
myCache(info.id,firstmsg);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
if(this.ifchatadd(info.id,info.minId)){
|
|
|
|
|
// 聊天框信息 保存缓存
|
|
|
|
|
let firstmsg = {
|
|
|
|
|
"fromname": info.name, // 发送人
|
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
|
"fromuser": info.fromuser, // 发送人
|
|
|
|
|
"headimg": info.img, // 发送人
|
|
|
|
|
"headimg": img, // 发送人
|
|
|
|
|
"toname": this.userName, // 接收人
|
|
|
|
|
"touser": this.userid, // 接收人姓名
|
|
|
|
|
"content": info.content,
|
|
|
|
|
"time": info.type==3?5:0,
|
|
|
|
|
"time": info.type==3?(info.time?info.time:5):0,
|
|
|
|
|
"ifaudio":info.type==3? true:false,
|
|
|
|
|
"fromtime": info.datetime,
|
|
|
|
|
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
|
|
|
|
|
"id": info.id,
|
|
|
|
|
"id": info.minId,
|
|
|
|
|
"minId": info.minId,
|
|
|
|
|
"recvId": info.recvId,
|
|
|
|
|
"sendId": info.sendId,
|
|
|
|
|
@ -849,72 +879,18 @@
|
|
|
|
|
myCache(info.id,msgchat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
info.name="匿名";
|
|
|
|
|
info.img="../../static/image/girl.png";
|
|
|
|
|
var idx=this.ifadd(info.id);
|
|
|
|
|
if(!idx){
|
|
|
|
|
this.grouplist.push(info);
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// this.grouplist[idx-1].sl=(this.grouplist[idx-1].sl?this.grouplist[idx-1].sl+1:1);
|
|
|
|
|
this.grouplist[idx-1].content=info.content;
|
|
|
|
|
this.grouplist[idx-1].datetime=info.datetime;
|
|
|
|
|
this.grouplist[idx-1].fromuser=info.fromuser;
|
|
|
|
|
this.grouplist[idx-1].type=info.type;
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
}
|
|
|
|
|
// 重新排序
|
|
|
|
|
this.reorder();
|
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
|
console.log(info.id,msgchat);
|
|
|
|
|
if(!msgchat){
|
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
|
let firstmsg = [{
|
|
|
|
|
"fromname": info.name, // 发送人
|
|
|
|
|
"fromuser": info.fromuser, // 发送人
|
|
|
|
|
"headimg": info.img, // 发送人
|
|
|
|
|
"toname": this.userName, // 接收人
|
|
|
|
|
"touser": this.userid, // 接收人姓名
|
|
|
|
|
"content": info.content,
|
|
|
|
|
"time": info.type==3?5:0,
|
|
|
|
|
"ifaudio":info.type==3? true:false,
|
|
|
|
|
"fromtime": info.datetime,
|
|
|
|
|
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
|
|
|
|
|
"id": info.id,
|
|
|
|
|
"minId": info.minId,
|
|
|
|
|
"recvId": info.recvId,
|
|
|
|
|
"sendId": info.sendId,
|
|
|
|
|
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
|
|
|
|
|
}];
|
|
|
|
|
myCache(info.id,firstmsg);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
// 聊天框信息 保存缓存
|
|
|
|
|
let firstmsg = {
|
|
|
|
|
"fromname": info.name, // 发送人
|
|
|
|
|
"fromuser": info.fromuser, // 发送人
|
|
|
|
|
"headimg": info.img, // 发送人
|
|
|
|
|
"toname": this.userName, // 接收人
|
|
|
|
|
"touser": this.userid, // 接收人姓名
|
|
|
|
|
"content": info.content,
|
|
|
|
|
"time": info.type==3?5:0,
|
|
|
|
|
"ifaudio":info.type==3? true:false,
|
|
|
|
|
"fromtime": info.datetime,
|
|
|
|
|
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
|
|
|
|
|
"id": info.id,
|
|
|
|
|
"minId": info.minId,
|
|
|
|
|
"recvId": info.recvId,
|
|
|
|
|
"sendId": info.sendId,
|
|
|
|
|
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
|
|
|
|
|
};
|
|
|
|
|
msgchat.push(firstmsg);
|
|
|
|
|
myCache(info.id,msgchat);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 消息是否存在列表中
|
|
|
|
|
ifchatadd(id,msgid){
|
|
|
|
|
var ret=true;
|
|
|
|
|
var msgchat=myCache(id);
|
|
|
|
|
msgchat.forEach((cell)=>{
|
|
|
|
|
if(cell.id==msgid){
|
|
|
|
|
ret=false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return ret;
|
|
|
|
|
},
|
|
|
|
|
async getProduct(id){
|
|
|
|
|
console.log("getProduct",id)
|
|
|
|
|
@ -1020,7 +996,7 @@
|
|
|
|
|
background: #fff;
|
|
|
|
|
margin: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
min-width: 600rpx;
|
|
|
|
|
min-width: 750rpx;
|
|
|
|
|
.lcon{
|
|
|
|
|
border-bottom: 1rpx solid #eee;
|
|
|
|
|
padding-top: 20rpx;
|
|
|
|
|
@ -1030,6 +1006,7 @@
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: center;
|
|
|
|
|
width: 100%;
|
|
|
|
|
min-width: 750rpx;
|
|
|
|
|
.limg{
|
|
|
|
|
width: 100rpx;
|
|
|
|
|
height: 100rpx;
|
|
|
|
|
|