onLoad: function (options) {
this.logIn()
}
/**
* IM登录
*/
logIn(){
let onMessageReceived = function(event) {
console.log(event,'收消息') //会多次触发
let msg = that.data.msg
msg.messageList = [...that.data.msg.messageList,...event.data]
that.setData({msg},()=>{
that.data.jumpView&&wx.nextTick(() => {
that.setData({ toView:`roll${msg.messageList.length}` }) // 在当前同步流程结束后,下一个时间片执行
})
})
}
let onSdkReady = function(event) {
console.log(event,'实例加载')
that.isCancel()
}
tim.on(TIM.EVENT.SDK_READY, onSdkReady);
tim.on(TIM.EVENT.MESSAGE_RECEIVED, onMessageReceived)
let promise = tim.login({userID: this.data.userAccount , userSig:getApp().globalData.userSig})
promise.then(function(imResponse) {
console.log(imResponse.data,'登录'); // 登录成功
if (imResponse.data.repeatLogin === true) {
that.getList(null,null)
}
}).catch(function(imError) {
console.warn('login error:', imError); // 登录失败的相关信息
});
},
onUnload: function () {
let promise = tim.logout()
promise.then(function(imResponse) {
console.log(imResponse,'退出成功');
}).catch(function(imError) {
console.warn('logout error:', imError);
})
},
相似问题