|
|
|
@ -6,35 +6,38 @@
|
|
|
|
<uni-icons type="staff-filled" size="30" color="#ffffff" @click="$u.throttle(gotoContacts(), 2000)"></uni-icons>
|
|
|
|
<uni-icons type="staff-filled" size="30" color="#ffffff" @click="$u.throttle(gotoContacts(), 2000)"></uni-icons>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<view class="wrapcon">
|
|
|
|
<view class="wrapcon">
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 列表 -->
|
|
|
|
<!-- 列表 -->
|
|
|
|
<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">
|
|
|
|
<view class="lcon" v-for="(info, index) in grouplist" :key="index" @click="gotoGroup(info)">
|
|
|
|
<u-swipe-action :options="options" v-for="(info, index) in grouplist" :key="index" @click="$u.throttle(actionClick(info,index), 2000)" >
|
|
|
|
<view class="limg">
|
|
|
|
<view class="lcon" @click="gotoGroup(info,index)">
|
|
|
|
<image class="img" :src="info.img" mode="aspectFill"></image>
|
|
|
|
<view class="limg">
|
|
|
|
</view>
|
|
|
|
<image class="img" :src="info.img" mode="aspectFill"></image>
|
|
|
|
<view class="lright">
|
|
|
|
|
|
|
|
<view class="lrow">
|
|
|
|
|
|
|
|
<view class="pname">{{info.name}}</view>
|
|
|
|
|
|
|
|
<view class="ptime"> {{ changeTime(info.datetime)}}</view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
<view class="lrow">
|
|
|
|
|
|
|
|
<view class="pnr">
|
|
|
|
|
|
|
|
{{info.content}}
|
|
|
|
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<!-- <view class="lnum">
|
|
|
|
<view class="lright">
|
|
|
|
{{ getgroupsnums(info.minId)}}
|
|
|
|
<view class="lrow">
|
|
|
|
</view> -->
|
|
|
|
<view class="pname">{{info.name}}</view>
|
|
|
|
<view class="lnum" v-if="info.sl>0">
|
|
|
|
<view class="ptime"> {{ changeTime(info.datetime)}}</view>
|
|
|
|
{{ info.sl}}
|
|
|
|
</view>
|
|
|
|
|
|
|
|
<view class="lrow">
|
|
|
|
|
|
|
|
<view class="pnr">
|
|
|
|
|
|
|
|
{{ info.type==0?info.content:(info.type==1?"图片":(info.type==2?"文件":(info.type==3?"语音":(info.type==4?"视频":
|
|
|
|
|
|
|
|
(info.type==5?"订单咨询":(info.type==6?"商品咨询":info.content))))))}}
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
<view class="lnum" v-if="info.sl>0">
|
|
|
|
|
|
|
|
{{ info.sl}}
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</u-swipe-action>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<u-loadmore v-if="grouplist.length==0 && loadStatus=='loading'" :status="loadStatus" :marginTop="20"></u-loadmore>
|
|
|
|
<u-loadmore v-if="grouplist.length==0 && loadStatus=='loading'" :status="loadStatus" :marginTop="20"></u-loadmore>
|
|
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
@ -53,92 +56,47 @@
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
|
|
|
|
openId:"",
|
|
|
|
|
|
|
|
phone:"",
|
|
|
|
|
|
|
|
userid:"",
|
|
|
|
|
|
|
|
userName:"",
|
|
|
|
|
|
|
|
userheadimg:"",
|
|
|
|
messageText:'', //错误提示框
|
|
|
|
messageText:'', //错误提示框
|
|
|
|
msgType :'error',
|
|
|
|
msgType :'error',
|
|
|
|
loadStatus:'loadmore',
|
|
|
|
loadStatus:'loadmore',
|
|
|
|
|
|
|
|
options: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
text: '删除',
|
|
|
|
|
|
|
|
style: {
|
|
|
|
|
|
|
|
backgroundColor: '#ed2a28'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
], //u-swipe-action样式
|
|
|
|
imgurl:uni.$http.baseUrl,
|
|
|
|
imgurl:uni.$http.baseUrl,
|
|
|
|
grouplist:[
|
|
|
|
grouplist:[],
|
|
|
|
// {
|
|
|
|
socketTask: null,
|
|
|
|
// id:1,
|
|
|
|
isConnected: false, // WebSocket连接状态
|
|
|
|
// sl:25,
|
|
|
|
socketmsg:[],//接收信息
|
|
|
|
// name:"商城客服-伽伽",
|
|
|
|
heartbeatInterval: null, // 心跳包20秒连接一次
|
|
|
|
// img:"../../static/image/girl.jpg",
|
|
|
|
heartbeatTimeout: 20000, // 心跳间隔时间,例如每20秒发送一次
|
|
|
|
// content:"测试信息1",
|
|
|
|
|
|
|
|
// datetime:"2025-07-10 12:18",
|
|
|
|
|
|
|
|
// type:1, // 客服
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// id:2,
|
|
|
|
|
|
|
|
// sl:8,
|
|
|
|
|
|
|
|
// name:"教练A",
|
|
|
|
|
|
|
|
// img:"../../static/image/girl.jpg",
|
|
|
|
|
|
|
|
// content:"测试信息2",
|
|
|
|
|
|
|
|
// datetime:"2025-07-05 12:18",
|
|
|
|
|
|
|
|
// type:2, // 老师
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// id:1,
|
|
|
|
|
|
|
|
// sl:25,
|
|
|
|
|
|
|
|
// name:"商城客服-伽伽",
|
|
|
|
|
|
|
|
// img:"../../static/image/girl.jpg",
|
|
|
|
|
|
|
|
// content:"测试信息1",
|
|
|
|
|
|
|
|
// datetime:"2025-07-10 12:18",
|
|
|
|
|
|
|
|
// type:1, // 客服
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// id:2,
|
|
|
|
|
|
|
|
// sl:8,
|
|
|
|
|
|
|
|
// name:"教练A",
|
|
|
|
|
|
|
|
// img:"../../static/image/girl.jpg",
|
|
|
|
|
|
|
|
// content:"测试信息2",
|
|
|
|
|
|
|
|
// datetime:"2025-07-05 12:18",
|
|
|
|
|
|
|
|
// type:2, // 老师
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// id:1,
|
|
|
|
|
|
|
|
// sl:25,
|
|
|
|
|
|
|
|
// name:"商城客服-伽伽",
|
|
|
|
|
|
|
|
// img:"../../static/image/girl.jpg",
|
|
|
|
|
|
|
|
// content:"测试信息1",
|
|
|
|
|
|
|
|
// datetime:"2025-07-10 12:18",
|
|
|
|
|
|
|
|
// type:1, // 客服
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// id:2,
|
|
|
|
|
|
|
|
// sl:8,
|
|
|
|
|
|
|
|
// name:"教练A",
|
|
|
|
|
|
|
|
// img:"../../static/image/girl.jpg",
|
|
|
|
|
|
|
|
// content:"测试信息2",
|
|
|
|
|
|
|
|
// datetime:"2025-07-05 12:18",
|
|
|
|
|
|
|
|
// type:2, // 老师
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// id:1,
|
|
|
|
|
|
|
|
// sl:25,
|
|
|
|
|
|
|
|
// name:"商城客服-伽伽",
|
|
|
|
|
|
|
|
// img:"../../static/image/girl.jpg",
|
|
|
|
|
|
|
|
// content:"测试信息1",
|
|
|
|
|
|
|
|
// datetime:"2025-07-10 12:18",
|
|
|
|
|
|
|
|
// type:1, // 客服
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// id:2,
|
|
|
|
|
|
|
|
// sl:8,
|
|
|
|
|
|
|
|
// name:"教练A",
|
|
|
|
|
|
|
|
// img:"../../static/image/girl.jpg",
|
|
|
|
|
|
|
|
// content:"测试信息2",
|
|
|
|
|
|
|
|
// datetime:"2025-07-05 12:18",
|
|
|
|
|
|
|
|
// type:2, // 老师
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onLoad(options) {
|
|
|
|
onLoad(options) {
|
|
|
|
// this.getgroupsmembers();
|
|
|
|
// socket接收信息初始化
|
|
|
|
|
|
|
|
// this.socketinit();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onShow(){
|
|
|
|
onShow(){
|
|
|
|
this.loadStatus='loadmore';
|
|
|
|
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); // 停止心跳包发送
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 从缓存聊天群里获取聊天群列表 chatlist
|
|
|
|
this.loadData();
|
|
|
|
this.loadData();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onPullDownRefresh() {
|
|
|
|
onPullDownRefresh() {
|
|
|
|
@ -147,12 +105,250 @@
|
|
|
|
uni.stopPullDownRefresh()
|
|
|
|
uni.stopPullDownRefresh()
|
|
|
|
},500);
|
|
|
|
},500);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onReachBottom() {
|
|
|
|
onBackPress(options) {
|
|
|
|
console.log('onReachBottom');
|
|
|
|
if (options.from === 'backbutton') {
|
|
|
|
// 暂不分页
|
|
|
|
// 来自顶部菜单的返回按钮
|
|
|
|
// this.loadData();
|
|
|
|
// 在这里处理你的逻辑
|
|
|
|
|
|
|
|
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: {
|
|
|
|
methods: {
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
|
|
|
actionClick(info,index) {
|
|
|
|
|
|
|
|
console.log(info,index);
|
|
|
|
|
|
|
|
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",that.grouplist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 定时心跳包
|
|
|
|
|
|
|
|
startHeartbeat() {
|
|
|
|
|
|
|
|
console.log("startHeartbeat")
|
|
|
|
|
|
|
|
this.heartbeatInterval = setInterval(() => {
|
|
|
|
|
|
|
|
if (this.socketTask) {
|
|
|
|
|
|
|
|
this.socketTask.send({
|
|
|
|
|
|
|
|
data: JSON.stringify({
|
|
|
|
|
|
|
|
'cmd': 1,//心跳
|
|
|
|
|
|
|
|
'data': {
|
|
|
|
|
|
|
|
'accessToken':uni.getStorageSync("token")
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}) // 发送心跳包数据
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, this.heartbeatTimeout);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// ws接收消息
|
|
|
|
|
|
|
|
socketinit(){
|
|
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
// if (!that.isConnected) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
that.socketTask=uni.connectSocket({
|
|
|
|
|
|
|
|
url: "wss://www.sanduolantoyoga.com/yoga-imserver/",
|
|
|
|
|
|
|
|
header: {
|
|
|
|
|
|
|
|
// 'content-type': 'application/json',
|
|
|
|
|
|
|
|
Authorization: uni.getStorageSync("token"),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
|
|
console.log(res, 'socket连接成功success');
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
fail: (res) => {
|
|
|
|
|
|
|
|
console.log(res, 'socket连接失败')
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
complete: (res) => {
|
|
|
|
|
|
|
|
console.log(res,'socket连接成功complete');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uni.onSocketOpen(resopen => {
|
|
|
|
|
|
|
|
console.log('WebSocket连接已打开!');
|
|
|
|
|
|
|
|
that.isConnected = true;
|
|
|
|
|
|
|
|
that.$forceUpdate()
|
|
|
|
|
|
|
|
uni.sendSocketMessage({
|
|
|
|
|
|
|
|
data: JSON.stringify({
|
|
|
|
|
|
|
|
"cmd": 0,//心跳
|
|
|
|
|
|
|
|
"data": {
|
|
|
|
|
|
|
|
"accessToken":uni.getStorageSync("token"),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}), // 发送心跳包数据 // 发送的消息内容
|
|
|
|
|
|
|
|
success(re) {
|
|
|
|
|
|
|
|
console.log(re);
|
|
|
|
|
|
|
|
console.log('消息发送成功!')
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
|
|
console.log('消息发送失败!')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 发送心跳包
|
|
|
|
|
|
|
|
this.startHeartbeat();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uni.onSocketMessage(res => {
|
|
|
|
|
|
|
|
console.log('收到WebSocket服务器消息:');
|
|
|
|
|
|
|
|
if(res.data){
|
|
|
|
|
|
|
|
var rs=JSON.parse(res.data);
|
|
|
|
|
|
|
|
console.log(rs);
|
|
|
|
|
|
|
|
if(rs.cmd==3){
|
|
|
|
|
|
|
|
// 私聊
|
|
|
|
|
|
|
|
if(rs.data){
|
|
|
|
|
|
|
|
var data=rs.data;
|
|
|
|
|
|
|
|
if(data.recvId&&(data.recvId).toString()==(that.userid).toString()){
|
|
|
|
|
|
|
|
// 是这个用户的接收的私聊信息
|
|
|
|
|
|
|
|
// 加入聊天记录
|
|
|
|
|
|
|
|
// 消息类型 0:文字 1:图片 2:文件 3:语音 4:视频 10, "撤回" 11, "已读 "12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
|
|
|
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.fromuser==data.sendId&&cell.userid==data.recvId&&cell.sort=="privatechat"){
|
|
|
|
|
|
|
|
ifexist=1;
|
|
|
|
|
|
|
|
idx=index;
|
|
|
|
|
|
|
|
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.$forceUpdate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ifexist==0){
|
|
|
|
|
|
|
|
// 未保存缓存
|
|
|
|
|
|
|
|
// 接收到socket后更新聊天列表记录
|
|
|
|
|
|
|
|
var chatlastinfo={
|
|
|
|
|
|
|
|
id: "privatechat-" + data.recvId +"-" + data.sendId,
|
|
|
|
|
|
|
|
content: data.content,
|
|
|
|
|
|
|
|
minId: data.id,
|
|
|
|
|
|
|
|
sl:1,
|
|
|
|
|
|
|
|
datetime: data.sendTime,
|
|
|
|
|
|
|
|
type: data.type,
|
|
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
|
|
userid: data.recvId,
|
|
|
|
|
|
|
|
fromuser: data.sendId,
|
|
|
|
|
|
|
|
img: "",
|
|
|
|
|
|
|
|
sort:"privatechat"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
that.updateChatList(chatlastinfo,ifexist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
that.updateChatList(that.grouplist[idx],ifexist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
// 10, "撤回" 11, "已读 " 12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(rs.cmd==4){
|
|
|
|
|
|
|
|
// 群聊
|
|
|
|
|
|
|
|
if(rs.data){
|
|
|
|
|
|
|
|
var data=rs.data;
|
|
|
|
|
|
|
|
if(data.atUserIds&&data.atUserIds.includes(that.userid)){
|
|
|
|
|
|
|
|
// 是这个用户的接收的群聊信息
|
|
|
|
|
|
|
|
// 加入聊天记录
|
|
|
|
|
|
|
|
// 消息类型 0:文字 1:图片 2:文件 3:语音 4:视频 10, "撤回" 11, "已读 "12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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.$forceUpdate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ifexist==0){
|
|
|
|
|
|
|
|
// 未保存缓存
|
|
|
|
|
|
|
|
// 接收到socket后更新聊天列表记录
|
|
|
|
|
|
|
|
var chatlastinfo={
|
|
|
|
|
|
|
|
id: "groupchat-" + data.groupId,
|
|
|
|
|
|
|
|
groupId:data.groupId,
|
|
|
|
|
|
|
|
content: data.content,
|
|
|
|
|
|
|
|
minId: data.id,
|
|
|
|
|
|
|
|
sl:1,
|
|
|
|
|
|
|
|
datetime: data.sendTime,
|
|
|
|
|
|
|
|
type: data.type,
|
|
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
|
|
userid: this.userid,
|
|
|
|
|
|
|
|
fromuser: data.sendId,
|
|
|
|
|
|
|
|
img: "",
|
|
|
|
|
|
|
|
sendId: data.sendId,
|
|
|
|
|
|
|
|
sendNickName: data.sendNickName,
|
|
|
|
|
|
|
|
sort:"groupchat"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
that.getGroupInfo(chatlastinfo,ifexist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
that.getGroupInfo(that.grouplist[idx],ifexist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
// 10, "撤回" 11, "已读 " 12, "消息已读回执 " 30,"加载中标记"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uni.onSocketClose(res => {
|
|
|
|
|
|
|
|
console.log('WebSocket连接已关闭!',res);
|
|
|
|
|
|
|
|
that.isConnected = false;
|
|
|
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
|
|
|
clearInterval(that.heartbeatInterval); // 停止心跳包发送
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uni.onSocketError(err => {
|
|
|
|
|
|
|
|
console.error('WebSocket连接打开失败,请检查:', err);
|
|
|
|
|
|
|
|
that.isConnected = false;
|
|
|
|
|
|
|
|
that.$forceUpdate();
|
|
|
|
|
|
|
|
clearInterval(that.heartbeatInterval); // 停止心跳包发送
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 关闭WebSocket连接
|
|
|
|
|
|
|
|
closeWebSocket() {
|
|
|
|
|
|
|
|
uni.closeSocket();
|
|
|
|
|
|
|
|
this.isConnected = false;
|
|
|
|
|
|
|
|
this.$forceUpdate()
|
|
|
|
|
|
|
|
},
|
|
|
|
gotoContacts(){
|
|
|
|
gotoContacts(){
|
|
|
|
uni.navigateTo({
|
|
|
|
uni.navigateTo({
|
|
|
|
url: `/pages/message/contact`
|
|
|
|
url: `/pages/message/contact`
|
|
|
|
@ -161,57 +357,448 @@
|
|
|
|
changeTime(date) {
|
|
|
|
changeTime(date) {
|
|
|
|
return dateTime.dateTime(date);
|
|
|
|
return dateTime.dateTime(date);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
gotoGroup(info){
|
|
|
|
gotoGroup(chat,index){
|
|
|
|
|
|
|
|
// 当前消息未读数据消除
|
|
|
|
|
|
|
|
this.grouplist[index]["sl"]=0;
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
myCache("chatlist",this.grouplist);
|
|
|
|
// 去聊天室
|
|
|
|
// 去聊天室
|
|
|
|
if(info.type==1){
|
|
|
|
if(chat.sort=="privatechat"){
|
|
|
|
// 客服
|
|
|
|
// 私聊
|
|
|
|
|
|
|
|
var info={
|
|
|
|
|
|
|
|
chatId: chat.id,
|
|
|
|
|
|
|
|
chatName: chat.name,
|
|
|
|
|
|
|
|
chatAvatar: chat.img,
|
|
|
|
|
|
|
|
chatTime: chat.datetime,
|
|
|
|
|
|
|
|
friendId: chat.fromuser,
|
|
|
|
|
|
|
|
minId: chat.minId,
|
|
|
|
|
|
|
|
sort:"privatechat",
|
|
|
|
|
|
|
|
from:"message" // yh 用户咨询进入聊天框,message 从消息进入聊天框
|
|
|
|
|
|
|
|
}
|
|
|
|
var data=encodeURIComponent(JSON.stringify(info));
|
|
|
|
var data=encodeURIComponent(JSON.stringify(info));
|
|
|
|
uni.navigateTo({
|
|
|
|
uni.navigateTo({
|
|
|
|
url: `/pages/product/service?data=${data}`
|
|
|
|
url: `/pages/chat/chat?data=${data}`
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(info.type==2){
|
|
|
|
else if(chat.sort=="groupchat"){
|
|
|
|
// 老师
|
|
|
|
// 群聊
|
|
|
|
|
|
|
|
var info={
|
|
|
|
|
|
|
|
chatId: chat.id,
|
|
|
|
|
|
|
|
groupId: chat.groupId,
|
|
|
|
|
|
|
|
chatName: chat.name,
|
|
|
|
|
|
|
|
chatAvatar: chat.img,
|
|
|
|
|
|
|
|
chatTime: chat.datetime,
|
|
|
|
|
|
|
|
friendId: chat.fromuser,
|
|
|
|
|
|
|
|
teacherId: chat.teacherId,
|
|
|
|
|
|
|
|
minId: chat.minId,
|
|
|
|
|
|
|
|
sort:"groupchat", // privatechat 私聊 groupchat 群聊
|
|
|
|
|
|
|
|
from:"message", // yh 用户咨询进入聊天框,message 从消息进入聊天框
|
|
|
|
|
|
|
|
notice: chat.notice,
|
|
|
|
|
|
|
|
remarkNickName: chat.remarkNickName,
|
|
|
|
|
|
|
|
showNickName: chat.showNickName,
|
|
|
|
|
|
|
|
showGroupName: chat.showGroupName,
|
|
|
|
|
|
|
|
remarkGroupName: chat.remarkGroupName,
|
|
|
|
|
|
|
|
reason: chat.reason,
|
|
|
|
|
|
|
|
customerService: chat.customerService,
|
|
|
|
|
|
|
|
instructor: chat.instructor,
|
|
|
|
|
|
|
|
productId: chat.productId,
|
|
|
|
|
|
|
|
productName: chat.productName
|
|
|
|
|
|
|
|
}
|
|
|
|
var data=encodeURIComponent(JSON.stringify(info));
|
|
|
|
var data=encodeURIComponent(JSON.stringify(info));
|
|
|
|
|
|
|
|
console.log(data);
|
|
|
|
uni.navigateTo({
|
|
|
|
uni.navigateTo({
|
|
|
|
url: `/pages/teacher/chat?data=${data}`
|
|
|
|
url: `/pages/chat/groupchat?data=${data}`
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
loadData(){
|
|
|
|
loadData(){
|
|
|
|
// 底部数据加载
|
|
|
|
// 信息列表加载
|
|
|
|
if(this.loadStatus=="loadmore") {
|
|
|
|
this.loadStatus="loading";
|
|
|
|
this.loadStatus="loading";
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.getgroupsmembers();
|
|
|
|
this.getgroupsmembers();
|
|
|
|
}, 300);
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 获取群聊
|
|
|
|
// 获取群聊列表
|
|
|
|
async getgroupsmembers(){
|
|
|
|
async getgroupsmembers(){
|
|
|
|
if(this.loadStatus!=="nomore")
|
|
|
|
// 获取聊天群列表
|
|
|
|
{
|
|
|
|
this.grouplist=[];
|
|
|
|
this.loadStatus="nomore";
|
|
|
|
var chatlist=myCache("chatlist")?myCache("chatlist"):[];
|
|
|
|
var chatlist=myCache("chatlist");
|
|
|
|
chatlist.forEach(cell=>{
|
|
|
|
this.grouplist=chatlist?chatlist:[];
|
|
|
|
if(cell.userid==this.userid){
|
|
|
|
this.grouplist.forEach((cell,i)=>{
|
|
|
|
this.grouplist.push(cell);
|
|
|
|
this.grouplist[i]["sl"]=this.getgroupsnums(cell.minId)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.loadStatus="nomore";
|
|
|
|
this.grouplist.forEach((cell,i)=>{
|
|
|
|
this.$forceUpdate();
|
|
|
|
if(cell.minId){
|
|
|
|
|
|
|
|
// 通过某个会话中已读消息的最大id 获取离线消息
|
|
|
|
|
|
|
|
this.readUp(i,cell);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.loadStatus="nomore";
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
var that=this;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
|
|
that.reorder();
|
|
|
|
|
|
|
|
myCache("chatlist",that.grouplist);
|
|
|
|
|
|
|
|
}, 300);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// socket接收实时消息
|
|
|
|
|
|
|
|
this.socketinit();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 重新排序
|
|
|
|
|
|
|
|
reorder(){
|
|
|
|
|
|
|
|
this.grouplist.sort((a, b) => b.datetime - a.datetime);
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 已读推送
|
|
|
|
|
|
|
|
async readUp(i,item) {
|
|
|
|
|
|
|
|
if(item.sort=="groupchat"){
|
|
|
|
|
|
|
|
const {data: res} = await uni.$http.put('/api/message/group/readed?groupId='+item.groupId);
|
|
|
|
|
|
|
|
this.getgroupsnums(i,item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
const {data: res} = await uni.$http.put('/api/message/private/readed?friendId='+item.fromuser);
|
|
|
|
|
|
|
|
this.getgroupsnums(i,item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 获取群聊中离线信息
|
|
|
|
|
|
|
|
async getgroupsnums(i,item){
|
|
|
|
|
|
|
|
if(item.sort=="groupchat"){
|
|
|
|
|
|
|
|
// 群聊
|
|
|
|
|
|
|
|
const {data: res} = await uni.$http.get("/api/message/group/pullOfflineMessage",{minId:item.minId});
|
|
|
|
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
|
|
|
|
// 获取消息后对消息进行缓存处理
|
|
|
|
|
|
|
|
var data=res.data;
|
|
|
|
|
|
|
|
// 获取离线消息数量返回
|
|
|
|
|
|
|
|
this.grouplist[i]["sl"]=res.data.length;
|
|
|
|
|
|
|
|
var last=res.data[res.data.length-1];
|
|
|
|
|
|
|
|
if(last.type==0){
|
|
|
|
|
|
|
|
last.content=decodeURIComponent(last.content);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(last.type==0||last.type==1||last.type==2||last.type==3||last.type==4||data.type==5||data.type==6){
|
|
|
|
|
|
|
|
this.grouplist[i].content=last.content;
|
|
|
|
|
|
|
|
this.grouplist[i].type=last.type;
|
|
|
|
|
|
|
|
this.grouplist[i].datetime=last.datetime;
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
// 重新排序
|
|
|
|
|
|
|
|
this.reorder();
|
|
|
|
|
|
|
|
myCache("chatlist",this.grouplist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
// 私聊
|
|
|
|
|
|
|
|
const {data: res} = await uni.$http.get("/api/message/private/pullOfflineMessage",{minId:item.minId});
|
|
|
|
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
|
|
|
|
// 获取消息后对消息进行缓存处理
|
|
|
|
|
|
|
|
var data=res.data;
|
|
|
|
|
|
|
|
// 获取离线消息数量返回
|
|
|
|
|
|
|
|
this.grouplist[i]["sl"]=res.data.length;
|
|
|
|
|
|
|
|
var last=res.data[res.data.length-1];
|
|
|
|
|
|
|
|
if(last.type==0){
|
|
|
|
|
|
|
|
last.content=decodeURIComponent(last.content);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(last.type==0||last.type==1||last.type==2||last.type==3||last.type==4||data.type==5||data.type==6){
|
|
|
|
|
|
|
|
this.grouplist[i].content=last.content;
|
|
|
|
|
|
|
|
this.grouplist[i].type=last.type;
|
|
|
|
|
|
|
|
this.grouplist[i].datetime=last.datetime;
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
// 重新排序
|
|
|
|
|
|
|
|
this.reorder();
|
|
|
|
|
|
|
|
myCache("chatlist",this.grouplist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 获取群信息
|
|
|
|
|
|
|
|
async getGroupInfo(info,ifexist) {
|
|
|
|
|
|
|
|
const {data: res} = await uni.$http.get('/api/group/find/'+info.groupId);
|
|
|
|
|
|
|
|
if(res.data){
|
|
|
|
|
|
|
|
var data = res.data;
|
|
|
|
|
|
|
|
info.name=data.name;
|
|
|
|
|
|
|
|
info.img=data.headImage||'/static/image/qltx.png';
|
|
|
|
|
|
|
|
info.notice=data.notice;
|
|
|
|
|
|
|
|
info.remarkNickName=data.remarkNickName;
|
|
|
|
|
|
|
|
info.showNickName=data.showNickName;
|
|
|
|
|
|
|
|
info.showGroupName=data.showGroupName;
|
|
|
|
|
|
|
|
info.remarkGroupName=data.remarkGroupName;
|
|
|
|
|
|
|
|
info.customerService=data.customerService;
|
|
|
|
|
|
|
|
info.instructor=data.instructor;
|
|
|
|
|
|
|
|
info.productId=data.productId;
|
|
|
|
|
|
|
|
info.productName=data.productName;
|
|
|
|
|
|
|
|
this.updateChatGroupList(info,ifexist);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
async updateChatGroupList(info,ifexist){
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
if(ifexist==0){
|
|
|
|
|
|
|
|
this.grouplist.push(info);
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重新排序 保存缓存
|
|
|
|
|
|
|
|
this.reorder();
|
|
|
|
|
|
|
|
myCache("chatlist",this.grouplist);
|
|
|
|
|
|
|
|
// 聊天框消息缓存
|
|
|
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
|
|
|
|
if(ifexist==0||!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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
msgchat.push(firstmsg);
|
|
|
|
|
|
|
|
myCache(info.id,msgchat);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
name="匿名";
|
|
|
|
|
|
|
|
img="../../static/image/girl.png";
|
|
|
|
|
|
|
|
if(ifexist==0){
|
|
|
|
|
|
|
|
this.grouplist.push(info);
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重新排序
|
|
|
|
|
|
|
|
this.reorder();
|
|
|
|
|
|
|
|
myCache("chatlist",this.grouplist);
|
|
|
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
|
|
|
|
if(ifexist==0||!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)
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
myCache(info.id,firstmsg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
msgchat.push(firstmsg);
|
|
|
|
|
|
|
|
myCache(info.id,msgchat);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
async updateChatList(info,ifexist){
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
if(ifexist==0){
|
|
|
|
|
|
|
|
this.grouplist.push(info);
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重新排序 保存缓存
|
|
|
|
|
|
|
|
this.reorder();
|
|
|
|
|
|
|
|
myCache("chatlist",this.grouplist);
|
|
|
|
|
|
|
|
// 聊天框消息缓存
|
|
|
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
|
|
|
|
if(ifexist==0||!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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
info.name="匿名";
|
|
|
|
|
|
|
|
info.img="../../static/image/girl.png";
|
|
|
|
|
|
|
|
if(ifexist==0){
|
|
|
|
|
|
|
|
this.grouplist.push(info);
|
|
|
|
|
|
|
|
this.$forceUpdate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重新排序
|
|
|
|
|
|
|
|
this.reorder();
|
|
|
|
|
|
|
|
myCache("chatlist",this.grouplist);
|
|
|
|
|
|
|
|
var msgchat=myCache(info.id);
|
|
|
|
|
|
|
|
if(ifexist==0||!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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 获取群聊
|
|
|
|
async getProduct(id){
|
|
|
|
async getgroupsnums(id){
|
|
|
|
console.log("getProduct",id)
|
|
|
|
var nums=0
|
|
|
|
var rets=null;
|
|
|
|
const {data: res} = await uni.$http.get("/api/message/private/pullOfflineMessage",{"minId":id});
|
|
|
|
const {data: res} = await uni.$http.post("/api/message/private/getProductForIm",{"productId":id});
|
|
|
|
if(res.data&&res.data.length>0){
|
|
|
|
if(res.data){
|
|
|
|
nums=res.data.length;
|
|
|
|
var data=res.data;
|
|
|
|
return nums;
|
|
|
|
rets={
|
|
|
|
|
|
|
|
type:data.isCourse==0?1:2,// 1 商品,2 课程,3订单
|
|
|
|
|
|
|
|
id:data.id,
|
|
|
|
|
|
|
|
name:data.name,
|
|
|
|
|
|
|
|
pic:data.pic,
|
|
|
|
|
|
|
|
price:data.price,
|
|
|
|
|
|
|
|
unit: data.unit,
|
|
|
|
|
|
|
|
brandName:data.brandName,
|
|
|
|
|
|
|
|
isCourse:data.isCourse
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(rets)
|
|
|
|
|
|
|
|
return rets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
console.log("nums",nums)
|
|
|
|
return rets;
|
|
|
|
return nums;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
async getOrder(id){
|
|
|
|
|
|
|
|
var rets=null;
|
|
|
|
|
|
|
|
const {data: res} = await uni.$http.post("/api/message/private/getOrderForIm",{"orderItemId":id});
|
|
|
|
|
|
|
|
if(res.data){
|
|
|
|
|
|
|
|
var data=res.data;
|
|
|
|
|
|
|
|
rets={
|
|
|
|
|
|
|
|
type:3,// 1 商品,2 课程,3订单
|
|
|
|
|
|
|
|
id:data.id,
|
|
|
|
|
|
|
|
orderId:data.orderId,
|
|
|
|
|
|
|
|
name:data.productName,
|
|
|
|
|
|
|
|
pic:data.pic?data.pic:'/static/image/nopic.png',
|
|
|
|
|
|
|
|
price:data.totalAmount,
|
|
|
|
|
|
|
|
quantity:data.quantity,
|
|
|
|
|
|
|
|
spData: data.spData? JSON.parse(data.spData):null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rets;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
return rets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 获取状态栏高度
|
|
|
|
// 获取状态栏高度
|
|
|
|
@ -263,29 +850,31 @@
|
|
|
|
width: 100%;
|
|
|
|
width: 100%;
|
|
|
|
position: relative;
|
|
|
|
position: relative;
|
|
|
|
margin: 180rpx 0 0 0;
|
|
|
|
margin: 180rpx 0 0 0;
|
|
|
|
min-height: calc(100vh - 100rpx);
|
|
|
|
min-height: calc(100vh - 180rpx);
|
|
|
|
/* #ifdef H5 */
|
|
|
|
/* #ifdef H5 */
|
|
|
|
margin: calc( 110rpx + var(--window-top)) 0 0 0;
|
|
|
|
margin: calc( 110rpx + var(--window-top)) 0 0 0;
|
|
|
|
min-height: calc(100vh - var(--window-top) - var(--window-bottom) - 100rpx);
|
|
|
|
min-height: calc(100vh - var(--window-top) - var(--window-bottom) - 180rpx);
|
|
|
|
/* #endif */
|
|
|
|
/* #endif */
|
|
|
|
overflow-y: auto;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.listcell{
|
|
|
|
.listcell{
|
|
|
|
background: #fff;
|
|
|
|
background: #fff;
|
|
|
|
margin: 0;
|
|
|
|
margin: 0;
|
|
|
|
|
|
|
|
width: 100%;
|
|
|
|
.lcon{
|
|
|
|
.lcon{
|
|
|
|
border-bottom: 1rpx solid #eee;
|
|
|
|
border-bottom: 1rpx solid #eee;
|
|
|
|
padding-top: 28rpx;
|
|
|
|
padding-top: 20rpx;
|
|
|
|
padding-bottom: 28rpx;
|
|
|
|
padding-bottom: 20rpx;
|
|
|
|
opacity: 1;
|
|
|
|
opacity: 1;
|
|
|
|
display: flex;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
width: 100%;
|
|
|
|
.limg{
|
|
|
|
.limg{
|
|
|
|
width: 120rpx;
|
|
|
|
width: 100rpx;
|
|
|
|
height: 120rpx;
|
|
|
|
height: 100rpx;
|
|
|
|
margin-right: 24rpx;
|
|
|
|
margin-right: 20rpx;
|
|
|
|
margin-left: 24rpx;
|
|
|
|
margin-left: 20rpx;
|
|
|
|
display: flex;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
flex-direction: row;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
@ -293,8 +882,8 @@
|
|
|
|
justify-content: center;
|
|
|
|
justify-content: center;
|
|
|
|
border-radius: 50%;
|
|
|
|
border-radius: 50%;
|
|
|
|
.img{
|
|
|
|
.img{
|
|
|
|
width: 120rpx;
|
|
|
|
width: 100rpx;
|
|
|
|
height: 120rpx;
|
|
|
|
height: 100rpx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.lright{
|
|
|
|
.lright{
|
|
|
|
|