|
|
|
@ -12,7 +12,8 @@
|
|
|
|
<view v-if="grouplist.length==0 && loadStatus=='nomore'" class="nodata">暂无消息~</view>
|
|
|
|
<view v-if="grouplist.length==0 && loadStatus=='nomore'" class="nodata">暂无消息~</view>
|
|
|
|
|
|
|
|
|
|
|
|
<view class="listcell">
|
|
|
|
<view class="listcell">
|
|
|
|
<u-swipe-action ref="swipeRef" :options="options" v-for="(info, index) in grouplist" :key="index" @click="$u.throttle(actionClick(info,index), 2000)" >
|
|
|
|
<u-swipe-action ref="swipeRef" :options="options" v-for="(info, index) in grouplist" :key="info.id" style="min-width: 600rpx;"
|
|
|
|
|
|
|
|
@click="$u.throttle(actionClick(info,index), 2000)">
|
|
|
|
<view class="lcon" @click="gotoGroup(info,index)" :key="index" @longpress="handleLongPress(info,index)">
|
|
|
|
<view class="lcon" @click="gotoGroup(info,index)" :key="index" @longpress="handleLongPress(info,index)">
|
|
|
|
<view class="limg">
|
|
|
|
<view class="limg">
|
|
|
|
<image class="img" :src="info.img" mode="aspectFill"></image>
|
|
|
|
<image class="img" :src="info.img" mode="aspectFill"></image>
|
|
|
|
@ -82,8 +83,6 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onLoad(options) {
|
|
|
|
onLoad(options) {
|
|
|
|
// socket接收信息初始化
|
|
|
|
|
|
|
|
// this.socketinit();
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onShow(){
|
|
|
|
onShow(){
|
|
|
|
this.openId = myCache('openId');
|
|
|
|
this.openId = myCache('openId');
|
|
|
|
@ -110,18 +109,18 @@
|
|
|
|
// 来自顶部菜单的返回按钮
|
|
|
|
// 来自顶部菜单的返回按钮
|
|
|
|
// 在这里处理你的逻辑
|
|
|
|
// 在这里处理你的逻辑
|
|
|
|
console.log('返回按钮被点击');
|
|
|
|
console.log('返回按钮被点击');
|
|
|
|
this.closeWebSocket();
|
|
|
|
// this.closeWebSocket();
|
|
|
|
uni.onSocketClose(function (res) {
|
|
|
|
// uni.onSocketClose(function (res) {
|
|
|
|
console.log('WebSocket 已关闭!');
|
|
|
|
// console.log('WebSocket 已关闭!');
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
beforeDestroy() {
|
|
|
|
console.log('界面关闭socket,beforeDestroy');
|
|
|
|
console.log('界面关闭socket,beforeDestroy');
|
|
|
|
// 在组件销毁前,确保关闭 WebSocket 连接
|
|
|
|
// 在组件销毁前,确保关闭 WebSocket 连接
|
|
|
|
this.closeWebSocket();
|
|
|
|
// this.closeWebSocket();
|
|
|
|
clearInterval(this.heartbeatInterval); // 停止心跳包发送
|
|
|
|
// clearInterval(this.heartbeatInterval); // 停止心跳包发送
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beforeRouteLeave(to, from, next) {
|
|
|
|
beforeRouteLeave(to, from, next) {
|
|
|
|
console.log('界面关闭socket,beforeRouteLeave');
|
|
|
|
console.log('界面关闭socket,beforeRouteLeave');
|
|
|
|
@ -130,22 +129,7 @@
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
handleLongPress(info,index) {
|
|
|
|
handleLongPress(info,index) {
|
|
|
|
console.log(index);
|
|
|
|
console.log(index);
|
|
|
|
this.$refs.swipeRef[index].open()
|
|
|
|
this.$refs.swipeRef[index].open();
|
|
|
|
// var that=this;
|
|
|
|
|
|
|
|
// uni.showModal({
|
|
|
|
|
|
|
|
// title: '提示',
|
|
|
|
|
|
|
|
// content: "确定要删除此聊天记录吗?",
|
|
|
|
|
|
|
|
// cancelText: '取消',
|
|
|
|
|
|
|
|
// confirmText: '确定',
|
|
|
|
|
|
|
|
// success: ress => {
|
|
|
|
|
|
|
|
// if (ress.confirm) {
|
|
|
|
|
|
|
|
// // myCache(info.id,"");
|
|
|
|
|
|
|
|
// // that.grouplist.splice(index, 1);
|
|
|
|
|
|
|
|
// // that.$forceUpdate();
|
|
|
|
|
|
|
|
// // myCache("chatlist-"+this.userid,that.grouplist);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 删除
|
|
|
|
// 删除
|
|
|
|
actionClick(info,index) {
|
|
|
|
actionClick(info,index) {
|
|
|
|
@ -158,6 +142,7 @@
|
|
|
|
confirmText: '确定',
|
|
|
|
confirmText: '确定',
|
|
|
|
success: ress => {
|
|
|
|
success: ress => {
|
|
|
|
if (ress.confirm) {
|
|
|
|
if (ress.confirm) {
|
|
|
|
|
|
|
|
that.$refs.swipeRef[index].close();
|
|
|
|
myCache(info.id,"");
|
|
|
|
myCache(info.id,"");
|
|
|
|
that.grouplist.splice(index, 1);
|
|
|
|
that.grouplist.splice(index, 1);
|
|
|
|
that.$forceUpdate();
|
|
|
|
that.$forceUpdate();
|
|
|
|
@ -185,8 +170,6 @@
|
|
|
|
// ws接收消息
|
|
|
|
// ws接收消息
|
|
|
|
socketinit(){
|
|
|
|
socketinit(){
|
|
|
|
var that = this;
|
|
|
|
var that = this;
|
|
|
|
// if (!that.isConnected) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
that.socketTask=uni.connectSocket({
|
|
|
|
that.socketTask=uni.connectSocket({
|
|
|
|
url: "wss://www.sanduolantoyoga.com/yoga-imserver/",
|
|
|
|
url: "wss://www.sanduolantoyoga.com/yoga-imserver/",
|
|
|
|
header: {
|
|
|
|
header: {
|
|
|
|
@ -207,7 +190,7 @@
|
|
|
|
uni.onSocketOpen(resopen => {
|
|
|
|
uni.onSocketOpen(resopen => {
|
|
|
|
console.log('WebSocket连接已打开!');
|
|
|
|
console.log('WebSocket连接已打开!');
|
|
|
|
that.isConnected = true;
|
|
|
|
that.isConnected = true;
|
|
|
|
that.$forceUpdate()
|
|
|
|
that.$forceUpdate();
|
|
|
|
uni.sendSocketMessage({
|
|
|
|
uni.sendSocketMessage({
|
|
|
|
data: JSON.stringify({
|
|
|
|
data: JSON.stringify({
|
|
|
|
"cmd": 0,//心跳
|
|
|
|
"cmd": 0,//心跳
|
|
|
|
@ -225,8 +208,49 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 发送心跳包
|
|
|
|
// 定时发送心跳包
|
|
|
|
this.startHeartbeat();
|
|
|
|
this.startHeartbeat();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 拉取离线消息
|
|
|
|
|
|
|
|
this.grouplist.forEach((cell,i)=>{
|
|
|
|
|
|
|
|
if(cell.minId){
|
|
|
|
|
|
|
|
// 通过某个会话中已读消息的最大id 获取离线消息
|
|
|
|
|
|
|
|
this.pullMessage(i,cell);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 已经删除的有最大id的继续拉取是否有消息
|
|
|
|
|
|
|
|
var data= myCache("privateMsgMaxId")?myCache("privateMsgMaxId"):[{id:0,minId:0}];
|
|
|
|
|
|
|
|
data.forEach((cell)=>{
|
|
|
|
|
|
|
|
console.log("privateMsgMaxId")
|
|
|
|
|
|
|
|
var ifcz=false;
|
|
|
|
|
|
|
|
this.grouplist.forEach((item)=>{
|
|
|
|
|
|
|
|
if(cell.id==item.id){
|
|
|
|
|
|
|
|
// 已经存在列表了,不用拉取离线信息
|
|
|
|
|
|
|
|
ifcz=true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if(!ifcz){
|
|
|
|
|
|
|
|
// 拉取离线信息
|
|
|
|
|
|
|
|
this.getList(cell);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data= myCache("groupMsgMaxId")?myCache("groupMsgMaxId"):[{id:0,minId:0}];
|
|
|
|
|
|
|
|
data.forEach((cell)=>{
|
|
|
|
|
|
|
|
var ifcz=false;
|
|
|
|
|
|
|
|
this.grouplist.forEach((item)=>{
|
|
|
|
|
|
|
|
if(cell.id==item.id){
|
|
|
|
|
|
|
|
// 已经存在列表了,不用拉取离线信息
|
|
|
|
|
|
|
|
ifcz=true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if(!ifcz){
|
|
|
|
|
|
|
|
// 拉取离线信息
|
|
|
|
|
|
|
|
this.getGroupList(cell);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
uni.onSocketMessage(res => {
|
|
|
|
uni.onSocketMessage(res => {
|
|
|
|
@ -246,19 +270,19 @@
|
|
|
|
data.content=decodeURIComponent(data.content);
|
|
|
|
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){
|
|
|
|
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;
|
|
|
|
var ifexist=0,chatinfo=null;
|
|
|
|
that.grouplist.forEach((cell,index)=>{
|
|
|
|
that.grouplist.forEach((cell,index)=>{
|
|
|
|
if(cell.fromuser==data.sendId&&cell.userid==data.recvId&&cell.sort=="privatechat"){
|
|
|
|
if(cell.fromuser==data.sendId&&cell.userid==data.recvId&&cell.sort=="privatechat"){
|
|
|
|
ifexist=1;
|
|
|
|
ifexist=1;
|
|
|
|
idx=index;
|
|
|
|
|
|
|
|
that.grouplist[index].sl=(that.grouplist[index].sl?that.grouplist[index].sl+1:1);
|
|
|
|
that.grouplist[index].sl=(that.grouplist[index].sl?that.grouplist[index].sl+1:1);
|
|
|
|
that.grouplist[index].content=data.content;
|
|
|
|
that.grouplist[index].content=data.content;
|
|
|
|
that.grouplist[index].datetime=data.sendTime;
|
|
|
|
that.grouplist[index].datetime=data.sendTime;
|
|
|
|
that.grouplist[index].type=data.type;
|
|
|
|
that.grouplist[index].type=data.type;
|
|
|
|
that.$forceUpdate();
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
|
|
|
chatinfo= JSON.parse(JSON.stringify(that.grouplist[index])) ;
|
|
|
|
|
|
|
|
console.log(chatinfo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if(ifexist==0){
|
|
|
|
if(ifexist==0){
|
|
|
|
// 未保存缓存
|
|
|
|
// 未保存缓存
|
|
|
|
// 接收到socket后更新聊天列表记录
|
|
|
|
// 接收到socket后更新聊天列表记录
|
|
|
|
@ -275,14 +299,15 @@
|
|
|
|
img: "",
|
|
|
|
img: "",
|
|
|
|
sort:"privatechat"
|
|
|
|
sort:"privatechat"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
that.updateChatList(chatlastinfo,ifexist);
|
|
|
|
that.updateChatList(chatlastinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
that.updateChatList(that.grouplist[idx],ifexist);
|
|
|
|
that.updateChatList(chatinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
// 10, "撤回" 11, "已读 " 12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
// 10, "撤回" 11, "已读 " 12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -332,14 +357,15 @@
|
|
|
|
sendNickName: data.sendNickName,
|
|
|
|
sendNickName: data.sendNickName,
|
|
|
|
sort:"groupchat"
|
|
|
|
sort:"groupchat"
|
|
|
|
};
|
|
|
|
};
|
|
|
|
that.getGroupInfo(chatlastinfo,ifexist);
|
|
|
|
that.getGroupInfo(chatlastinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
that.getGroupInfo(that.grouplist[idx],ifexist);
|
|
|
|
that.getGroupInfo(that.grouplist[idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
// 10, "撤回" 11, "已读 " 12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
// 10, "撤回" 11, "已读 " 12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -360,7 +386,6 @@
|
|
|
|
that.$forceUpdate();
|
|
|
|
that.$forceUpdate();
|
|
|
|
clearInterval(that.heartbeatInterval); // 停止心跳包发送
|
|
|
|
clearInterval(that.heartbeatInterval); // 停止心跳包发送
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// }
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 关闭WebSocket连接
|
|
|
|
// 关闭WebSocket连接
|
|
|
|
closeWebSocket() {
|
|
|
|
closeWebSocket() {
|
|
|
|
@ -368,6 +393,16 @@
|
|
|
|
this.isConnected = false;
|
|
|
|
this.isConnected = false;
|
|
|
|
this.$forceUpdate()
|
|
|
|
this.$forceUpdate()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// 消息是否存在列表中
|
|
|
|
|
|
|
|
ifadd(id){
|
|
|
|
|
|
|
|
var ret=0;
|
|
|
|
|
|
|
|
this.grouplist.forEach((cell,ii)=>{
|
|
|
|
|
|
|
|
if(cell.id==id){
|
|
|
|
|
|
|
|
ret=ii+1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
},
|
|
|
|
gotoContacts(){
|
|
|
|
gotoContacts(){
|
|
|
|
uni.navigateTo({
|
|
|
|
uni.navigateTo({
|
|
|
|
url: `/pages/message/contact`
|
|
|
|
url: `/pages/message/contact`
|
|
|
|
@ -440,21 +475,10 @@
|
|
|
|
// 获取群聊列表
|
|
|
|
// 获取群聊列表
|
|
|
|
async getgroupsmembers(){
|
|
|
|
async getgroupsmembers(){
|
|
|
|
// 获取聊天群列表
|
|
|
|
// 获取聊天群列表
|
|
|
|
this.grouplist=[];
|
|
|
|
this.grouplist=myCache("chatlist-"+this.userid)?myCache("chatlist-"+this.userid):[];
|
|
|
|
var chatlist=myCache("chatlist-"+this.userid)?myCache("chatlist-"+this.userid):[];
|
|
|
|
|
|
|
|
chatlist.forEach(cell=>{
|
|
|
|
|
|
|
|
if(cell.userid==this.userid){
|
|
|
|
|
|
|
|
this.grouplist.push(cell);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.grouplist.forEach((cell,i)=>{
|
|
|
|
|
|
|
|
if(cell.minId){
|
|
|
|
|
|
|
|
// 通过某个会话中已读消息的最大id 获取离线消息
|
|
|
|
|
|
|
|
this.readUp(i,cell);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.loadStatus="nomore";
|
|
|
|
this.loadStatus="nomore";
|
|
|
|
this.$forceUpdate();
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
// 按照时间排序
|
|
|
|
var that=this;
|
|
|
|
var that=this;
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
that.reorder();
|
|
|
|
that.reorder();
|
|
|
|
@ -469,20 +493,96 @@
|
|
|
|
this.grouplist.sort((a, b) => b.datetime - a.datetime);
|
|
|
|
this.grouplist.sort((a, b) => b.datetime - a.datetime);
|
|
|
|
this.$forceUpdate();
|
|
|
|
this.$forceUpdate();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 已读推送
|
|
|
|
// 拉取离线信息
|
|
|
|
async readUp(i,item) {
|
|
|
|
async pullMessage(i,item) {
|
|
|
|
if(item.sort=="groupchat"){
|
|
|
|
if(item.sort=="groupchat"){
|
|
|
|
const {data: res} = await uni.$http.put('/api/message/group/readed?groupId='+item.groupId);
|
|
|
|
|
|
|
|
this.getgroupsnums(i,item);
|
|
|
|
this.getgroupsnums(i,item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
const {data: res} = await uni.$http.put('/api/message/private/readed?friendId='+item.fromuser);
|
|
|
|
|
|
|
|
this.getgroupsnums(i,item);
|
|
|
|
this.getgroupsnums(i,item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// 拉取离线消息
|
|
|
|
|
|
|
|
async getGroupList(item) {
|
|
|
|
|
|
|
|
// 判断当前 minId 是不是列表中已经存在了,是不再拉取,不是继续拉取
|
|
|
|
|
|
|
|
var that=this;
|
|
|
|
|
|
|
|
const {data: res} = await uni.$http.get('/api/message/group/pullOfflineMessage',{minId: item.minId});
|
|
|
|
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
|
|
|
|
res.data.forEach((cell,index)=>{
|
|
|
|
|
|
|
|
// 获取消息后对消息进行缓存处理
|
|
|
|
|
|
|
|
var chatlastinfo={
|
|
|
|
|
|
|
|
id: "groupchat-" + cell.groupId,
|
|
|
|
|
|
|
|
groupId:cell.groupId,
|
|
|
|
|
|
|
|
content: cell.content,
|
|
|
|
|
|
|
|
minId: cell.id,
|
|
|
|
|
|
|
|
sl: index+1,
|
|
|
|
|
|
|
|
datetime: cell.sendTime,
|
|
|
|
|
|
|
|
type: cell.type,
|
|
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
|
|
userid: this.userid,
|
|
|
|
|
|
|
|
fromuser: cell.sendId,
|
|
|
|
|
|
|
|
img: "",
|
|
|
|
|
|
|
|
sendId: cell.sendId,
|
|
|
|
|
|
|
|
sendNickName: cell.sendNickName,
|
|
|
|
|
|
|
|
sort:"groupchat"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getGroupInfo(chatlastinfo,index);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 拉取离线消息
|
|
|
|
|
|
|
|
async getList(item) {
|
|
|
|
|
|
|
|
// 判断当前 minId 是不是列表中已经存在了,是不再拉取,不是继续拉取
|
|
|
|
|
|
|
|
var that=this;
|
|
|
|
|
|
|
|
const {data: res} = await uni.$http.get('/api/message/private/pullOfflineMessage',{minId: item.minId});
|
|
|
|
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
|
|
|
|
res.data.forEach((cell,index)=>{
|
|
|
|
|
|
|
|
// 获取消息后对消息进行缓存处理
|
|
|
|
|
|
|
|
var chatlastinfo={
|
|
|
|
|
|
|
|
id: "privatechat-" + cell.recvId +"-" + cell.sendId,
|
|
|
|
|
|
|
|
content: cell.content,
|
|
|
|
|
|
|
|
minId: cell.id,
|
|
|
|
|
|
|
|
sl:index+1,
|
|
|
|
|
|
|
|
datetime: cell.sendTime,
|
|
|
|
|
|
|
|
type: cell.type,
|
|
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
|
|
userid: cell.recvId,
|
|
|
|
|
|
|
|
fromuser: cell.sendId,
|
|
|
|
|
|
|
|
img: "",
|
|
|
|
|
|
|
|
sort:"privatechat"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
this.updateChatList(chatlastinfo,index);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
ifprivateMsgMaxId(item){
|
|
|
|
|
|
|
|
var ret=true;
|
|
|
|
|
|
|
|
// 判断当前 minId 是不是列表中已经存在了,是不再拉取,不是继续拉取
|
|
|
|
|
|
|
|
var data= myCache("privateMsgMaxId")?myCache("privateMsgMaxId"):[];
|
|
|
|
|
|
|
|
data.forEach((cell)=>{
|
|
|
|
|
|
|
|
if(cell.id==item.id&&parseInt(item.minId)>=parseInt(cell.minId)){
|
|
|
|
|
|
|
|
ret=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
ifgroupMsgMaxId(item){
|
|
|
|
|
|
|
|
console.log("ifgroupMsgMaxId")
|
|
|
|
|
|
|
|
var ret=true;
|
|
|
|
|
|
|
|
// 判断当前 minId 是不是列表中已经存在了,是不再拉取,不是继续拉取
|
|
|
|
|
|
|
|
var data= myCache("groupMsgMaxId")?myCache("groupMsgMaxId"):[];
|
|
|
|
|
|
|
|
data.forEach((cell)=>{
|
|
|
|
|
|
|
|
if(cell.id==item.id&&parseInt(item.minId)>=parseInt(cell.minId)){
|
|
|
|
|
|
|
|
ret=false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
},
|
|
|
|
// 获取群聊中离线信息
|
|
|
|
// 获取群聊中离线信息
|
|
|
|
async getgroupsnums(i,item){
|
|
|
|
async getgroupsnums(i,item){
|
|
|
|
if(item.sort=="groupchat"){
|
|
|
|
if(item.sort=="groupchat"){
|
|
|
|
|
|
|
|
// 判断当前 minId 是不是列表中已经存在了,是不再拉取,不是继续拉取
|
|
|
|
|
|
|
|
// if(this.ifgroupMsgMaxId(item)){
|
|
|
|
// 群聊
|
|
|
|
// 群聊
|
|
|
|
const {data: res} = await uni.$http.get("/api/message/group/pullOfflineMessage",{minId:item.minId});
|
|
|
|
const {data: res} = await uni.$http.get("/api/message/group/pullOfflineMessage",{minId:item.minId});
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
@ -504,8 +604,11 @@
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
|
|
|
|
// 判断当前 minId 是不是列表中已经存在了,是不再拉取,不是继续拉取
|
|
|
|
|
|
|
|
// if(this.ifprivateMsgMaxId(item)){
|
|
|
|
// 私聊
|
|
|
|
// 私聊
|
|
|
|
const {data: res} = await uni.$http.get("/api/message/private/pullOfflineMessage",{minId:item.minId});
|
|
|
|
const {data: res} = await uni.$http.get("/api/message/private/pullOfflineMessage",{minId:item.minId});
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
@ -527,10 +630,11 @@
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 获取群信息
|
|
|
|
// 获取群信息
|
|
|
|
async getGroupInfo(info,ifexist) {
|
|
|
|
async getGroupInfo(info) {
|
|
|
|
const {data: res} = await uni.$http.get('/api/group/find/'+info.groupId);
|
|
|
|
const {data: res} = await uni.$http.get('/api/group/find/'+info.groupId);
|
|
|
|
if(res.data){
|
|
|
|
if(res.data){
|
|
|
|
var data = res.data;
|
|
|
|
var data = res.data;
|
|
|
|
@ -545,26 +649,34 @@
|
|
|
|
info.instructor=data.instructor;
|
|
|
|
info.instructor=data.instructor;
|
|
|
|
info.productId=data.productId;
|
|
|
|
info.productId=data.productId;
|
|
|
|
info.productName=data.productName;
|
|
|
|
info.productName=data.productName;
|
|
|
|
this.updateChatGroupList(info,ifexist);
|
|
|
|
this.updateChatGroupList(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async updateChatGroupList(info,ifexist){
|
|
|
|
async updateChatGroupList(info){
|
|
|
|
var name=info.name,img=info.img||require("@/static/image/girl.png");
|
|
|
|
var name=info.name,img=info.img||require("@/static/image/girl.png");
|
|
|
|
const {data: res} = await uni.$http.get("/api/friend/find/"+info.sendId);
|
|
|
|
const {data: res} = await uni.$http.get("/api/friend/find/"+info.sendId);
|
|
|
|
if(res.data){
|
|
|
|
if(res.data){
|
|
|
|
var data=res.data;
|
|
|
|
var data=res.data;
|
|
|
|
name=data.nickName?data.nickName:"匿名";
|
|
|
|
name=data.nickName?data.nickName:"匿名";
|
|
|
|
img=data.headImage?data.headImage:require("@/static/image/girl.png");
|
|
|
|
img=data.headImage?data.headImage:require("@/static/image/girl.png");
|
|
|
|
if(ifexist==0){
|
|
|
|
var idx=this.ifadd(info.id);
|
|
|
|
|
|
|
|
if(!idx){
|
|
|
|
this.grouplist.push(info);
|
|
|
|
this.grouplist.push(info);
|
|
|
|
this.$forceUpdate();
|
|
|
|
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.reorder();
|
|
|
|
this.reorder();
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
// 聊天框消息缓存
|
|
|
|
// 聊天框消息缓存
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
if(ifexist==0||!msgchat){
|
|
|
|
if(!msgchat){
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
let firstmsg = [{
|
|
|
|
let firstmsg = [{
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
@ -610,15 +722,23 @@
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
name="匿名";
|
|
|
|
name="匿名";
|
|
|
|
img="../../static/image/girl.png";
|
|
|
|
img="../../static/image/girl.png";
|
|
|
|
if(ifexist==0){
|
|
|
|
var idx=this.ifadd(info.id);
|
|
|
|
|
|
|
|
if(!idx){
|
|
|
|
this.grouplist.push(info);
|
|
|
|
this.grouplist.push(info);
|
|
|
|
this.$forceUpdate();
|
|
|
|
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.reorder();
|
|
|
|
this.reorder();
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
if(ifexist==0||!msgchat){
|
|
|
|
if(!msgchat){
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
let firstmsg = [{
|
|
|
|
let firstmsg = [{
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
"fromname": name, // 发送人
|
|
|
|
@ -661,22 +781,31 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async updateChatList(info,ifexist){
|
|
|
|
async updateChatList(info){
|
|
|
|
const {data: res} = await uni.$http.get("/api/friend/find/"+info.fromuser);
|
|
|
|
const {data: res} = await uni.$http.get("/api/friend/find/"+info.fromuser);
|
|
|
|
if(res.data){
|
|
|
|
if(res.data){
|
|
|
|
var data=res.data;
|
|
|
|
var data=res.data;
|
|
|
|
info.name=data.nickName?data.nickName:"匿名";
|
|
|
|
info.name=data.nickName?data.nickName:"匿名";
|
|
|
|
info.img=data.headImage?data.headImage:require("@/static/image/girl.png");
|
|
|
|
info.img=data.headImage?data.headImage:require("@/static/image/girl.png");
|
|
|
|
if(ifexist==0){
|
|
|
|
var idx=this.ifadd(info.id);
|
|
|
|
|
|
|
|
if(!idx){
|
|
|
|
this.grouplist.push(info);
|
|
|
|
this.grouplist.push(info);
|
|
|
|
this.$forceUpdate();
|
|
|
|
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();
|
|
|
|
this.reorder();
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
// 聊天框消息缓存
|
|
|
|
// 聊天框消息缓存
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
if(ifexist==0||!msgchat){
|
|
|
|
if(!msgchat){
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
let firstmsg = [{
|
|
|
|
let firstmsg = [{
|
|
|
|
"fromname": info.name, // 发送人
|
|
|
|
"fromname": info.name, // 发送人
|
|
|
|
@ -723,15 +852,26 @@
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
info.name="匿名";
|
|
|
|
info.name="匿名";
|
|
|
|
info.img="../../static/image/girl.png";
|
|
|
|
info.img="../../static/image/girl.png";
|
|
|
|
if(ifexist==0){
|
|
|
|
var idx=this.ifadd(info.id);
|
|
|
|
|
|
|
|
if(!idx){
|
|
|
|
this.grouplist.push(info);
|
|
|
|
this.grouplist.push(info);
|
|
|
|
this.$forceUpdate();
|
|
|
|
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();
|
|
|
|
this.reorder();
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
myCache("chatlist-"+this.userid,this.grouplist);
|
|
|
|
|
|
|
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
if(ifexist==0||!msgchat){
|
|
|
|
console.log(info.id,msgchat);
|
|
|
|
|
|
|
|
if(!msgchat){
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
// 第一条聊天记录保存缓存
|
|
|
|
let firstmsg = [{
|
|
|
|
let firstmsg = [{
|
|
|
|
"fromname": info.name, // 发送人
|
|
|
|
"fromname": info.name, // 发送人
|
|
|
|
@ -880,6 +1020,7 @@
|
|
|
|
background: #fff;
|
|
|
|
background: #fff;
|
|
|
|
margin: 0;
|
|
|
|
margin: 0;
|
|
|
|
width: 100%;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
min-width: 600rpx;
|
|
|
|
.lcon{
|
|
|
|
.lcon{
|
|
|
|
border-bottom: 1rpx solid #eee;
|
|
|
|
border-bottom: 1rpx solid #eee;
|
|
|
|
padding-top: 20rpx;
|
|
|
|
padding-top: 20rpx;
|
|
|
|
@ -939,6 +1080,12 @@
|
|
|
|
font-family: PingFang SC, PingFang SC;
|
|
|
|
font-family: PingFang SC, PingFang SC;
|
|
|
|
font-weight: 400;
|
|
|
|
font-weight: 400;
|
|
|
|
color: #595959;
|
|
|
|
color: #595959;
|
|
|
|
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
|
|
/* 假设你的行高是20px,并且你想要两行显示 */
|
|
|
|
|
|
|
|
line-height: 40rpx; /* 每行的行高 */
|
|
|
|
|
|
|
|
max-height: 40rpx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.lnum{
|
|
|
|
.lnum{
|
|
|
|
background-color: #de0000;
|
|
|
|
background-color: #de0000;
|
|
|
|
|