zouyanyan 2 days ago
parent 7f5c4fd704
commit c2903e3b2a

@ -3,10 +3,21 @@
//import checkupdate from "@/uni_modules/uni-upgrade-center-app/utils/check-update.js"
//
// import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
import { myCache } from '@/utils/utils.js';
//#ifdef APP-PLUS
const jpushModule = uni.requireNativePlugin('JG-JPush');
//#endif
export default {
data() {
return {
userid:"",
userName:"",
userheadimg:"",
}
},
onLaunch() {
//
//checkupdate();
@ -29,7 +40,6 @@
// })
// }
//
// jpushModule.addTagAliasListener(result => {
// let code = result.code
// let sequence = result.sequence
@ -68,7 +78,449 @@
// console.log("", result)
// })
//#endif
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");
//
if(uni.getStorageSync("token")&&this.userid){
this.startHeartbeat();
}
},
methods: {
//
startHeartbeat() {
console.log("startHeartbeat");
var that=this;
this.heartbeatInterval = setInterval(() => {
if(this.isConnected){
// ws
uni.sendSocketMessage({
data: JSON.stringify({
'cmd': 1,//
'data': {
'accessToken':uni.getStorageSync("token")
},
}), // ,
success(re) {
console.log(re);
console.log('消息发送成功!')
},
fail(err) {
console.log(err);
console.log('消息发送失败!');
that.reconnect();
}
});
}
else{
//
that.reconnect();
}
}, this.heartbeatTimeout); // 20
},
//
reconnect () {
if (!this.isConnected) {
clearTimeout(this.heartbeatInterval);
this.heartbeatInterval = setTimeout(() => {
console.log('开始重连...');
this.socketinit();
},this.heartbeatTimeout);
}
},
// ws
socketinit(){
var that = this;
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连接已打开');
this.isConnected = true;
this.$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.onSocketClose(res => {
console.log('WebSocket连接已关闭',res);
this.isConnected = false;
this.$forceUpdate();
// socket
this.reconnect();
});
//
uni.onSocketError(err => {
console.error('WebSocket连接打开失败请检查', err);
this.isConnected = false;
this.$forceUpdate();
// socket
this.reconnect();
});
//
uni.onSocketMessage(res => {
console.log('收到WebSocket服务器消息');
if(res.data){
var rs=JSON.parse(res.data);
console.log("onSocketMessage",rs);
if(rs.cmd==3){
//
if(rs.data){
var data=rs.data;
if(data.recvId&&(data.recvId).toString()==(this.userid).toString()){
//
//
// 0: 1: 2: 3: 4: 10, "" 11, " "12, " " 30,""
if(data.type==0||data.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){
if(data.type==0){
data.content=decodeURIComponent(data.content);
}
var id="privatechat-" + data.recvId +"-" + data.sendId;
var index=this.ifadd(id);
var chatinfo=null;
var grouplist=myCache("chatlist-"+this.userid)?myCache("chatlist-"+this.userid):[];
if(index>-1){
grouplist[index].sl=(grouplist[index].sl?grouplist[index].sl+1:1);
grouplist[index].content=data.content;
grouplist[index].datetime=data.sendTime;
grouplist[index].type=data.type;
grouplist[index].minId=data.id;
grouplist[index].ifload=1;
that.$forceUpdate();
chatinfo= JSON.parse(JSON.stringify(grouplist[index]));
}
else{
//
// socket
chatinfo={
id: id,
content: data.content,
minId: data.id,
sl:1,
datetime: data.sendTime,
type: data.type,
name: "",
userid: data.recvId,
fromuser: data.sendId,
img: "",
sort:"privatechat",
ifload:0
};
grouplist.push(chatinfo);
this.$forceUpdate();
}
myCache("chatlist-"+this.userid,grouplist);
this.getPrivateInfo(chatinfo);
}
else{
// 10, "" 11, " " 12, " " 30,""
}
}
}
}
else if(rs.cmd==4){
//
if(rs.data){
var data=rs.data;
if(data.atUserIds&&data.atUserIds.includes(this.userid)){
//
//
// 0: 1: 2: 3: 4: 10, "" 11, " "12, " " 30,""
if(data.type==0||data.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){
if(data.type==0){
data.content=decodeURIComponent(data.content);
}
var id="groupchat-" + data.groupId;
var index=this.ifadd(id);
var chatinfo=null;
var grouplist=myCache("chatlist-"+this.userid)?myCache("chatlist-"+this.userid):[];
if(index>-1){
grouplist[index].sl=(grouplist[index].sl?grouplist[index].sl+1:1);
grouplist[index].content=data.content;
grouplist[index].datetime=data.sendTime;
grouplist[index].fromuser=data.sendId;
grouplist[index].type=data.type;
grouplist[index].minId=data.id;
grouplist[index].ifload=1;
that.$forceUpdate();
chatinfo= JSON.parse(JSON.stringify(grouplist[index]));
}
else{
//
// socket
chatinfo={
id: id,
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",
ifload:0
};
grouplist.push(chatinfo);
}
myCache("chatlist-"+this.userid,grouplist);
this.getGroupInfo(chatinfo);
}
else{
// 10, "" 11, " " 12, " " 30,""
}
}
}
}
}
});
},
//
ifadd(id){
var ret=-1;
var grouplist=myCache("chatlist-"+this.userid)?myCache("chatlist-"+this.userid):[];
grouplist.forEach((cell,ii)=>{
if(cell.id==id){
ret=ii;
}
});
return ret;
},
//
async getPrivateInfo(info) {
if(info.ifload==0){
info[info.fromuser]=(info.fromuser!=this.userid? await this.getFriend(info.fromuser):{});
this.updateChatList(info);
}
else{
this.updateChatList(info);
}
},
//
async getGroupInfo(info) {
if(info.ifload==0){
const {data: res} = await uni.$http.get('/api/group/find/'+info.groupId);
if(res.data){
var data = res.data;
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.ownerId=data.ownerId;
info.productId=data.productId;
info.productName=data.productName;
info[data.ownerId]=(data.ownerId!= this.userid? await this.getFriend(data.ownerId):{});
info[data.customerService]=(data.customerService!= this.userid? await this.getFriend(data.customerService):{});
info[data.instructor]=(data.instructor!= this.userid? await this.getFriend(data.instructor):{});
this.updateChatGroupList(info);
}
}
else{
this.updateChatGroupList(info);
}
},
async getFriend(id){
var name="匿名",img=require("@/static/image/girl.png");
const {data: res} = await uni.$http.get("/api/friend/find/"+id);
if(res.data){
name=res.data.nickName?res.data.nickName:"匿名";
img=res.data.headImage?res.data.headImage:require("@/static/image/girl.png");
}
return {
name:name,
img:img
};
},
async updateChatGroupList(info){
var idx=this.ifadd(info.id);
if(idx<0){
//
this.grouplist.push(info);
this.$forceUpdate();
}
else{
this.grouplist[idx].content=info.content;
this.grouplist[idx].datetime=info.datetime;
this.grouplist[idx].fromuser=info.fromuser;
this.grouplist[idx].type=info.type;
this.$forceUpdate();
}
//
this.reorder();
myCache("chatlist-"+ this.userid,this.grouplist);
//
//
var name=info[info.sendId]?info[info.sendId].name:"匿名",img=info[info.sendId]?info[info.sendId].img:require("@/static/image/girl.png");
var msgchat=myCache(info.id);
if(!msgchat){
//
let firstmsg = [{
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?(info.time?info.time:5):0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.minId,
"minId": info.minId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
}];
myCache(info.id,firstmsg);
}
else{
//
if(this.ifchatadd(info.id,info.minId)){
//
let firstmsg = {
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?(info.time?info.time:5):0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.minId,
"minId": info.minId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
};
msgchat.push(firstmsg);
myCache(info.id,msgchat);
}
}
},
async updateChatList(info){
//
var idx=this.ifadd(info.id);
if(idx<0){
this.grouplist.push(info);
this.$forceUpdate();
}
else{
this.grouplist[idx].content=info.content;
this.grouplist[idx].datetime=info.datetime;
this.grouplist[idx].fromuser=info.fromuser;
this.grouplist[idx].type=info.type;
this.$forceUpdate();
}
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
//
//
var name=info[info.fromuser]?info[info.fromuser].name:"匿名",img=info[info.fromuser]?info[info.fromuser].img:require("@/static/image/girl.png");
var msgchat=myCache(info.id);
if(!msgchat){
//
let firstmsg = [{
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?(info.time?info.time:5):0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.minId,
"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{
if(this.ifchatadd(info.id,info.minId)){
//
let firstmsg = {
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?(info.time?info.time:5):0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.minId,
"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);
}
}
},
},
}
</script>

@ -86,6 +86,10 @@ $http.afterRequest = function (response) {
}
Vue.config.productionTip = false;
Vue.prototype.isConnected = false; // ws是否已经连接;
Vue.prototype.heartbeatInterval = null; // 心跳;
Vue.prototype.heartbeatTimeout =20000; // ws20秒执行一次
App.mpType = "app";
// 引入全局uView

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

@ -143,7 +143,7 @@
</template>
<script>
import { myCache,getcartNum,getcartLoseNum,getRemoteFile } from '../../utils/utils.js';
import { myCache,getcartNum,getmessageNum,getcartLoseNum,getRemoteFile } from '../../utils/utils.js';
import openlogin from "../components/openlogin.vue";
export default {
components: {
@ -214,6 +214,23 @@
this.phone = user.userphone;
this.checked = false;
this.getapicart();
var messageNum=getmessageNum();
console.log("messageNum",messageNum)
if(messageNum>0){
//
uni.setTabBarBadge({
//
index: 3,
text: messageNum+''
});
}
else{
uni.removeTabBarBadge({
index: 3
})
}
},
computed: {
//
@ -328,6 +345,7 @@
}
this.loseNum=getcartLoseNum();
this.$forceUpdate();
},
getcheck1(id){
var fcarts=myCache("carts");

@ -155,7 +155,7 @@
</template>
<script>
import { myCache,getcartNum,getRemoteFile } from '../../utils/utils.js';
import { myCache,getcartNum,getmessageNum,getRemoteFile } from '../../utils/utils.js';
import openlogin from "../components/openlogin.vue";
import selShop from "../components/selShop.vue";
export default {
@ -330,6 +330,23 @@
index: 4
})
}
var messageNum=getmessageNum();
console.log("messageNum",messageNum)
if(messageNum>0){
//
uni.setTabBarBadge({
//
index: 3,
text: messageNum+''
});
}
else{
uni.removeTabBarBadge({
index: 3
})
}
},
mounted() {
if(this.userid==""||this.userid=="0"){

@ -239,10 +239,9 @@
oldTime: new Date(),
inputh: '90',
ifaudio:false, //
socketTask: null, // WebSocket
isConnected: false, // WebSocket
heartbeatInterval: null, // 20
heartbeatTimeout: 20000, // 20
// isConnected: false, // WebSocket
// heartbeatInterval: null, // 20
// heartbeatTimeout: 20000, // 20
//
ifsend: false,
sendinfo:{
@ -287,39 +286,195 @@
this.$forceUpdate();
}
}
},
onShow() {
//
this.getchatstore();
var that=this;
// :id
setTimeout(() => {
this.screendo(this.unshiftmsg.length - 1);
}, 100);
that.screendo(that.unshiftmsg.length - 1);
if(!that.isConnected){
// socket
that.reconnect();
}
}, 500);
//
if(this.heartbeatInterval){
clearInterval(this.heartbeatInterval); //
}
},
onBackPress(options) {
if (options.from === 'backbutton') {
//
//
console.log('返回按钮被点击');
// this.closeWebSocket();
// uni.onSocketClose(function (res) {
// console.log('WebSocket ');
// });
return false;
}
},
beforeDestroy() {
console.log('界面关闭socketbeforeDestroy');
// WebSocket
// this.closeWebSocket();
// clearInterval(this.heartbeatInterval); //
},
methods: {
//
startHeartbeat() {
console.log("startHeartbeat");
var that=this;
this.heartbeatInterval = setInterval(() => {
if(this.isConnected){
uni.sendSocketMessage({
data: JSON.stringify({
'cmd': 1,//
'data': {
'accessToken':uni.getStorageSync("token")
},
}), // ,
success(re) {
console.log(re);
console.log('消息发送成功!')
},
fail(err) {
console.log(err);
console.log('消息发送失败!');
that.reconnect();
}
});
}
}, this.heartbeatTimeout);
},
//
reconnect () {
if (!this.isConnected) {
clearTimeout(this.heartbeatInterval);
this.heartbeatInterval = setTimeout(() => {
console.log('开始重连...');
this.socketinit();
},this.heartbeatTimeout);
}
},
// ws
socketinit(){
var that = this;
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');
// minId 线
that.getReadedId();
},
fail: (res) => {
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) {
console.log(err);
console.log('消息发送失败!')
}
});
//
this.startHeartbeat();
});
uni.onSocketClose(res => {
console.log('WebSocket连接已关闭');
this.isConnected = false;
this.$forceUpdate();
// socket
this.reconnect();
});
uni.onSocketError(err => {
console.error('WebSocket连接打开失败请检查', err);
this.isConnected = false;
this.$forceUpdate();
// socket
this.reconnect();
});
uni.onSocketMessage(res => {
console.log('收到WebSocket服务器消息');
if(res.data){
let data=JSON.parse(res.data);
console.log("onSocketMessage",data);
if(data.data){
data=data.data;
if(data){
//
if(this.ifadd(data.id)){
//
if(data.recvId&&data.recvId.toString()==that.userid.toString()&&data.sendId.toString()==this.info.friendId.toString()){
//
// 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.content=decodeURIComponent(data.content);
}
//
if(data.type == 1) {
this.imgMsg.unshift(data.content)
}
//
let mdata = {
"fromname": this.info.chatName,
"fromuser": this.info.friendId,
"headimg": this.info.chatAvatar,
"toname": this.userName,
"touser": this.userid,
"content": data.content,
"time": data.type==3?5:0,
"ifaudio":data.type==3? true:false,
"fromtime": data.sendTime,
"type": data.type,
"id": data.id,
"recvId": data.recvId,
"sendId": data.sendId
};
this.setMsglist(mdata)
// socket
var chatlastinfo={
id: this.info.chatId,
content:data.content,
type:data.type,
minId: data.id,
datetime: data.sendTime,
name: this.info.chatName,
userid: this.userid,
fromuser: this.info.friendId,
img: this.info.chatAvatar,
sort:"privatechat"
};
//
this.updateChatList(chatlastinfo);
//
this.readed();
}
else{
// 10, "" 11, " " 12, " " 30,""
}
}
}
// 10, "" 11, " " 12, " " 30,""
if(data.type==12){
//
this.updateRead(data);
}
}
}
}
});
},
gotoDetail(item){
var send=item.send;
if(send){
@ -495,160 +650,9 @@
});
return ret;
},
//
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;
this.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');
// minId 线
that.getReadedId();
},
fail: (res) => {
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) {
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(this.ifadd(data.id)){
//
if(data.recvId&&data.recvId.toString()==that.userid.toString()&&data.sendId.toString()==this.info.friendId.toString()){
//
// 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.content=decodeURIComponent(data.content);
}
//
if(data.type == 1) {
this.imgMsg.unshift(data.content)
}
let mdata = {
"fromname": this.info.chatName,
"fromuser": this.info.friendId,
"headimg": this.info.chatAvatar,
"toname": this.userName,
"touser": this.userid,
"content": data.content,
"time": data.type==3?5:0,
"ifaudio":data.type==3? true:false,
"fromtime": data.sendTime,
"type": data.type,
"id": data.id,
"recvId": data.recvId,
"sendId": data.sendId
};
this.setMsglist(mdata)
// socket
var chatlastinfo={
id: this.info.chatId,
content:data.content,
type:data.type,
minId: data.id,
datetime: data.sendTime,
name: this.info.chatName,
userid: this.userid,
fromuser: this.info.friendId,
img: this.info.chatAvatar,
sort:"privatechat"
};
this.updateChatList(chatlastinfo);
//
this.readed();
}
else{
// 10, "" 11, " " 12, " " 30,""
}
}
}
// 10, "" 11, " " 12, " " 30,""
if(data.type==12){
//
this.updateRead(data);
}
}
}
}
});
uni.onSocketClose(res => {
console.log('WebSocket连接已关闭');
that.isConnected = false;
clearInterval(that.heartbeatInterval); //
});
uni.onSocketError(err => {
console.error('WebSocket连接打开失败请检查', err);
clearInterval(that.heartbeatInterval); //
});
},
// WebSocket
closeWebSocket() {
if (this.socket) {
uni.closeSocket();
this.socket = null;
this.isConnected = false;
}
},
async setMsglist(data){
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':'')))),
// console.log("setMsglist",data)
this.unshiftmsg.push(data);
this.$forceUpdate();
setTimeout(() => {
@ -795,11 +799,9 @@
//
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,
@ -1201,7 +1203,7 @@
}
},
updateChatList(chatlastinfo){
//
//
var chatlist = myCache("chatlist-"+this.userid);
if(chatlist&&chatlist.length>0){
var ifexist=0;

File diff suppressed because it is too large Load Diff

@ -90,29 +90,36 @@
<text class="uname">{{item.fromname}}</text>
</view>
<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="rcon">
<view class="read" @click="openRead(item)">{{item.read?item.read.length:0}}</view>
<view class="noread" @click="openNoRead(item)">{{item.read?3-item.read.length:3}}</view>
</view>
<view class="msg-text">
<text selectable>{{item.content}}</text>
</view>
</view>
<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>
<view class="rcon">
<view class="read" @click="openRead(item)">{{item.read?item.read.length:0}}</view>
<view class="noread" @click="openNoRead(item)">{{item.read?3-item.read.length:3}}</view>
</view>
<image :src="item.content" class="msg-img" mode="widthFix"></image>
</view>
<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>
<view class="rcon">
<view class="read" @click="openRead(item)">{{item.read?item.read.length:0}}</view>
<view class="noread" @click="openNoRead(item)">{{item.read?3-item.read.length:3}}</view>
</view>
<!-- 视频 -->
<myVideo :videoUrl="item.content"></myVideo>
</view>
<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="rcon">
<view class="read" @click="openRead(item)">{{item.read?item.read.length:0}}</view>
<view class="noread" @click="openNoRead(item)">{{item.read?3-item.read.length:3}}</view>
</view>
<view class="msg-text voice" :style="{width: item.time>2? item.time*40+'rpx' :'auto'}">
{{item.time}}
<view class="voicel" v-if="item.ifaudio" >
@ -122,8 +129,10 @@
</view>
</view>
<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 class="rcon">
<view class="read" @click="openRead(item)">{{item.read?item.read.length:0}}</view>
<view class="noread" @click="openNoRead(item)">{{item.read?3-item.read.length:3}}</view>
</view>
<view v-if="item.send" class="msg-product" @click="gotoDetail(item)">
<view v-if="item.send.type==3" class="zx">
<view class="zxname">订单咨询</view>
@ -199,23 +208,23 @@
<submit @inputs="inputs" @heights="heights"></submit>
<u-toast ref="uToast" />
<!-- 普通弹窗 -->
<!-- 群公告 -->
<uni-popup ref="popup" background-color="#fff">
<view class="popup-content" :class="{ 'popup-height': 'right' }">
<view class="example">
<view class="order">
<view class="chatlist">
<view class="chatcell">
<image class="user-img" :src="info.teacherimg||'/static/image/jltx.png'"></image>
<text class="user-name">{{info.teachername||"教练"}}</text>
<image class="user-img" :src="info.instructorimg||'/static/image/jltx.png'"></image>
<text class="user-name">{{info.instructorname||"教练"}}</text>
</view>
<view class="chatcell">
<image class="user-img" :src="info.friendimg||'/static/image/kfr.png'"></image>
<text class="user-name">{{info.friendname||"客服"}}</text>
<image class="user-img" :src="info.customerimg||'/static/image/kfr.png'"></image>
<text class="user-name">{{info.customername||"客服"}}</text>
</view>
<view class="chatcell">
<image class="user-img" :src="info.headImage||'/static/image/mr.png'"></image>
<text class="user-name">{{info.showNickName||"咨询用户"}}</text>
<image class="user-img" :src="info.ownerimg||'/static/image/mr.png'"></image>
<text class="user-name">{{info.ownername||"咨询用户"}}</text>
</view>
</view>
</view>
@ -241,6 +250,31 @@
</view>
</uni-popup>
<!-- 未读已读 -->
<uni-popup ref="popupRead" background-color="#fff">
<view class="popup-content" :class="{ 'popup-height': 'right' }">
<view class="example">
<view class="order">
<view class="qhbtn">
<view :class="ifread?'btn cur':'btn'" @click="qhrd(1)">({{readinfo.read.length}})</view>
<view :class="ifread?'btn':'btn cur'" @click="qhrd(2)">({{readinfo.noread.length}})</view>
</view>
<view class="readlist" v-if="ifread">
<view class="readcell" v-for="(value, key) in readinfo.read" :key="value.id">
<text class="readname">{{value.name}}</text>
<text class="readtime">{{value.time}}</text>
</view>
</view>
<view class="readlist" v-else>
<view class="readcell" v-for="(value, key) in readinfo.noread" :key="value.id">
<text class="readname">{{value.name}}</text>
</view>
</view>
</view>
</view>
</view>
</uni-popup>
</view>
</template>
@ -314,10 +348,9 @@
oldTime: new Date(),
inputh: '90',
ifaudio:false, //
socketTask: null, // WebSocket
isConnected: false, // WebSocket
heartbeatInterval: null, // 20
heartbeatTimeout: 20000, // 20
// isConnected: false, // WebSocket
// heartbeatInterval: null, // 20
// heartbeatTimeout: 20000, // 20
//
ifsend: false,
sendinfo:{
@ -332,6 +365,11 @@
// isCourse: 0,
// quantity:1,
// spData:{"":"绿","":"80"}
},
ifread:true,
readinfo:{
read:[],
noread:[]
}
}
},
@ -341,10 +379,11 @@
this.userName=user.nickName?user.nickName:"";
this.userid=user.userid?user.userid:"";
this.userheadimg=user.avatar?user.avatar:require("@/static/image/girl.png");
if(options.data){
//
this.info=JSON.parse(decodeURIComponent(options.data));
console.log("chat",this.info)
console.log("groupchat",this.info)
//
var title = this.info.chatName;
uni.setNavigationBarTitle({
@ -361,37 +400,30 @@
this.sendinfo=null;
this.$forceUpdate();
}
}
},
onShow() {
//
this.getchatstore();
//
this.getrwinfo();
var that=this;
// :id
setTimeout(() => {
console.log("onShow")
this.screendo(this.unshiftmsg.length - 1);
}, 100);
that.screendo(that.unshiftmsg.length - 1);
if(!that.isConnected){
// socket
that.reconnect();
}
}, 500);
this.getGroupInfo(this.info.groupId);
//
if(this.heartbeatInterval){
clearInterval(this.heartbeatInterval); //
}
},
onBackPress(options) {
if (options.from === 'backbutton') {
//
//
console.log('返回按钮被点击');
// this.closeWebSocket();
// uni.onSocketClose(function (res) {
// console.log('WebSocket ');
// });
return false;
}
},
// buttons
onNavigationBarButtonTap: async function(e) {
@ -400,41 +432,213 @@
this.$refs.popup.open("right");
}
},
beforeDestroy() {
console.log('界面关闭socketbeforeDestroy');
// WebSocket
// this.closeWebSocket();
// clearInterval(this.heartbeatInterval); //
},
methods: {
//
startHeartbeat() {
console.log("startHeartbeat")
var that=this;
this.heartbeatInterval = setInterval(() => {
if(this.isConnected){
uni.sendSocketMessage({
data: JSON.stringify({
'cmd': 1,//
'data': {
'accessToken':uni.getStorageSync("token")
},
}), // ,
success(re) {
console.log(re);
console.log('消息发送成功!')
},
fail(err) {
console.log(err);
console.log('消息发送失败!');
that.reconnect();
}
});
}
}, this.heartbeatTimeout);
},
//
reconnect () {
if (!this.isConnected) {
clearTimeout(this.heartbeatInterval);
this.heartbeatInterval = setTimeout(() => {
console.log('开始重连...');
this.socketinit();
},this.heartbeatTimeout);
}
},
// ws
socketinit(){
var that = this;
if (!this.isConnected) {
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');
// minId 线
that.getReadedId();
},
fail: (res) => {
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) {
console.log(err);
console.log('消息发送失败!')
}
});
//
this.startHeartbeat();
});
uni.onSocketClose(res => {
console.log('WebSocket连接已关闭');
this.isConnected = false;
this.$forceUpdate();
// socket
this.reconnect();
});
uni.onSocketError(err => {
console.error('WebSocket连接打开失败请检查', err);
this.isConnected = false;
this.$forceUpdate();
// socket
this.reconnect();
});
uni.onSocketMessage(res => {
console.log('收到WebSocket服务器消息');
if(res.data){
let data=JSON.parse(res.data);
console.log("onSocketMessage",data);
if(data.cmd==4){
//
if(data.data){
data=data.data;
//
if(data.groupId==this.info.groupId){
//
if(this.ifadd(data.id)){
//
// 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){
this.getMsgSender(data);
//
this.readed();
}
else{
// 10, "" 11, " " 12, " " 30,""
}
}
// 10, "" 11, " " 12, " " 30,""
if(data.type==12){
//
this.updateRead(data);
}
}
}
}
}
});
}
},
//
async getGroupInfo(id) {
const {data: res} = await uni.$http.get('/api/group/find/'+id);
if(res.data){
var data = res.data;
}
},
//
async getrwinfo(){
//
const {data: res} = await uni.$http.get("/api/friend/find/"+this.info.friendId);
if(res.data){
var data=res.data;
this.info.friendname=data.nickName?data.nickName:"客服";
this.info.friendimg=data.headImage?data.headImage:require("@/static/image/kfr.png");
if(this.userid==this.info.customerService){
this.info.customername=this.userName;
this.info.customerimg=this.userheadimg;
this.$forceUpdate();
}
else{
this.info.friendname="客服";
this.info.friendimg=require("@/static/image/kfr.png");
this.$forceUpdate();
const {data: res} = await uni.$http.get("/api/friend/find/"+this.info.customerService);
if(res.data){
var data=res.data;
this.info.customername=data.nickName?data.nickName:"客服";
this.info.customerimg=data.headImage?data.headImage:require("@/static/image/kfr.png");
this.$forceUpdate();
}
else{
this.info.customername="客服";
this.info.customerimg=require("@/static/image/kfr.png");
this.$forceUpdate();
}
}
//
const {data: res1} = await uni.$http.get("/api/friend/find/"+this.info.teacherId);
if(res1.data){
var data=res1.data;
this.info.teachername=data.nickName?data.nickName:"教练";
this.info.teacherimg=data.headImage?data.headImage:require("@/static/image/jltx.png");
if(this.userid==this.info.instructor){
this.info.instructorname=this.userName;
this.info.instructorimg=this.userheadimg;
this.$forceUpdate();
}
else{
this.info.teachername="教练";
this.info.teacherimg=require("@/static/image/jltx.png");
const {data: res1} = await uni.$http.get("/api/friend/find/"+this.info.instructor);
if(res1.data){
var data=res1.data;
this.info.instructorname=data.nickName?data.nickName:"教练";
this.info.instructorimg=data.headImage?data.headImage:require("@/static/image/jltx.png");
this.$forceUpdate();
}
else{
this.info.instructorname="教练";
this.info.instructorimg=require("@/static/image/jltx.png");
this.$forceUpdate();
}
}
//
if(this.userid==this.info.ownerId){
this.info.ownername=this.userName;
this.info.ownerimg=this.userheadimg;
this.$forceUpdate();
}
else{
const {data: res2} = await uni.$http.get("/api/friend/find/"+this.info.ownerId);
if(res2.data){
var data=res2.data;
this.info.ownername=data.nickName?data.nickName:"咨询用户";
this.info.ownerimg=data.headImage?data.headImage:require("@/static/image/jltx.png");
this.$forceUpdate();
}
else{
this.info.ownername="咨询用户";
this.info.ownerimg=require("@/static/image/jltx.png");
this.$forceUpdate();
}
}
},
gotoDetail(item){
var send=item.send;
@ -582,6 +786,8 @@
that.screendo(that.unshiftmsg.length-1);
}, 100);
}
//
this.readed();
}
catch(err){
console.log(err);
@ -609,121 +815,6 @@
});
return ret;
},
//
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);
},
// WebSocket
closeWebSocket() {
if (this.socket) {
uni.closeSocket();
this.socket = null;
this.isConnected = false;
}
},
// ws
socketinit(){
var that = this;
if (!this.isConnected) {
this.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');
// minId 线
that.getReadedId();
},
fail: (res) => {
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) {
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.cmd==4){
//
if(data.data){
data=data.data;
//
if(data.groupId==this.info.groupId){
if(this.ifadd(data.id)){
//
// 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){
this.getMsgSender(data);
//
this.readed();
}
else{
// 10, "" 11, " " 12, " " 30,""
}
}
// 10, "" 11, " " 12, " " 30,""
if(data.type==12){
//
this.updateRead(data);
}
}
}
}
}
});
uni.onSocketClose(res => {
console.log('WebSocket连接已关闭');
that.isConnected = false;
clearInterval(that.heartbeatInterval); //
});
uni.onSocketError(err => {
console.error('WebSocket连接打开失败请检查', err);
clearInterval(that.heartbeatInterval); //
});
}
},
//
async getMsgSender(data){
var nickName="匿名";
@ -740,7 +831,6 @@
}
},
async msgMerge(data,nickName,headImage){
if(data.type==0){
data.content=decodeURIComponent(data.content);
}
@ -925,11 +1015,6 @@
this.unshiftmsg.unshift(mdata);
}
});
// // :id
// setTimeout(() => {
// that.screendo(gotonum -1);
// }, 100);
// :id
setTimeout(() => {
that.screendo(that.unshiftmsg.length-1);
}, 100);
@ -957,11 +1042,10 @@
sort:"groupchat"
};
this.updateChatList(chatlastinfo);
//
this.readed();
}
// }
//
this.readed();
},
screendo(scrindex){
@ -1320,6 +1404,9 @@
friendId: this.info.friendId, // userid
teacherId: this.info.teacherId?this.info.teacherId:this.info.instructor, // userid
fromuser: this.info.friendId,
customerService: this.info.customerService,
instructor: this.info.instructor,
ownerId: this.info.ownerId,
img: this.info.chatAvatar,
sort:"groupchat",
send:this.sendinfo
@ -1353,7 +1440,10 @@
chatlist.forEach((cell,i)=>{
if(cell.id==this.info.chatId){
ifexist++;
chatlist[i]=chatlastinfo;
chatlist[i].content=chatlastinfo.content;
chatlist[i].datetime=chatlastinfo.datetime;
chatlist[i].fromuser=chatlastinfo.fromuser;
chatlist[i].type=chatlastinfo.type;
}
});
if(ifexist==0){
@ -1371,12 +1461,25 @@
},
//
updateRead(item){
console.log(this.info)
console.log("updateRead")
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;
var read={
readedId:item.readedId,
readTime:new Date()
}
if(this.unshiftmsg[index].read){
let tmp = this.unshiftmsg[index].read.some(val => {
return val.readedId == item.readedId;
});
if(!tmp){
this.unshiftmsg[index].read.push(read);
}
}
else{
this.unshiftmsg[index].read=[];
this.unshiftmsg[index].read.push(read);
}
this.$forceUpdate();
}
@ -1400,6 +1503,147 @@
this.unshiftmsg[index]["headimg"]= require("@/static/image/girl.png");
this.$forceUpdate();
},
//
openNoRead(item){
this.ifread=false;
this.$forceUpdate();
this.readinfo.read=[];
this.readinfo.noread=[];
//
if(item.read&&item.read.length>0){
item.read.forEach(cell=>{
if(cell.readedId==this.info.customerService){
this.readinfo.read.push({
id:cell.readedId,
name:this.info.customername,
time:this.changeTime(cell.readTime)
})
}
else if(cell.readedId==this.info.instructor){
this.readinfo.read.push({
id:cell.readedId,
name:this.info.instructorname,
time:this.changeTime(cell.readTime)
})
}
else if(cell.readedId==this.info.ownerId){
this.readinfo.read.push({
id:cell.readedId,
name:this.info.ownername,
time:this.changeTime(cell.readTime)
})
}
});
}
//
var that=this;
let tmp = this.readinfo.read.some(val => {
return val.id == that.info.customerService;
});
if(!tmp){
this.readinfo.noread.push({
id:this.info.customerService,
name:this.info.customername
})
}
tmp = this.readinfo.read.some(val => {
return val.id == that.info.instructor;
});
if(!tmp){
this.readinfo.noread.push({
id:this.info.instructor,
name:this.info.instructorname
})
}
tmp = this.readinfo.read.some(val => {
return val.id == that.info.ownerId;
});
if(!tmp){
this.readinfo.noread.push({
id:this.info.ownerId,
name:this.info.ownername
})
}
this.$refs.popupRead.open("right");
},
//
openRead(item){
this.ifread=true;
this.$forceUpdate();
this.readinfo.read=[];
this.readinfo.noread=[];
//
if(item.read&&item.read.length>0){
item.read.forEach(cell=>{
if(cell.readedId==this.info.customerService){
this.readinfo.read.push({
id:cell.readedId,
name:this.info.customername,
time:this.changeTime(cell.readTime)
})
}
else if(cell.readedId==this.info.instructor){
this.readinfo.read.push({
id:cell.readedId,
name:this.info.instructorname,
time:this.changeTime(cell.readTime)
})
}
else if(cell.readedId==this.info.ownerId){
this.readinfo.read.push({
id:cell.readedId,
name:this.info.ownername,
time:this.changeTime(cell.readTime)
})
}
});
}
//
var that=this;
let tmp = this.readinfo.read.some(val => {
return val.id == that.info.customerService;
});
if(!tmp){
this.readinfo.noread.push({
id:this.info.customerService,
name:this.info.customername
})
}
tmp = this.readinfo.read.some(val => {
return val.id == that.info.instructor;
});
if(!tmp){
this.readinfo.noread.push({
id:this.info.instructor,
name:this.info.instructorname
})
}
tmp = this.readinfo.read.some(val => {
return val.id == that.info.ownerId;
});
if(!tmp){
this.readinfo.noread.push({
id:this.info.ownerId,
name:this.info.ownername
})
}
this.$refs.popupRead.open("right");
},
qhrd(type){
if(type==1){
this.ifread=true;
this.$forceUpdate();
}
else{
this.ifread=false;
this.$forceUpdate();
}
},
}
}
</script>
@ -1723,6 +1967,12 @@
.msg-right {
flex-direction: row-reverse;
.rcon{
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: flex-end;
}
.read{
font-size: 24rpx;
color: #888;
@ -2066,6 +2316,51 @@
box-sizing: border-box;
padding: 0rpx 20rpx;
}
.qhbtn{
width: 100%;
display: flex;
flex-direction: row;
.btn{
width: 120rpx;
height: 60rpx;
border-radius: 20rpx;
background-color: #eee;
color: #000;
font-size: 26rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16rpx;
margin-top: 16rpx;
}
.cur{
background-color: #00a89b;
color: #fff;
}
}
.readlist{
display: flex;
flex-wrap: wrap;
padding: 20rpx 0 0 10rpx ;
}
.readcell{
display: flex;
justify-content: space-between;
width: 100%;
padding: 16rpx 0;
border-bottom: 1rpx solid #eee;
.readtime{
font-size: 24rpx;
color: #888;
}
.readname{
font-size: 26rpx;
color: #33383c;
display: flex;
flex: 1;
}
}
.chatlist{
display: flex;
flex-wrap: wrap;

@ -212,11 +212,6 @@
return false;
}
},
beforeDestroy() {
console.log('界面关闭socketbeforeDestroy');
// WebSocket
this.closeWebSocket();
},
methods: {
gotoInfo(item){
var data=encodeURIComponent(JSON.stringify(item));

File diff suppressed because it is too large Load Diff

@ -85,7 +85,7 @@
<script>
import checkupdate from "@/uni_modules/uni-upgrade-center-app/utils/check-update.js"
import { myCache,getcartNum,getRemoteFile,ifnonet } from '../../utils/utils.js';
import { myCache,getcartNum,getmessageNum,getRemoteFile,ifnonet } from '../../utils/utils.js';
import openlogin from "../components/openlogin.vue";
import top from "../components/top.vue";
import service from "../components/service.vue";
@ -280,6 +280,22 @@
})
}
var messageNum=getmessageNum();
console.log("messageNum",messageNum)
if(messageNum>0){
//
uni.setTabBarBadge({
//
index: 3,
text: messageNum+''
});
}
else{
uni.removeTabBarBadge({
index: 3
})
}
// banner
// this.getBanner();

