Compare commits

..

No commits in common. '7f5c4fd704d4fc7e9eca679bb527822e8b374fc7' and '23dafaf347f77c2d12178df39618996100343a2c' have entirely different histories.

@ -152,7 +152,7 @@
// }, 0) // }, 0)
// } // }
if (this.msg.length > 0) { if (this.msg.length > 1) {
// 0 // 0
this.send(this.msg, 'txt'); this.send(this.msg, 'txt');
this.ifmore=true; this.ifmore=true;
@ -161,7 +161,7 @@
}, },
inputs(e) { inputs(e) {
var chatm = e.detail.value; var chatm = e.detail.value;
if (chatm.length > 0) { if (chatm.length > 1) {
this.ifmore=false; this.ifmore=false;
} }
else{ else{
@ -431,12 +431,12 @@
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;
box-sizing: border-box; box-sizing: border-box;
padding: 14rpx; padding: 14rpx 20rpx;
image { image {
width: 60rpx; width: 56rpx;
height: 60rpx; height: 56rpx;
margin: 0 8rpx; margin: 0 10rpx;
flex: auto; flex: auto;
} }
.btnt { .btnt {
@ -464,7 +464,7 @@
.record { .record {
line-height: 44rpx; line-height: 44rpx;
text-align: center; text-align: center;
font-size: 24rpx; font-size: 20rpx;
color: rgba(39, 40, 50, 0.6); color: rgba(39, 40, 50, 0.6);
} }
} }

@ -2,8 +2,8 @@
"name" : "瑜伽汇", "name" : "瑜伽汇",
"appid" : "__UNI__B6E0086", "appid" : "__UNI__B6E0086",
"description" : "瑜伽汇", "description" : "瑜伽汇",
"versionName" : "1.0.16", "versionName" : "1.0.11",
"versionCode" : 1016, "versionCode" : 1011,
"transformPx" : false, "transformPx" : false,
"app-plus" : { "app-plus" : {
"flexible" : true, "flexible" : true,

@ -90,26 +90,18 @@
<text class="uname">{{item.fromname}}</text> <text class="uname">{{item.fromname}}</text>
</view> </view>
<view v-if="item.type == 'txt'" class="message"> <view v-if="item.type == 'txt'" class="message">
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">未读</view>
<view class="msg-text"> <view class="msg-text">
<text selectable>{{item.content}}</text> <text selectable>{{item.content}}</text>
</view> </view>
</view> </view>
<view v-if="item.type == 'image'" @tap="previewImg(item.content)" class="message"> <view v-if="item.type == 'image'" @tap="previewImg(item.content)" class="message">
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">未读</view>
<image :src="item.content" class="msg-img" mode="widthFix"></image> <image :src="item.content" class="msg-img" mode="widthFix"></image>
</view> </view>
<view v-if="item.type == 'video'" class="messagevideo"> <view v-if="item.type == 'video'" class="messagevideo">
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">未读</view>
<!-- 视频 --> <!-- 视频 -->
<myVideo :videoUrl="item.content"></myVideo> <myVideo :videoUrl="item.content"></myVideo>
</view> </view>
<view v-if="item.type == 'audio'" @click="playVoice(item.content,item.ifaudio,index)" class="message"> <view v-if="item.type == 'audio'" @click="playVoice(item.content,item.ifaudio,index)" class="message">
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">未读</view>
<!-- 音频 --> <!-- 音频 -->
<view class="msg-text voice" :style="{width: item.time>2? item.time*40+'rpx' :'auto'}"> <view class="msg-text voice" :style="{width: item.time>2? item.time*40+'rpx' :'auto'}">
{{item.time}} {{item.time}}
@ -120,8 +112,6 @@
</view> </view>
</view> </view>
<view v-if="item.type == 'product'" class="message" > <view v-if="item.type == 'product'" class="message" >
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">未读</view>
<view v-if="item.send" class="msg-product" @click="gotoDetail(item)"> <view v-if="item.send" class="msg-product" @click="gotoDetail(item)">
<view v-if="item.send.type==3" class="zx"> <view v-if="item.send.type==3" class="zx">
<view class="zxname">订单咨询</view> <view class="zxname">订单咨询</view>
@ -286,13 +276,15 @@
this.sendinfo=null; this.sendinfo=null;
this.$forceUpdate(); this.$forceUpdate();
} }
//
this.getchatstore();
} }
}, },
onShow() { onShow() {
//
this.getchatstore();
// :id // :id
setTimeout(() => { setTimeout(() => {
console.log("onShow")
this.screendo(this.unshiftmsg.length - 1); this.screendo(this.unshiftmsg.length - 1);
}, 100); }, 100);
@ -300,24 +292,26 @@
if(this.heartbeatInterval){ if(this.heartbeatInterval){
clearInterval(this.heartbeatInterval); // clearInterval(this.heartbeatInterval); //
} }
// socket
this.socketinit();
}, },
onBackPress(options) { onBackPress(options) {
if (options.from === 'backbutton') { if (options.from === 'backbutton') {
// //
// //
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('界面关闭socketbeforeDestroy'); console.log('界面关闭socketbeforeDestroy');
// WebSocket // WebSocket
// this.closeWebSocket(); this.closeWebSocket();
// clearInterval(this.heartbeatInterval); // clearInterval(this.heartbeatInterval); //
}, },
methods: { methods: {
gotoDetail(item){ gotoDetail(item){
@ -391,12 +385,11 @@
}, },
// //
getchatstore(){ getchatstore(){
console.log("getchatstore");
var that=this; var that=this;
try{ try{
this.unshiftmsg=[];
// //
var data= myCache(this.info.chatId)?myCache(this.info.chatId):[]; var data= myCache(this.info.chatId)?myCache(this.info.chatId):[];
console.log("data",data)
data.forEach((cell,i)=>{ data.forEach((cell,i)=>{
cell["ifaudio"]=false; cell["ifaudio"]=false;
// //
@ -417,6 +410,7 @@
} }
this.unshiftmsg.push(cell); this.unshiftmsg.push(cell);
}); });
if(this.unshiftmsg.length<=0) if(this.unshiftmsg.length<=0)
{ {
if(this.info.from=="yh"){ if(this.info.from=="yh"){
@ -459,41 +453,30 @@
]; ];
this.$forceUpdate(); this.$forceUpdate();
} }
// minId线
if(this.info.minId){
this.readUp(1);
}
} }
else{ else{
// :id // :id
setTimeout(() => { setTimeout(() => {
that.screendo(that.unshiftmsg.length-1); that.screendo(that.unshiftmsg.length-1);
}, 100); }, 100);
// 线
this.info.minId=this.unshiftmsg[this.unshiftmsg.length-1].id;
this.$forceUpdate();
// 线
if(this.info.minId&&this.info.minId>0){
this.readUp(1);
}
} }
} }
catch(err){ catch(err){
console.log(err); console.log(err);
} }
// socket
this.socketinit();
},
// minId
ifpull(){
var ret=true;
this.unshiftmsg.forEach((cell)=>{
if(cell.id&&this.info.minId&&parseInt(cell.id)>=parseInt(this.info.minId)){
ret=false;
}
});
return ret;
},
//
ifadd(id){
var ret=true;
this.unshiftmsg.forEach((cell)=>{
if(cell.id==id){
ret=false;
}
});
return ret;
}, },
// //
startHeartbeat() { startHeartbeat() {
@ -514,59 +497,54 @@
// ws // ws
socketinit(){ socketinit(){
var that = this; var that = this;
this.socketTask=uni.connectSocket({ if (!this.isConnected) {
url: "wss://www.sanduolantoyoga.com/yoga-imserver/", this.socketTask=uni.connectSocket({
header: { url: "wss://www.sanduolantoyoga.com/yoga-imserver/",
// 'content-type': 'application/json', header: {
Authorization: uni.getStorageSync("token"), // 'content-type': 'application/json',
}, Authorization: uni.getStorageSync("token"),
success: (res) => { },
console.log(res, 'socket连接成功success'); success: (res) => {
// minId 线 console.log(res, 'socket连接成功success');
that.getReadedId(); },
}, fail: (res) => {
fail: (res) => { console.log(res, 'socket连接失败')
console.log(res, 'socket连接失败')
},
complete: (res) => {
console.log(res,'socket连接成功complete');
}
});
uni.onSocketOpen(res => {
console.log('WebSocket连接已打开');
that.isConnected = true;
//
uni.sendSocketMessage({
data: JSON.stringify({
"cmd": 0,//
"data": {
"accessToken":uni.getStorageSync("token"),
},
}), // //
success(re) {
console.log(re);
console.log('消息发送成功!')
}, },
fail(err) { complete: (res) => {
console.log(err); console.log(res,'socket连接成功complete');
console.log('消息发送失败!')
} }
}); });
uni.onSocketOpen(res => {
// console.log('WebSocket连接已打开');
this.startHeartbeat(); that.isConnected = true;
//
}); uni.sendSocketMessage({
uni.onSocketMessage(res => { data: JSON.stringify({
console.log('收到WebSocket服务器消息'); "cmd": 0,//
if(res.data){ "data": {
let data=JSON.parse(res.data); "accessToken":uni.getStorageSync("token"),
console.log(data); },
if(data.data){ }), // //
data=data.data; success(re) {
if(data){ console.log(re);
if(this.ifadd(data.id)){ console.log('消息发送成功!')
},
fail(err) {
console.log(err);
console.log('消息发送失败!')
}
});
//
this.startHeartbeat();
});
uni.onSocketMessage(res => {
console.log('收到WebSocket服务器消息');
if(res.data){
let data=JSON.parse(res.data);
console.log(data);
if(data.data){
data=data.data;
if(data){
// //
if(data.recvId&&data.recvId.toString()==that.userid.toString()&&data.sendId.toString()==this.info.friendId.toString()){ if(data.recvId&&data.recvId.toString()==that.userid.toString()&&data.sendId.toString()==this.info.friendId.toString()){
// //
@ -618,24 +596,19 @@
} }
} }
} }
// 10, "" 11, " " 12, " " 30,""
if(data.type==12){
//
this.updateRead(data);
}
} }
} }
} });
}); uni.onSocketClose(res => {
uni.onSocketClose(res => { console.log('WebSocket连接已关闭');
console.log('WebSocket连接已关闭'); that.isConnected = false;
that.isConnected = false; clearInterval(that.heartbeatInterval); //
clearInterval(that.heartbeatInterval); // });
}); uni.onSocketError(err => {
uni.onSocketError(err => { console.error('WebSocket连接打开失败请检查', err);
console.error('WebSocket连接打开失败请检查', err); clearInterval(that.heartbeatInterval); //
clearInterval(that.heartbeatInterval); // });
}); }
}, },
// WebSocket // WebSocket
closeWebSocket() { closeWebSocket() {
@ -648,7 +621,7 @@
async setMsglist(data){ async setMsglist(data){
data.send=data.type==6?await this.getProduct(data.content):(data.type==5?await this.getOrder(data.content):null); data.send=data.type==6?await this.getProduct(data.content):(data.type==5?await this.getOrder(data.content):null);
data.type=data.type==0?'txt':(data.type==1?'image':data.type==3?'audio':(data.type==4?'video':(data.type==5?'order':(data.type==6?'product':'')))), data.type=data.type==0?'txt':(data.type==1?'image':data.type==3?'audio':(data.type==4?'video':(data.type==5?'order':(data.type==6?'product':'')))),
// console.log("setMsglist",data) console.log("setMsglist",data)
this.unshiftmsg.push(data); this.unshiftmsg.push(data);
this.$forceUpdate(); this.$forceUpdate();
setTimeout(() => { setTimeout(() => {
@ -656,29 +629,6 @@
}, 100); }, 100);
// //
myCache(this.info.chatId,this.unshiftmsg); myCache(this.info.chatId,this.unshiftmsg);
// Id
this.savaMaxId({id:this.info.chatId,minId:this.info.minId});
},
savaMaxId(info){
// Id
var data= myCache("privateMsgMaxId")?myCache("privateMsgMaxId"):[];
console.log("data",data)
var ifhas=0;
data.forEach((cell,i)=>{
if(cell.id==info.id){
ifhas=1;
data[i].minId==info.minId;
}
});
if(ifhas){
//
myCache("privateMsgMaxId",data);
}
else{
//
data.push(info);
myCache("privateMsgMaxId",data);
}
}, },
async getProduct(id){ async getProduct(id){
console.log("getProduct",id) console.log("getProduct",id)
@ -729,97 +679,89 @@
async readed() { async readed() {
const {data: res} = await uni.$http.put('/api/message/private/readed?friendId='+this.info.friendId); const {data: res} = await uni.$http.put('/api/message/private/readed?friendId='+this.info.friendId);
}, },
// minId //
async getReadedId() { async readUp(ii) {
const {data: res} = await uni.$http.get('/api/message/private/maxReadedId',{friendId:this.info.friendId}); const {data: res} = await uni.$http.put('/api/message/private/readed?friendId='+this.info.friendId);
if(res.data){ this.getList(ii);
this.info.minId=res.data;
this.$forceUpdate();
// Id
this.savaMaxId({id:this.info.chatId,minId:this.info.minId});
this.getList();
}
}, },
// 线 //
async getList() { async getList(ii) {
// minId var that=this;
// if(this.ifpull()){ const {data: res} = await uni.$http.get('/api/message/private/pullOfflineMessage',{minId: this.info.minId});
var that=this; this.triggered = false;
const {data: res} = await uni.$http.get('/api/message/private/pullOfflineMessage',{minId: this.info.minId}); if(res.data&&res.data.length>0){
this.triggered = false; const gotonum=res.data.length;
if(res.data&&res.data.length>0){ var type=0;
var type=0; res.data.forEach((cell,i)=>{
res.data.forEach((cell,i)=>{ type=cell.type;
type=cell.type; cell["ifaudio"]=false;
cell["ifaudio"]=false; //
// if (i < this.unshiftmsg.length - 1) {
if (i < this.unshiftmsg.length - 1) { //
// let t = dateTime.spaceTime(this.oldTime, cell.fromtime);
let t = dateTime.spaceTime(this.oldTime, cell.fromtime); if (t) {
if (t) { this.oldTime = t;
this.oldTime = t;
}
cell.fromtime = t;
}
//
if (cell.type == 1) {
this.imgMsg.unshift(cell.content)
}
else if(cell.type==0){
cell.content=decodeURIComponent(cell.content);
} }
// // 0: 1: 2: 3: 4: 5 6 10, "" 11, " "12, " " 30,"" cell.fromtime = t;
let mdata = { }
"fromname": this.userName, //
"fromuser": this.userid, if (cell.type == 1) {
"headimg": cell.headImage?cell.headImage:'/static/image/kfr.png', this.imgMsg.unshift(cell.content)
"toname": this.info.chatName, // }
"touser": this.info.friendId, // else if(cell.type==0){
"content": cell.content, cell.content=decodeURIComponent(cell.content);
"time": cell.type==3?5:0, }
"ifaudio":cell.type==3? true:false, // // 0: 1: 2: 3: 4: 5 6 10, "" 11, " "12, " " 30,""
"fromtime": cell.sendTime, let mdata = {
"type": data.type==0?'txt':(data.type==1?'image':data.type==3?'audio':(data.type==4?'video':(data.type==5?'order':(data.type==6?'product':'')))), "fromname": this.userName,
"id": cell.id, "fromuser": this.userid,
"recvId": cell.recvId, "headimg": cell.headImage?cell.headImage:'/static/image/kfr.png',
"sendId": cell.sendId, "toname": this.info.chatName, //
}; "touser": this.info.friendId, //
this.unshiftmsg.unshift(mdata); "content": cell.content,
}); "time": cell.type==3?5:0,
"ifaudio":cell.type==3? true:false,
"fromtime": cell.sendTime,
"type": data.type==0?'txt':(data.type==1?'image':data.type==3?'audio':(data.type==4?'video':(data.type==5?'order':(data.type==6?'product':'')))),
"id": cell.id,
"recvId": cell.recvId,
"sendId": cell.sendId,
};
this.unshiftmsg.unshift(mdata);
});
if(ii==2){
// :id
setTimeout(() => {
that.screendo(gotonum -1);
}, 100);
}
else{
// :id // :id
setTimeout(() => { setTimeout(() => {
that.screendo(that.unshiftmsg.length-1); that.screendo(that.unshiftmsg.length-1);
}, 100); }, 100);
//
myCache(this.info.chatId,this.unshiftmsg);
this.info.minId=this.unshiftmsg[this.unshiftmsg.length-1].id;
// Id
// this.savaMaxId({id:this.info.chatId,minId:this.info.minId});
this.$forceUpdate();
// 线
var chatlastinfo={
id: this.info.chatId,
content:this.unshiftmsg[this.unshiftmsg.length-1].content,
type: type,
minId: this.unshiftmsg[this.unshiftmsg.length-1].id,
datetime: this.unshiftmsg[this.unshiftmsg.length-1].sendTime,
name: this.info.chatName,
userid: this.userid,
fromuser: this.info.friendId,
img: this.info.chatAvatar,
sort:"privatechat"
};
this.updateChatList(chatlastinfo);
//
this.readed();
} }
// } //
myCache(this.info.chatId,this.unshiftmsg);
this.info.minId=this.unshiftmsg[this.unshiftmsg.length-1].id;
this.$forceUpdate();
// 线
var chatlastinfo={
id: this.info.chatId,
content:this.unshiftmsg[this.unshiftmsg.length-1].content,
type: type,
minId: this.unshiftmsg[this.unshiftmsg.length-1].id,
datetime: this.unshiftmsg[this.unshiftmsg.length-1].sendTime,
name: this.info.chatName,
userid: this.userid,
fromuser: this.info.friendId,
img: this.info.chatAvatar,
sort:"privatechat"
};
this.updateChatList(chatlastinfo);
}
}, },
screendo(scrindex){ screendo(scrindex){
this.scrollToView = ''; this.scrollToView = '';
@ -843,7 +785,7 @@
// //
onRefresh(event){ onRefresh(event){
// //
this.getList(); this.readUp(2);
}, },
// //
onRestore() { onRestore() {
@ -1161,10 +1103,6 @@
this.$forceUpdate(); this.$forceUpdate();
// //
myCache(this.info.chatId,this.unshiftmsg); myCache(this.info.chatId,this.unshiftmsg);
this.info.minId=this.unshiftmsg[this.unshiftmsg.length-1].id;
this.$forceUpdate();
// Id
// this.savaMaxId({id:this.info.chatId,minId:this.info.minId});
// //
var chatlastinfo={ var chatlastinfo={
id:this.info.chatId, id:this.info.chatId,
@ -1224,19 +1162,6 @@
myCache("chatlist-"+this.userid,chatlist); myCache("chatlist-"+this.userid,chatlist);
} }
}, },
//
updateRead(item){
console.log("updateRead")
this.unshiftmsg.forEach((cell,index)=>{
// console.log(cell,item.recvId)
if(cell.fromuser==item.recvId){
this.unshiftmsg[index].ifread=true;
this.$forceUpdate();
}
});
//
myCache(this.info.chatId,this.unshiftmsg);
},
// //
heights(e) { heights(e) {
this.inputh = e; this.inputh = e;
@ -1321,23 +1246,19 @@
} }
.message { .message {
flex: none; flex: none;
max-width: 540rpx; max-width: 480rpx;
display: flex;
flex-direction: row;
} }
.messagevideo { .messagevideo {
max-width: 540rpx; max-width: 480rpx;
height: 300rpx; height: 300rpx;
display: flex;
flex-direction: row;
} }
.msg-text { .msg-text {
font-size: 32rpx; font-size: 32rpx;
color: rgba(39, 40, 50, 1); color: rgba(39, 40, 50, 1);
line-height: 44rpx; line-height: 44rpx;
padding: 18rpx 24rpx; padding: 18rpx 24rpx;
word-break: break-all;
} }
.msg-img { .msg-img {
max-width: 400rpx; max-width: 400rpx;
border-radius: 20rpx; border-radius: 20rpx;
@ -1416,7 +1337,6 @@
margin-left: 16rpx; margin-left: 16rpx;
background-color: #fff; background-color: #fff;
border-radius: 0rpx 20rpx 20rpx 20rpx; border-radius: 0rpx 20rpx 20rpx 20rpx;
word-break: break-all;
} }
.ms-img { .ms-img {
@ -1577,22 +1497,6 @@
.msg-right { .msg-right {
flex-direction: row-reverse; flex-direction: row-reverse;
.read{
font-size: 24rpx;
color: #888;
margin-right: 10rpx;
display: flex;
justify-content: flex-end;
align-items: flex-end;
}
.noread{
font-size: 24rpx;
color: #00a89b;
margin-right: 10rpx;
display: flex;
justify-content: flex-end;
align-items: flex-end;
}
.feed-imgy{ .feed-imgy{
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -1619,7 +1523,6 @@
font-size: 32rpx; font-size: 32rpx;
color: #FFFFFF; color: #FFFFFF;
line-height: 48rpx; line-height: 48rpx;
word-break: break-all;
border-radius: 20rpx 0rpx 20rpx 20rpx; border-radius: 20rpx 0rpx 20rpx 20rpx;
} }

@ -90,29 +90,19 @@
<text class="uname">{{item.fromname}}</text> <text class="uname">{{item.fromname}}</text>
</view> </view>
<view v-if="item.type == 'txt'" class="message"> <view v-if="item.type == 'txt'" class="message">
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">{{item.readedCount?(2-item.readedCount):2}}未读</view>
<view class="msg-text"> <view class="msg-text">
<text selectable>{{item.content}}</text> <text selectable>{{item.content}}</text>
</view> </view>
</view> </view>
<view v-if="item.type == 'image'" @tap="previewImg(item.content)" class="message"> <view v-if="item.type == 'image'" @tap="previewImg(item.content)" class="message">
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">{{item.readedCount?(2-item.readedCount):2}}未读</view>
<image :src="item.content" class="msg-img" mode="widthFix"></image> <image :src="item.content" class="msg-img" mode="widthFix"></image>
</view> </view>
<view v-if="item.type == 'video'" class="messagevideo"> <view v-if="item.type == 'video'" class="messagevideo">
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">{{item.readedCount?(2-item.readedCount):2}}未读</view>
<!-- 视频 --> <!-- 视频 -->
<myVideo :videoUrl="item.content"></myVideo> <myVideo :videoUrl="item.content"></myVideo>
</view> </view>
<view v-if="item.type == 'audio'" @click="playVoice(item.content,item.ifaudio,index)" class="message"> <view v-if="item.type == 'audio'" @click="playVoice(item.content,item.ifaudio,index)" class="message">
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">{{item.readedCount?(2-item.readedCount):2}}未读</view>
<!-- 音频 --> <!-- 音频 -->
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">{{item.readedCount?(2-item.readedCount):2}}未读</view>
<view class="msg-text voice" :style="{width: item.time>2? item.time*40+'rpx' :'auto'}"> <view class="msg-text voice" :style="{width: item.time>2? item.time*40+'rpx' :'auto'}">
{{item.time}} {{item.time}}
<view class="voicel" v-if="item.ifaudio" > <view class="voicel" v-if="item.ifaudio" >
@ -122,8 +112,6 @@
</view> </view>
</view> </view>
<view v-if="item.type == 'product'" class="message" > <view v-if="item.type == 'product'" class="message" >
<view v-if="item.ifread" class="read"></view>
<view v-else class="noread">{{item.readedCount?(2-item.readedCount):2}}未读</view>
<view v-if="item.send" class="msg-product" @click="gotoDetail(item)"> <view v-if="item.send" class="msg-product" @click="gotoDetail(item)">
<view v-if="item.send.type==3" class="zx"> <view v-if="item.send.type==3" class="zx">
<view class="zxname">订单咨询</view> <view class="zxname">订单咨询</view>
@ -361,15 +349,15 @@
this.sendinfo=null; this.sendinfo=null;
this.$forceUpdate(); this.$forceUpdate();
} }
//
this.getchatstore();
//
this.getrwinfo();
} }
}, },
onShow() { onShow() {
//
this.getchatstore();
//
this.getrwinfo();
// :id // :id
setTimeout(() => { setTimeout(() => {
console.log("onShow") console.log("onShow")
@ -380,16 +368,18 @@
if(this.heartbeatInterval){ if(this.heartbeatInterval){
clearInterval(this.heartbeatInterval); // clearInterval(this.heartbeatInterval); //
} }
// socket
this.socketinit();
}, },
onBackPress(options) { onBackPress(options) {
if (options.from === 'backbutton') { if (options.from === 'backbutton') {
// //
// //
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;
} }
}, },
@ -403,8 +393,8 @@
beforeDestroy() { beforeDestroy() {
console.log('界面关闭socketbeforeDestroy'); console.log('界面关闭socketbeforeDestroy');
// WebSocket // WebSocket
// this.closeWebSocket(); this.closeWebSocket();
// clearInterval(this.heartbeatInterval); // clearInterval(this.heartbeatInterval); //
}, },
methods: { methods: {
// //
@ -509,9 +499,9 @@
getchatstore(){ getchatstore(){
var that=this; var that=this;
try{ try{
this.unshiftmsg=[];
// //
var data= myCache(this.info.chatId)?myCache(this.info.chatId):[]; var data= myCache(this.info.chatId)?myCache(this.info.chatId):[];
console.log("data",data)
data.forEach((cell,i)=>{ data.forEach((cell,i)=>{
cell["ifaudio"]=false; cell["ifaudio"]=false;
// //
@ -575,39 +565,30 @@
]; ];
this.$forceUpdate(); this.$forceUpdate();
} }
// minId线
if(this.info.minId){
this.readUp(1);
}
} }
else{ else{
// :id // :id
setTimeout(() => { setTimeout(() => {
that.screendo(that.unshiftmsg.length-1); that.screendo(that.unshiftmsg.length-1);
}, 100); }, 100);
// 线
this.info.minId=this.unshiftmsg[this.unshiftmsg.length-1].id;
this.$forceUpdate();
// 线
if(this.info.minId&&this.info.minId>0){
this.readUp(1);
}
} }
} }
catch(err){ catch(err){
console.log(err); console.log(err);
} }
// socket
this.socketinit();
},
// minId
ifpull(){
var ret=true;
this.unshiftmsg.forEach((cell)=>{
if(cell.id&&this.info.minId&&parseInt(cell.id)>=parseInt(this.info.minId)){
ret=false;
}
});
return ret;
},
ifadd(id){
var ret=true;
this.unshiftmsg.forEach((cell)=>{
if(cell.id==id){
ret=false;
}
});
return ret;
}, },
// //
startHeartbeat() { startHeartbeat() {
@ -645,8 +626,6 @@
}, },
success: (res) => { success: (res) => {
console.log(res, 'socket连接成功success'); console.log(res, 'socket连接成功success');
// minId 线
that.getReadedId();
}, },
fail: (res) => { fail: (res) => {
console.log(res, 'socket连接失败') console.log(res, 'socket连接失败')
@ -687,29 +666,18 @@
// //
if(data.data){ if(data.data){
data=data.data; data=data.data;
// //
if(data.groupId==this.info.groupId){ if(data.groupId==this.info.groupId){
if(this.ifadd(data.id)){ //
// // 0: 1: 2: 3: 4: 5 6 10, "" 11, " "12, " " 30,""
// 0: 1: 2: 3: 4: 5 6 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.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){ this.getMsgSender(data)
this.getMsgSender(data);
//
this.readed();
}
else{
// 10, "" 11, " " 12, " " 30,""
}
} }
// 10, "" 11, " " 12, " " 30,"" else{
if(data.type==12){ // 10, "" 11, " " 12, " " 30,""
//
this.updateRead(data);
} }
} }
} }
} }
} }
}); });
@ -774,8 +742,6 @@
// //
myCache(this.info.chatId,this.unshiftmsg); myCache(this.info.chatId,this.unshiftmsg);
// Id
this.savaMaxId({id:this.info.chatId,minId:data.id});
// socket // socket
var chatlastinfo={ var chatlastinfo={
@ -798,27 +764,6 @@
// //
this.readed(); this.readed();
}, },
savaMaxId(info){
// Id
var data= myCache("groupMsgMaxId")?myCache("groupMsgMaxId"):[];
console.log("data",data)
var ifhas=0;
data.forEach((cell,i)=>{
if(cell.id==info.id){
ifhas=1;
data[i].minId==info.minId;
}
});
if(ifhas){
//
myCache("groupMsgMaxId",data);
}
else{
//
data.push(info);
myCache("groupMsgMaxId",data);
}
},
async getProduct(id){ async getProduct(id){
console.log("getProduct",id) console.log("getProduct",id)
var rets=null; var rets=null;
@ -867,102 +812,93 @@
async readed() { async readed() {
const {data: res} = await uni.$http.put('/api/message/group/readed?groupId='+this.info.groupId); const {data: res} = await uni.$http.put('/api/message/group/readed?groupId='+this.info.groupId);
}, },
// minId //
async getReadedId() { async readUp(ii) {
const {data: res} = await uni.$http.get('/api/message/group/maxReadedId',{groupId:this.info.groupId}); const {data: res} = await uni.$http.put('/api/message/group/readed?groupId='+this.info.groupId);
if(res.data){ this.getList(ii);
this.info.minId=res.data;
this.$forceUpdate();
this.getList();
}
}, },
// //
async getList() { async getList(ii) {
// if(this.ifpull()){ var that=this;
var that=this; const {data: res} = await uni.$http.get('/api/message/group/pullOfflineMessage',{minId: this.info.minId});
const {data: res} = await uni.$http.get('/api/message/group/pullOfflineMessage',{minId: this.info.minId}); this.triggered = false;
this.triggered = false; if(res.data&&res.data.length>0){
if(res.data&&res.data.length>0){ const gotonum=res.data.length;
const gotonum=res.data.length; var type=0;
var type=0; res.data.forEach((cell,i)=>{
res.data.forEach((cell,i)=>{ type=cell.type;
if(this.ifadd(cell.id)){ cell["ifaudio"]=false;
type=cell.type; //
cell["ifaudio"]=false; if (i < this.unshiftmsg.length - 1) {
// //
if (i < this.unshiftmsg.length - 1) { let t = dateTime.spaceTime(this.oldTime, cell.fromtime);
// if (t) {
let t = dateTime.spaceTime(this.oldTime, cell.fromtime); this.oldTime = t;
if (t) {
this.oldTime = t;
}
cell.fromtime = t;
}
//
if (cell.type == 1) {
this.imgMsg.unshift(cell.content)
}
else if(cell.type==0){
cell.content=decodeURIComponent(cell.content);
}
// // 0: 1: 2: 3: 4: 5 6 10, "" 11, " "12, " " 30,""
let mdata = {
"fromname": this.userName,
"fromuser": this.userid,
"headimg": cell.headImage?cell.headImage:'/static/image/kfr.png',
"toname": cell.sendNickName, //
"touser": cell.sendId, //
"content": cell.content,
"readedCount": cell.readedCount,
"time": cell.type==3?5:0,
"ifaudio":cell.type==3? true:false,
"fromtime": cell.sendTime,
"type": data.type==0?'txt':(data.type==1?'image':data.type==3?'audio':(data.type==4?'video':(data.type==5?'order':(data.type==6?'product':'')))),
"id": cell.id,
"sendId": cell.sendId,
"atUserIds": data.atUserIds,
};
this.unshiftmsg.unshift(mdata);
} }
}); cell.fromtime = t;
// // :id }
// setTimeout(() => { //
// that.screendo(gotonum -1); if (cell.type == 1) {
// }, 100); this.imgMsg.unshift(cell.content)
}
else if(cell.type==0){
cell.content=decodeURIComponent(cell.content);
}
// // 0: 1: 2: 3: 4: 5 6 10, "" 11, " "12, " " 30,""
let mdata = {
"fromname": this.userName,
"fromuser": this.userid,
"headimg": cell.headImage?cell.headImage:'/static/image/kfr.png',
"toname": cell.sendNickName, //
"touser": cell.sendId, //
"content": cell.content,
"readedCount": cell.readedCount,
"time": cell.type==3?5:0,
"ifaudio":cell.type==3? true:false,
"fromtime": cell.sendTime,
"type": data.type==0?'txt':(data.type==1?'image':data.type==3?'audio':(data.type==4?'video':(data.type==5?'order':(data.type==6?'product':'')))),
"id": cell.id,
"sendId": cell.sendId,
"atUserIds": data.atUserIds,
};
this.unshiftmsg.unshift(mdata);
});
if(ii==2){
// :id
setTimeout(() => {
that.screendo(gotonum -1);
}, 100);
}
else{
// :id // :id
setTimeout(() => { setTimeout(() => {
that.screendo(that.unshiftmsg.length-1); that.screendo(that.unshiftmsg.length-1);
}, 100); }, 100);
//
myCache(this.info.chatId,this.unshiftmsg);
this.info.minId=this.unshiftmsg[this.unshiftmsg.length-1].id;
this.$forceUpdate();
// Id
this.savaMaxId({id:this.info.chatId,minId:this.info.minId});
// 线
var chatlastinfo={
id: this.info.chatId,
groupId:this.info.groupId,
content:this.unshiftmsg[this.unshiftmsg.length-1].content,
type: type,
minId: this.unshiftmsg[this.unshiftmsg.length-1].id,
datetime: this.unshiftmsg[this.unshiftmsg.length-1].sendTime,
name: this.info.chatName,
userid: this.userid,
friendId: this.info.friendId, // userid
teacherId: this.info.teacherId? this.info.teacherId:this.info.instructor, // userid
fromuser: this.unshiftmsg[this.unshiftmsg.length-1].touser,
img: this.unshiftmsg[this.unshiftmsg.length-1].headimg,
sort:"groupchat"
};
this.updateChatList(chatlastinfo);
//
this.readed();
} }
// } //
myCache(this.info.chatId,this.unshiftmsg);
this.info.minId=this.unshiftmsg[this.unshiftmsg.length-1].id;
this.$forceUpdate();
// 线
var chatlastinfo={
id: this.info.chatId,
groupId:this.info.groupId,
content:this.unshiftmsg[this.unshiftmsg.length-1].content,
type: type,
minId: this.unshiftmsg[this.unshiftmsg.length-1].id,
datetime: this.unshiftmsg[this.unshiftmsg.length-1].sendTime,
name: this.info.chatName,
userid: this.userid,
friendId: this.info.friendId, // userid
teacherId: this.info.teacherId? this.info.teacherId:this.info.instructor, // userid
fromuser: this.unshiftmsg[this.unshiftmsg.length-1].touser,
img: this.unshiftmsg[this.unshiftmsg.length-1].headimg,
sort:"groupchat"
};
this.updateChatList(chatlastinfo);
}
}, },
screendo(scrindex){ screendo(scrindex){
this.scrollToView = ''; this.scrollToView = '';
@ -986,7 +922,7 @@
// //
onRefresh(event){ onRefresh(event){
// //
this.getList(); this.readUp(2);
}, },
// //
onRestore() { onRestore() {
@ -1304,9 +1240,6 @@
this.$forceUpdate(); this.$forceUpdate();
// //
myCache(this.info.chatId,this.unshiftmsg); myCache(this.info.chatId,this.unshiftmsg);
// Id
this.savaMaxId({id:this.info.chatId,minId:rrdata.id});
// //
var chatlastinfo={ var chatlastinfo={
id:this.info.chatId, id:this.info.chatId,
@ -1369,21 +1302,6 @@
myCache("chatlist-"+this.userid,chatlist); myCache("chatlist-"+this.userid,chatlist);
} }
}, },
//
updateRead(item){
console.log(this.info)
this.unshiftmsg.forEach((cell,index)=>{
if(cell.id==item.id){
this.unshiftmsg[index].readedCount=item.readedCount;
if(item.readedCount>=2){
this.unshiftmsg[index].ifread=true;
}
this.$forceUpdate();
}
});
//
myCache(this.info.chatId,this.unshiftmsg);
},
// //
heights(e) { heights(e) {
this.inputh = e; this.inputh = e;
@ -1468,15 +1386,11 @@
} }
.message { .message {
flex: none; flex: none;
max-width: 540rpx; max-width: 480rpx;
display: flex;
flex-direction: row;
} }
.messagevideo { .messagevideo {
max-width: 540rpx; max-width: 480rpx;
height: 300rpx; height: 300rpx;
display: flex;
flex-direction: row;
} }
.msg-text { .msg-text {
font-size: 32rpx; font-size: 32rpx;
@ -1723,23 +1637,6 @@
.msg-right { .msg-right {
flex-direction: row-reverse; flex-direction: row-reverse;
.read{
font-size: 24rpx;
color: #888;
margin-right: 10rpx;
display: flex;
justify-content: flex-end;
align-items: flex-end;
}
.noread{
font-size: 24rpx;
color: #00a89b;
margin-right: 10rpx;
display: flex;
justify-content: flex-end;
align-items: flex-end;
}
.feed-imgy{ .feed-imgy{
display: flex; display: flex;
flex-direction: column; flex-direction: column;

@ -781,13 +781,6 @@
.thname{ .thname{
font-size: 30rpx; font-size: 30rpx;
color:#000; color:#000;
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
/* 假设你的行高是20px并且你想要两行显示 */
line-height: 40rpx; /* 每行的行高 */
max-height: 80rpx;
} }
.thtext{ .thtext{
margin-top: 10rpx; margin-top: 10rpx;

@ -12,28 +12,27 @@
<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="info.id" style="min-width: 600rpx;" <u-swipe-action ref="swipeRef" :options="options" v-for="(info, index) in grouplist" :key="index" @click="$u.throttle(actionClick(info,index), 2000)" >
@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>
</view>
<view class="lright">
<view class="lrow">
<view class="pname">{{info.name}}</view>
<view class="ptime"> {{ changeTime(info.datetime)}}</view>
</view> </view>
<view class="lrow"> <view class="lright">
<view class="pnr"> <view class="lrow">
{{ info.type==0?info.content:(info.type==1?"图片":(info.type==2?"文件":(info.type==3?"语音":(info.type==4?"视频": <view class="pname">{{info.name}}</view>
(info.type==5?"订单咨询":(info.type==6?"商品咨询":info.content))))))}} <view class="ptime"> {{ changeTime(info.datetime)}}</view>
</view> </view>
<view class="lnum" v-if="info.sl>0"> <view class="lrow">
{{ info.sl}} <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>
</view>
</u-swipe-action> </u-swipe-action>
@ -72,7 +71,7 @@
backgroundColor: '#ed2a28' backgroundColor: '#ed2a28'
} }
} }
], // u-swipe-action ], //u-swipe-action
imgurl:uni.$http.baseUrl, imgurl:uni.$http.baseUrl,
grouplist:[], grouplist:[],
socketTask: null, socketTask: null,
@ -83,6 +82,8 @@
} }
}, },
onLoad(options) { onLoad(options) {
// socket
// this.socketinit();
}, },
onShow(){ onShow(){
this.openId = myCache('openId'); this.openId = myCache('openId');
@ -109,18 +110,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('界面关闭socketbeforeDestroy'); console.log('界面关闭socketbeforeDestroy');
// WebSocket // WebSocket
// this.closeWebSocket(); this.closeWebSocket();
// clearInterval(this.heartbeatInterval); // clearInterval(this.heartbeatInterval); //
}, },
beforeRouteLeave(to, from, next) { beforeRouteLeave(to, from, next) {
console.log('界面关闭socketbeforeRouteLeave'); console.log('界面关闭socketbeforeRouteLeave');
@ -129,7 +130,22 @@
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) {
@ -142,7 +158,6 @@
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();
@ -170,222 +185,182 @@
// ws // ws
socketinit(){ socketinit(){
var that = this; var that = this;
that.socketTask=uni.connectSocket({ // if (!that.isConnected) {
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 => { that.socketTask=uni.connectSocket({
console.log('WebSocket连接已打开'); url: "wss://www.sanduolantoyoga.com/yoga-imserver/",
that.isConnected = true; header: {
that.$forceUpdate(); // 'content-type': 'application/json',
uni.sendSocketMessage({ Authorization: uni.getStorageSync("token"),
data: JSON.stringify({
"cmd": 0,//
"data": {
"accessToken":uni.getStorageSync("token"),
},
}), // //
success(re) {
console.log(re);
console.log('消息发送成功!')
}, },
fail(err) { success: (res) => {
console.log(err); console.log(res, 'socket连接成功success');
console.log('消息发送失败!') },
} fail: (res) => {
}); console.log(res, 'socket连接失败')
},
// complete: (res) => {
this.startHeartbeat(); console.log(res,'socket连接成功complete');
// 线
this.grouplist.forEach((cell,i)=>{
if(cell.minId){
// id 线
this.pullMessage(i,cell);
} }
}); });
// id uni.onSocketOpen(resopen => {
var data= myCache("privateMsgMaxId")?myCache("privateMsgMaxId"):[{id:0,minId:0}]; console.log('WebSocket连接已打开');
data.forEach((cell)=>{ that.isConnected = true;
console.log("privateMsgMaxId") that.$forceUpdate()
var ifcz=false; uni.sendSocketMessage({
this.grouplist.forEach((item)=>{ data: JSON.stringify({
if(cell.id==item.id){ "cmd": 0,//
// 线 "data": {
ifcz=true; "accessToken":uni.getStorageSync("token"),
},
}), // //
success(re) {
console.log(re);
console.log('消息发送成功!')
},
fail(err) {
console.log(err);
console.log('消息发送失败!')
} }
}); });
if(!ifcz){
// 线
this.getList(cell);
}
});
var data= myCache("groupMsgMaxId")?myCache("groupMsgMaxId"):[{id:0,minId:0}]; //
data.forEach((cell)=>{ this.startHeartbeat();
var ifcz=false;
this.grouplist.forEach((item)=>{
if(cell.id==item.id){
// 线
ifcz=true;
}
});
if(!ifcz){
// 线
this.getGroupList(cell);
}
}); });
}); 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();
}
});
uni.onSocketMessage(res => { if(ifexist==0){
console.log('收到WebSocket服务器消息'); //
if(res.data){ // socket
var rs=JSON.parse(res.data); var chatlastinfo={
console.log(rs); id: "privatechat-" + data.recvId +"-" + data.sendId,
if(rs.cmd==3){ content: data.content,
// minId: data.id,
if(rs.data){ sl:1,
var data=rs.data; datetime: data.sendTime,
if(data.recvId&&(data.recvId).toString()==(that.userid).toString()){ type: data.type,
// name: "",
// userid: data.recvId,
// 0: 1: 2: 3: 4: 10, "" 11, " "12, " " 30,"" fromuser: data.sendId,
if(data.type==0){ img: "",
data.content=decodeURIComponent(data.content); sort:"privatechat"
} };
if(data.type==0||data.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){ that.updateChatList(chatlastinfo,ifexist);
var ifexist=0,chatinfo=null; }
that.grouplist.forEach((cell,index)=>{ else{
if(cell.fromuser==data.sendId&&cell.userid==data.recvId&&cell.sort=="privatechat"){ that.updateChatList(that.grouplist[idx],ifexist);
ifexist=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.$forceUpdate();
chatinfo= JSON.parse(JSON.stringify(that.grouplist[index])) ;
console.log(chatinfo)
} }
});
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);
} }
else{ else{
that.updateChatList(chatinfo); // 10, "" 11, " " 12, " " 30,""
} }
} }
else{
// 10, "" 11, " " 12, " " 30,""
}
} }
} }
} else if(rs.cmd==4){
else if(rs.cmd==4){ //
// if(rs.data){
if(rs.data){ var data=rs.data;
var data=rs.data; if(data.atUserIds&&data.atUserIds.includes(that.userid)){
if(data.atUserIds&&data.atUserIds.includes(that.userid)){ //
// //
// // 0: 1: 2: 3: 4: 10, "" 11, " "12, " " 30,""
// 0: 1: 2: 3: 4: 10, "" 11, " "12, " " 30,"" if(data.type==0){
if(data.type==0){ 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,idx=null; that.grouplist.forEach((cell,index)=>{
that.grouplist.forEach((cell,index)=>{ if(cell.groupId==data.groupId&&cell.sort=="groupchat"){
if(cell.groupId==data.groupId&&cell.sort=="groupchat"){ ifexist=1;
ifexist=1; idx=index;
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].fromuser=data.sendId;
that.grouplist[index].fromuser=data.sendId; that.grouplist[index].type=data.type;
that.grouplist[index].type=data.type; that.$forceUpdate();
that.$forceUpdate(); }
} });
});
if(ifexist==0){ if(ifexist==0){
// //
// socket // socket
var chatlastinfo={ var chatlastinfo={
id: "groupchat-" + data.groupId, id: "groupchat-" + data.groupId,
groupId:data.groupId, groupId:data.groupId,
content: data.content, content: data.content,
minId: data.id, minId: data.id,
sl:1, sl:1,
datetime: data.sendTime, datetime: data.sendTime,
type: data.type, type: data.type,
name: "", name: "",
userid: this.userid, userid: this.userid,
fromuser: data.sendId, fromuser: data.sendId,
img: "", img: "",
sendId: data.sendId, sendId: data.sendId,
sendNickName: data.sendNickName, sendNickName: data.sendNickName,
sort:"groupchat" sort:"groupchat"
}; };
that.getGroupInfo(chatlastinfo); that.getGroupInfo(chatlastinfo,ifexist);
}
else{
that.getGroupInfo(that.grouplist[idx],ifexist);
}
} }
else{ else{
that.getGroupInfo(that.grouplist[idx]); // 10, "" 11, " " 12, " " 30,""
} }
} }
else{
// 10, "" 11, " " 12, " " 30,""
}
} }
} }
} }
} });
});
uni.onSocketClose(res => { uni.onSocketClose(res => {
console.log('WebSocket连接已关闭',res); console.log('WebSocket连接已关闭',res);
that.isConnected = false; that.isConnected = false;
that.$forceUpdate(); that.$forceUpdate();
clearInterval(that.heartbeatInterval); // clearInterval(that.heartbeatInterval); //
}); });
uni.onSocketError(err => { uni.onSocketError(err => {
console.error('WebSocket连接打开失败请检查', err); console.error('WebSocket连接打开失败请检查', err);
that.isConnected = false; that.isConnected = false;
that.$forceUpdate(); that.$forceUpdate();
clearInterval(that.heartbeatInterval); // clearInterval(that.heartbeatInterval); //
}); });
// }
}, },
// WebSocket // WebSocket
closeWebSocket() { closeWebSocket() {
@ -393,16 +368,6 @@
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`
@ -475,10 +440,21 @@
// //
async getgroupsmembers(){ async getgroupsmembers(){
// //
this.grouplist=myCache("chatlist-"+this.userid)?myCache("chatlist-"+this.userid):[]; this.grouplist=[];
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();
@ -493,148 +469,68 @@
this.grouplist.sort((a, b) => b.datetime - a.datetime); this.grouplist.sort((a, b) => b.datetime - a.datetime);
this.$forceUpdate(); this.$forceUpdate();
}, },
// 线 //
async pullMessage(i,item) { async readUp(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});
// if(res.data&&res.data.length>0){
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;
// // 线
var data=res.data; this.grouplist[i]["sl"]=res.data.length;
// 线 var last=res.data[res.data.length-1];
this.grouplist[i]["sl"]=res.data.length; if(last.type==0){
var last=res.data[res.data.length-1]; last.content=decodeURIComponent(last.content);
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.userid,this.grouplist);
}
} }
// } 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.userid,this.grouplist);
}
}
} }
else{ else{
// minId //
// if(this.ifprivateMsgMaxId(item)){ const {data: res} = await uni.$http.get("/api/message/private/pullOfflineMessage",{minId:item.minId});
// if(res.data&&res.data.length>0){
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;
// // 线
var data=res.data; this.grouplist[i]["sl"]=res.data.length;
// 线 var last=res.data[res.data.length-1];
this.grouplist[i]["sl"]=res.data.length; if(last.type==0){
var last=res.data[res.data.length-1]; last.content=decodeURIComponent(last.content);
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.userid,this.grouplist);
}
} }
// } 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.userid,this.grouplist);
}
}
} }
}, },
// //
async getGroupInfo(info) { async getGroupInfo(info,ifexist) {
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;
@ -649,34 +545,26 @@
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); this.updateChatGroupList(info,ifexist);
} }
}, },
async updateChatGroupList(info){ async updateChatGroupList(info,ifexist){
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");
var idx=this.ifadd(info.id); if(ifexist==0){
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(!msgchat){ if(ifexist==0||!msgchat){
// //
let firstmsg = [{ let firstmsg = [{
"fromname": name, // "fromname": name, //
@ -722,23 +610,15 @@
else{ else{
name="匿名"; name="匿名";
img="../../static/image/girl.png"; img="../../static/image/girl.png";
var idx=this.ifadd(info.id); if(ifexist==0){
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(!msgchat){ if(ifexist==0||!msgchat){
// //
let firstmsg = [{ let firstmsg = [{
"fromname": name, // "fromname": name, //
@ -781,31 +661,22 @@
} }
} }
}, },
async updateChatList(info){ async updateChatList(info,ifexist){
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");
var idx=this.ifadd(info.id); if(ifexist==0){
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(!msgchat){ if(ifexist==0||!msgchat){
// //
let firstmsg = [{ let firstmsg = [{
"fromname": info.name, // "fromname": info.name, //
@ -852,26 +723,15 @@
else{ else{
info.name="匿名"; info.name="匿名";
info.img="../../static/image/girl.png"; info.img="../../static/image/girl.png";
var idx=this.ifadd(info.id); if(ifexist==0){
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);
console.log(info.id,msgchat); if(ifexist==0||!msgchat){
if(!msgchat){
// //
let firstmsg = [{ let firstmsg = [{
"fromname": info.name, // "fromname": info.name, //
@ -1020,7 +880,6 @@
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;
@ -1080,12 +939,6 @@
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;

@ -360,6 +360,11 @@
uni.stopPullDownRefresh() uni.stopPullDownRefresh()
},500); },500);
}, },
// onTabItemTap(){
// console.log('socketonTabItemTap');
// // WebSocket
// uni.closeSocket();
// },
methods: { methods: {
ifview(value){ ifview(value){
// ID103 104 105 107 // ID103 104 105 107

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Loading…
Cancel
Save