@@ -48,6 +48,7 @@ Component({ | |||
*/ | |||
methods: { | |||
tabChange(e) { | |||
wx.closeSocket(); | |||
if (e.detail.item.text == "发布需求" || e.detail.item.text == "消息") { | |||
if (!app.globalData.customerId) { | |||
app.goLogin(); |
@@ -21,6 +21,10 @@ Page({ | |||
* 生命周期函数--监听页面加载 | |||
*/ | |||
onLoad() { | |||
}, | |||
onShow() { | |||
const businessCommunicationCustomer = wx.getStorageSync('businessCommunicationCustomer') || null; | |||
if (businessCommunicationCustomer) { | |||
this.setData({ | |||
@@ -29,8 +33,6 @@ Page({ | |||
} | |||
// 初始化websocket | |||
this.initWebSocket(); | |||
}, | |||
onShow() { | |||
// 初始化数据 | |||
this.initData(); | |||
}, | |||
@@ -59,7 +61,22 @@ Page({ | |||
wx.onSocketMessage(function (res) { | |||
// 接收到的消息{date,message,type} type类型为 1 是对方的消息 为 0 是自己的消息 | |||
console.log(res,'消息页----收到新消息') | |||
_this.initData(); | |||
// _this.initData(); | |||
let _data = JSON.parse(res.data); | |||
_data.chatRecord = JSON.parse(_data.chatRecord); | |||
let msgData = _this.data.msgData; | |||
msgData.forEach(el=>{ | |||
// 如果当前消息的 customerId = 发送人的ID | |||
if(el.businessCommunicationCustomerVO.customerId == _data.chatRecord.sender){ | |||
el.lastContent = _data.chatRecord.content; | |||
el.lastContentDate = $util.formatTime(new Date(_data.chatRecord.sendTime)); | |||
el.lastContentDate = el.lastContentDate.replaceAll('/', '-'); | |||
} | |||
el.size + 1; | |||
}) | |||
_this.setData({ | |||
msgData | |||
}) | |||
}) | |||
// 监听连接关闭 | |||
@@ -151,4 +168,7 @@ Page({ | |||
this.getListData(); | |||
} | |||
}, | |||
onHide(){ | |||
wx.closeSocket(); | |||
}, | |||
}) |
@@ -18,6 +18,7 @@ | |||
<view class="msg-li-item" wx:for="{{msgData}}" wx:key="index" bindtap="goToChat" data-item="{{ item }}"> | |||
<view class="chatheads-view fl"> | |||
<image class='other-head-img' src='{{item.businessCommunicationCustomerVO.chatHeads }}'></image> | |||
<view class="view-info" wx:if="{{ item.size > 0 }}">{{ item.size > 99 ? '99+' : item.size }}</view> | |||
</view> | |||
<view class="msg-content fl"> | |||
<view class="msg-nickName fl yichu">{{ item.businessCommunicationCustomerVO.nickName }}</view> |
@@ -77,6 +77,7 @@ | |||
margin: 0 20rpx; | |||
border-radius: 50%; | |||
margin-top: 7rpx; | |||
position: relative; | |||
} | |||
.msg-li-item .chatheads-view .other-head-img{ | |||
width: 100%; | |||
@@ -102,4 +103,19 @@ | |||
} | |||
.msg-li-item .msg-content .msg-last-content { | |||
max-width: calc(100% - 270rpx); | |||
} | |||
.msg-li-item .chatheads-view .view-info { | |||
position: absolute; | |||
right: -8rpx; | |||
top: -8rpx; | |||
background: red; | |||
color: #fff; | |||
font-size: 12px; | |||
border-radius: 50%; | |||
box-sizing: border-box; | |||
min-width: 30rpx; | |||
height: 30rpx; | |||
line-height: 30rpx; | |||
text-align: center; | |||
} |
@@ -264,7 +264,7 @@ Page({ | |||
* 生命周期函数--监听页面隐藏 | |||
*/ | |||
onHide: function () { | |||
wx.closeSocket(); | |||
}, | |||
/** |