@ -235,6 +235,7 @@
reason: item.reason,
customerService: item.customerService,
instructor: item.instructor,
ownerId: item.ownerId,
productId: item.productId,
productName: item.productName
}

@ -52,7 +52,7 @@
</template>
<script>
import { myCache } from '../../utils/utils.js';
import { getcartNum,getmessageNum,myCache } from '../../utils/utils.js';
import dateTime from '@/common/dateTime.js';
export default {
data() {
@ -75,28 +75,39 @@
], // u-swipe-action
imgurl:uni.$http.baseUrl,
grouplist:[],
socketTask: null,
isConnected: false, // WebSocket
socketmsg:[],//
heartbeatInterval: null, // 20
heartbeatTimeout: 20000, // 20
// isConnected: false, // WebSocket
// heartbeatInterval: null, // 20
// heartbeatTimeout: 20000, // 20
}
},
onLoad(options) {
},
onShow(){
this.openId = myCache('openId');
var user = myCache('user');
this.userid = user.userid? user.userid:'';
this.userName=user.nickName?user.nickName:"";
this.userheadimg=user.avatar?user.avatar:require("@/static/image/girl.png");
this.phone = user.userphone;
//
if(this.heartbeatInterval){
clearInterval(this.heartbeatInterval); //
}
//
this.loadData();
var that=this;
setTimeout(() => {
if(!that.isConnected){
// socket
that.reconnect();
}
}, 500);
that.setmsgnum();
setTimeout(() => {
that.setmsgnum();
}, 2000);
},
onPullDownRefresh() {
console.log('onPullDownRefresh');
@ -104,73 +115,47 @@
uni.stopPullDownRefresh()
},500);
},
onBackPress(options) {
if (options.from === 'backbutton') {
//
//
console.log('返回按钮被点击');
// this.closeWebSocket();
// uni.onSocketClose(function (res) {
// console.log('WebSocket ');
// });
return false;
}
},
beforeDestroy() {
console.log('界面关闭socketbeforeDestroy');
// WebSocket
// this.closeWebSocket();
// clearInterval(this.heartbeatInterval); //
},
beforeRouteLeave(to, from, next) {
console.log('界面关闭socketbeforeRouteLeave');
next();
},
methods: {
handleLongPress(info,index) {
console.log(index);
this.$refs.swipeRef[index].open();
},
//
actionClick(info,index) {
console.log(info,index);
var that=this;
uni.showModal({
title: '提示',
content: "确定要删除此聊天记录吗?",
cancelText: '取消',
confirmText: '确定',
success: ress => {
if (ress.confirm) {
that.$refs.swipeRef[index].close();
myCache(info.id,"");
that.grouplist.splice(index, 1);
that.$forceUpdate();
myCache("chatlist-"+this.userid,that.grouplist);
}
}
});
},
//
startHeartbeat() {
var that=this;
console.log("startHeartbeat")
this.heartbeatInterval = setInterval(() => {
if (this.socketTask) {
this.socketTask.send({
data: JSON.stringify({
'cmd': 1,//
'data': {
'accessToken':uni.getStorageSync("token")
},
}) //
});
}
if(this.isConnected){
uni.sendSocketMessage({
data: JSON.stringify({
'cmd': 1,//
'data': {
'accessToken':uni.getStorageSync("token")
},
}), // ,
success(re) {
console.log(re);
console.log('消息发送成功!')
},
fail(err) {
console.log(err);
console.log('消息发送失败!');
that.reconnect();
}
});
}
}, this.heartbeatTimeout);
},
//
reconnect () {
if (!this.isConnected) {
clearTimeout(this.heartbeatInterval);
this.heartbeatInterval = setTimeout(() => {
console.log('开始重连...');
this.socketinit();
},this.heartbeatTimeout);
}
},
// ws
socketinit(){
var that = this;
that.socketTask=uni.connectSocket({
uni.connectSocket({
url: "wss://www.sanduolantoyoga.com/yoga-imserver/",
header: {
// 'content-type': 'application/json',
@ -189,8 +174,8 @@
uni.onSocketOpen(resopen => {
console.log('WebSocket连接已打开');
that.isConnected = true;
that.$forceUpdate();
this.isConnected = true;
this.$forceUpdate();
uni.sendSocketMessage({
data: JSON.stringify({
"cmd": 0,//
@ -253,41 +238,59 @@
});
//
uni.onSocketClose(res => {
console.log('WebSocket连接已关闭',res);
this.isConnected = false;
this.$forceUpdate();
// socket
this.reconnect();
});
//
uni.onSocketError(err => {
console.error('WebSocket连接打开失败请检查', err);
this.isConnected = false;
this.$forceUpdate();
// socket
this.reconnect();
});
//
uni.onSocketMessage(res => {
console.log('收到WebSocket服务器消息');
if(res.data){
var rs=JSON.parse(res.data);
console.log(rs);
console.log("onSocketMessage",rs);
if(rs.cmd==3){
//
if(rs.data){
var data=rs.data;
if(data.recvId&&(data.recvId).toString()==(that.userid).toString()){
if(data.recvId&&data.recvId==that.userid){
//
//
// 0: 1: 2: 3: 4: 10, "" 11, " "12, " " 30,""
if(data.type==0){
data.content=decodeURIComponent(data.content);
}
if(data.type==0||data.type==1||data.type==2||data.type==3||data.type==4||data.type==5||data.type==6){
var ifexist=0,chatinfo=null;
that.grouplist.forEach((cell,index)=>{
if(cell.fromuser==data.sendId&&cell.userid==data.recvId&&cell.sort=="privatechat"){
ifexist=1;
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){
if(data.type==0){
data.content=decodeURIComponent(data.content);
}
var id="privatechat-" + data.recvId +"-" + data.sendId;
var index=this.ifadd(id);
var chatinfo=null;
if(index>-1){
that.grouplist[index].sl=(that.grouplist[index].sl?that.grouplist[index].sl+1:1);
that.grouplist[index].content=data.content;
that.grouplist[index].datetime=data.sendTime;
that.grouplist[index].type=data.type;
that.grouplist[index].minId=data.id;
that.grouplist[index].ifload=1;
that.$forceUpdate();
chatinfo= JSON.parse(JSON.stringify(that.grouplist[index]));
}
else{
//
// socket
var chatlastinfo={
id: "privatechat-" + data.recvId +"-" + data.sendId,
chatinfo={
id: id,
content: data.content,
minId: data.id,
sl:1,
@ -297,13 +300,16 @@
userid: data.recvId,
fromuser: data.sendId,
img: "",
sort:"privatechat"
sort:"privatechat",
ifload:0
};
that.updateChatList(chatlastinfo);
}
else{
that.updateChatList(chatinfo);
this.grouplist.push(chatinfo);
this.$forceUpdate();
}
myCache("chatlist-"+this.userid,this.grouplist);
this.getPrivateInfo(chatinfo);
//
this.setmsgnum();
}
else{
// 10, "" 11, " " 12, " " 30,""
@ -320,30 +326,32 @@
//
//
// 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){
if(data.type==0){
data.content=decodeURIComponent(data.content);
}
var id="groupchat-" + data.groupId;
var index=this.ifadd(id);
var chatinfo=null;
if(index>-1){
that.grouplist[index].sl=(that.grouplist[index].sl?that.grouplist[index].sl+1:1);
that.grouplist[index].content=data.content;
that.grouplist[index].datetime=data.sendTime;
that.grouplist[index].fromuser=data.sendId;
that.grouplist[index].type=data.type;
that.grouplist[index].minId=data.id;
that.grouplist[index].ifload=1;
that.$forceUpdate();
chatinfo= JSON.parse(JSON.stringify(that.grouplist[index]));
}
else{
//
// socket
var chatlastinfo={
id: "groupchat-" + data.groupId,
groupId:data.groupId,
chatinfo={
id: id,
groupId: data.groupId,
content: data.content,
minId: data.id,
sl:1,
@ -355,17 +363,19 @@
img: "",
sendId: data.sendId,
sendNickName: data.sendNickName,
sort:"groupchat"
sort:"groupchat",
ifload:0
};
that.getGroupInfo(chatlastinfo);
}
else{
that.getGroupInfo(that.grouplist[idx]);
this.grouplist.push(chatinfo);
this.$forceUpdate();
}
myCache("chatlist-"+this.userid,this.grouplist);
//
this.setmsgnum();
this.getGroupInfo(chatinfo);
}
else{
// 10, "" 11, " " 12, " " 30,""
}
}
}
@ -373,32 +383,56 @@
}
});
uni.onSocketClose(res => {
console.log('WebSocket连接已关闭',res);
that.isConnected = false;
that.$forceUpdate();
clearInterval(that.heartbeatInterval); //
});
uni.onSocketError(err => {
console.error('WebSocket连接打开失败请检查', err);
that.isConnected = false;
that.$forceUpdate();
clearInterval(that.heartbeatInterval); //
});
},
// WebSocket
closeWebSocket() {
uni.closeSocket();
this.isConnected = false;
this.$forceUpdate()
//
setmsgnum(){
var messageNum=getmessageNum();
if(messageNum>0){
//
uni.setTabBarBadge({
//
index: 3,
text: messageNum+''
});
}
else{
uni.removeTabBarBadge({
index: 3
})
}
},
handleLongPress(info,index) {
console.log(index);
this.$refs.swipeRef[index].open();
},
//
actionClick(info,index) {
console.log(info,index);
var that=this;
uni.showModal({
title: '提示',
content: "确定要删除此聊天记录吗?",
cancelText: '取消',
confirmText: '确定',
success: ress => {
if (ress.confirm) {
that.$refs.swipeRef[index].close();
myCache(info.id,"");
that.grouplist.splice(index, 1);
that.$forceUpdate();
myCache("chatlist-"+this.userid,that.grouplist);
//
this.setmsgnum();
}
}
});
},
//
ifadd(id){
var ret=0;
var ret=-1;
this.grouplist.forEach((cell,ii)=>{
if(cell.id==id){
ret=ii+1;
ret=ii;
}
});
return ret;
@ -416,6 +450,8 @@
this.grouplist[index]["sl"]=0;
this.$forceUpdate();
myCache("chatlist-"+this.userid,this.grouplist);
//
this.setmsgnum();
//
if(chat.sort=="privatechat"){
//
@ -455,6 +491,7 @@
reason: chat.reason,
customerService: chat.customerService,
instructor: chat.instructor,
ownerId: chat.ownerId,
productId: chat.productId,
productName: chat.productName
}
@ -483,8 +520,9 @@
setTimeout(() => {
that.reorder();
myCache("chatlist-"+this.userid,that.grouplist);
//
this.setmsgnum();
}, 300);
// socket
this.socketinit();
},
@ -524,7 +562,8 @@
img: "",
sendId: cell.sendId,
sendNickName: cell.sendNickName,
sort:"groupchat"
sort:"groupchat",
ifload:1
};
this.getGroupInfo(chatlastinfo,index);
});
@ -549,9 +588,11 @@
userid: cell.recvId,
fromuser: cell.sendId,
img: "",
sort:"privatechat"
sort:"privatechat",
ifload:1
};
this.updateChatList(chatlastinfo,index);
this.getPrivateInfo(chatlastinfo);
});
}
},
@ -602,6 +643,8 @@
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
//
this.setmsgnum();
}
}
// }
@ -628,150 +671,129 @@
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
//
this.setmsgnum();
}
}
// }
}
},
//
async getPrivateInfo(info) {
if(info.ifload==0){
info[info.fromuser]=(info.fromuser!=this.userid? await this.getFriend(info.fromuser):{});
info.name=info[info.fromuser]?info[info.fromuser].name:"匿名";
info.img=info[info.fromuser]?info[info.fromuser].img:require("@/static/image/girl.png");
this.updateChatList(info);
}
else{
this.updateChatList(info);
}
},
//
async getGroupInfo(info) {
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;
if(info.ifload==0){
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.ownerId=data.ownerId;
info.productId=data.productId;
info.productName=data.productName;
info[data.ownerId]=(data.ownerId!=this.userid? await this.getFriend(data.ownerId):{});
info[data.customerService]=(data.customerService!= this.userid? await this.getFriend(data.customerService):{});
info[data.instructor]=(data.instructor!=this.userid? await this.getFriend(data.instructor):{});
this.updateChatGroupList(info);
}
}
else{
this.updateChatGroupList(info);
}
},
async updateChatGroupList(info){
var name=info.name,img=info.img||require("@/static/image/girl.png");
const {data: res} = await uni.$http.get("/api/friend/find/"+info.sendId);
async getFriend(id){
var name="匿名",img=require("@/static/image/girl.png");
const {data: res} = await uni.$http.get("/api/friend/find/"+id);
if(res.data){
var data=res.data;
name=data.nickName?data.nickName:"匿名";
img=data.headImage?data.headImage:require("@/static/image/girl.png");
var idx=this.ifadd(info.id);
if(!idx){
this.grouplist.push(info);
this.$forceUpdate();
}
else{
this.grouplist[idx-1].content=info.content;
this.grouplist[idx-1].datetime=info.datetime;
this.grouplist[idx-1].fromuser=info.fromuser;
this.grouplist[idx-1].type=info.type;
this.$forceUpdate();
}
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
//
var msgchat=myCache(info.id);
if(!msgchat){
//
let firstmsg = [{
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?5:0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.id,
"minId": info.minId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
}];
console.log("firstmsg",firstmsg)
myCache(info.id,firstmsg);
}
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);
}
name=res.data.nickName?res.data.nickName:"匿名";
img=res.data.headImage?res.data.headImage:require("@/static/image/girl.png");
}
return {
name:name,
img:img
};
},
async updateChatGroupList(info){
//
var name= "匿名",img= require("@/static/image/girl.png");
var idx=this.ifadd(info.id);
if(idx<0){
name=info[info.sendId]?info[info.sendId].name:"匿名";
img=info[info.sendId]?info[info.sendId].img:require("@/static/image/girl.png");
//
this.grouplist.push(info);
this.$forceUpdate();
}
else{
name="匿名";
img="../../static/image/girl.png";
var idx=this.ifadd(info.id);
if(!idx){
this.grouplist.push(info);
this.$forceUpdate();
}
else{
this.grouplist[idx-1].content=info.content;
this.grouplist[idx-1].datetime=info.datetime;
this.grouplist[idx-1].fromuser=info.fromuser;
this.grouplist[idx-1].type=info.type;
this.$forceUpdate();
}
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
var msgchat=myCache(info.id);
if(!msgchat){
//
let firstmsg = [{
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?5:0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.id,
"minId": info.minId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
}];
myCache(info.id,firstmsg);
}
else{
name=this.grouplist[idx][info.sendId].name?this.grouplist[idx][info.sendId].name:"匿名";
img=this.grouplist[idx][info.sendId].img?this.grouplist[idx][info.sendId].img:require("@/static/image/girl.png");
this.grouplist[idx].content=info.content;
this.grouplist[idx].datetime=info.datetime;
this.grouplist[idx].fromuser=info.fromuser;
this.grouplist[idx].type=info.type;
this.$forceUpdate();
}
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
//
this.setmsgnum();
//
var msgchat=myCache(info.id);
if(!msgchat){
//
let firstmsg = [{
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?(info.time?info.time:5):0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.minId,
"minId": info.minId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
}];
myCache(info.id,firstmsg);
}
else{
//
if(this.ifchatadd(info.id,info.minId)){
//
let firstmsg = {
"fromname": name, //
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?5:0,
"time": info.type==3?(info.time?info.time:5):0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.id,
"id": info.minId,
"minId": info.minId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
@ -779,133 +801,75 @@
msgchat.push(firstmsg);
myCache(info.id,msgchat);
}
}
},
async updateChatList(info){
const {data: res} = await uni.$http.get("/api/friend/find/"+info.fromuser);
if(res.data){
var data=res.data;
info.name=data.nickName?data.nickName:"匿名";
info.img=data.headImage?data.headImage:require("@/static/image/girl.png");
var idx=this.ifadd(info.id);
if(!idx){
this.grouplist.push(info);
this.$forceUpdate();
}
else{
// this.grouplist[idx-1].sl=(this.grouplist[idx-1].sl?this.grouplist[idx-1].sl+1:1);
this.grouplist[idx-1].content=info.content;
this.grouplist[idx-1].datetime=info.datetime;
this.grouplist[idx-1].fromuser=info.fromuser;
this.grouplist[idx-1].type=info.type;
this.$forceUpdate();
}
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
//
var msgchat=myCache(info.id);
if(!msgchat){
//
let firstmsg = [{
"fromname": info.name, //
"fromuser": info.fromuser, //
"headimg": info.img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?5:0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.id,
"minId": info.minId,
"recvId": info.recvId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
}];
myCache(info.id,firstmsg);
}
else{
//
let firstmsg = {
"fromname": info.name, //
"fromuser": info.fromuser, //
"headimg": info.img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?5:0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.id,
"minId": info.minId,
"recvId": info.recvId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
};
msgchat.push(firstmsg);
myCache(info.id,msgchat);
}
var name= "匿名",img= require("@/static/image/girl.png");
//
var idx=this.ifadd(info.id);
if(idx<0){
//
name=info[info.fromuser]?info[info.fromuser].name:"匿名";
img=info[info.fromuser]?info[info.fromuser].img:require("@/static/image/girl.png");
info.img=img;
info.name=name;
this.grouplist.push(info);
this.$forceUpdate();
}
else{
info.name="匿名";
info.img="../../static/image/girl.png";
var idx=this.ifadd(info.id);
if(!idx){
this.grouplist.push(info);
this.$forceUpdate();
}
else{
// this.grouplist[idx-1].sl=(this.grouplist[idx-1].sl?this.grouplist[idx-1].sl+1:1);
this.grouplist[idx-1].content=info.content;
this.grouplist[idx-1].datetime=info.datetime;
this.grouplist[idx-1].fromuser=info.fromuser;
this.grouplist[idx-1].type=info.type;
this.$forceUpdate();
}
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
name=this.grouplist[idx].name?this.grouplist[idx].name:"匿名";
img=this.grouplist[idx].img?this.grouplist[idx].img:require("@/static/image/girl.png");
this.grouplist[idx].content=info.content;
this.grouplist[idx].datetime=info.datetime;
this.grouplist[idx].fromuser=info.fromuser;
this.grouplist[idx].type=info.type;
this.$forceUpdate();
}
//
this.reorder();
myCache("chatlist-"+this.userid,this.grouplist);
//
this.setmsgnum();
var msgchat=myCache(info.id);
console.log(info.id,msgchat);
if(!msgchat){
//
let firstmsg = [{
"fromname": info.name, //
"fromuser": info.fromuser, //
"headimg": info.img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?5:0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.id,
"minId": info.minId,
"recvId": info.recvId,
"sendId": info.sendId,
"send": info.type==6?await this.getProduct(info.content):(info.type==5?await this.getOrder(info.content):null)
}];
myCache(info.id,firstmsg);
}
else{
//
var msgchat=myCache(info.id);
if(!msgchat){
//
let firstmsg = [{
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?(info.time?info.time:5):0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.minId,
"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{
if(this.ifchatadd(info.id,info.minId)){
//
let firstmsg = {
"fromname": info.name, //
"fromname": name, //
"fromuser": info.fromuser, //
"headimg": info.img, //
"headimg": img, //
"toname": this.userName, //
"touser": this.userid, //
"content": info.content,
"time": info.type==3?5:0,
"time": info.type==3?(info.time?info.time:5):0,
"ifaudio":info.type==3? true:false,
"fromtime": info.datetime,
"type": info.type==0?'txt':(info.type==1?'image':info.type==3?'audio':(info.type==4?'video':'product')),
"id": info.id,
"id": info.minId,
"minId": info.minId,
"recvId": info.recvId,
"sendId": info.sendId,
@ -915,6 +879,18 @@
myCache(info.id,msgchat);
}
}
},
//
ifchatadd(id,msgid){
var ret=true;
var msgchat=myCache(id);
msgchat.forEach((cell)=>{
if(cell.id==msgid){
ret=false;
}
});
return ret;
},
async getProduct(id){
console.log("getProduct",id)
@ -1020,7 +996,7 @@
background: #fff;
margin: 0;
width: 100%;
min-width: 600rpx;
min-width: 750rpx;
.lcon{
border-bottom: 1rpx solid #eee;
padding-top: 20rpx;
@ -1030,6 +1006,7 @@
flex-direction: row;
align-items: center;
width: 100%;
min-width: 750rpx;
.limg{
width: 100rpx;
height: 100rpx;

File diff suppressed because it is too large Load Diff

@ -748,6 +748,7 @@
reason: data.reason,
customerService: data.customerService,
instructor: data.instructor,
ownerId: data.ownerId,
productId: data.productId,
productName: data.productName,
sendinfo:{

@ -177,7 +177,7 @@
</template>
<script>
import { myCache,getcartNum,getRemoteFile } from '../../utils/utils.js';
import { myCache,getcartNum,getmessageNum,getRemoteFile } from '../../utils/utils.js';
import openlogin from "../components/openlogin.vue";
import top from "../components/top.vue";
@ -342,6 +342,22 @@
})
}
var messageNum=getmessageNum();
console.log("messageNum",messageNum)
if(messageNum>0){
//
uni.setTabBarBadge({
//
index: 3,
text: messageNum+''
});
}
else{
uni.removeTabBarBadge({
index: 3
})
}
if(this.userid){
//
this.getnum();

@ -124,6 +124,21 @@ function getcartLoseNum() {
}
return num
};
function getmessageNum() {
var user=myCache("user");
var userid = user.userid? user.userid:'';
var num=0;
if(userid){
var grouplist=myCache("chatlist-"+userid)?myCache("chatlist-"+userid):[];
for(let i=0;i<grouplist.length;i++){
num=num+1*(grouplist[i].sl?grouplist[i].sl:0);
}
return num
}
else{
return num
}
};
export {
myCache,
getRemoteFile,
@ -132,6 +147,7 @@ export {
getMondate,
ifnonet,
getcartNum,
getcartLoseNum
getcartLoseNum,
getmessageNum
};

Loading…
Cancel
Save