在页面的两个生命周期组件里面
onShow() {
console.log('-----上线线')
let info = wx.getStorageSync('chat_item')
DB.collection('friends')
.where({
_id: info._id
}).get().then(res => {
console.log('-----', res)
if (res.data[0].a == wx.getStorageSync('userInfo')._openid) {
console.log('-----a上线',res.data[0].a,wx.getStorageSync('userInfo')._openid)
DB.collection('friends').doc(info._id).update({
data: {
a_zaixian: true
}
})
} else {
console.log('-----b上线',res.data[0].b,wx.getStorageSync('userInfo')._openid)
DB.collection('friends').doc(info._id).update({
data: {
b_zaixian: true
}
})
}
})
},
onUnload() {
console.log('-----离线')
let info = wx.getStorageSync('chat_item')
DB.collection('friends')
.where({
_id: info._id
}).get().then(res => {
if (res.data[0].a == wx.getStorageSync('userInfo')._openid) {
console.log('-----a离线')
DB.collection('friends').doc(info._id).update({
data: {
a_zaixian: false
}
})
} else {
console.log('-----b离线')
DB.collection('friends').doc(info._id).update({
data: {
b_zaixian: false
}
})
}
})
},