...
|
...
|
@@ -229,17 +229,19 @@ |
|
|
watch:{
|
|
|
currentMessageList(newVal,oldVal){
|
|
|
this.msgList = newVal
|
|
|
this.screenMsg(newVal,oldVal)
|
|
|
if(this.isSDKReady){
|
|
|
this.screenMsg(newVal,oldVal)
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
onLoad(option) {
|
|
|
onLoad() {
|
|
|
this.showRoom = false
|
|
|
if(!this.isSDKReady){
|
|
|
uni.switchTab({
|
|
|
url:'/pages/index/index'
|
|
|
})
|
|
|
return
|
|
|
this.loginTim()
|
|
|
}else{
|
|
|
this.getTimInfo()
|
|
|
}
|
|
|
this.showRoom = false
|
|
|
|
|
|
//监听键盘高度变化
|
|
|
uni.onKeyboardHeightChange(res => {
|
|
|
console.log('键盘高度变化了',res.height)
|
...
|
...
|
@@ -249,21 +251,6 @@ |
|
|
this.keyboardHeight = 20
|
|
|
}
|
|
|
})
|
|
|
this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
|
|
|
this.toUserId = this.$store.state.toUserId
|
|
|
this.conversationActive = this.$store.state.conversationActive
|
|
|
this.TIM = this.$TIM
|
|
|
|
|
|
//获取聊天对象的用户信息
|
|
|
this.$request('/user/userInfo',{user_id:this.toUserId}).then((res)=>{
|
|
|
console.log('获取聊天对象的用户信息',res)
|
|
|
this.toUserInfo = res.data
|
|
|
uni.setNavigationBarTitle({
|
|
|
title:this.toUserInfo.nickname
|
|
|
})
|
|
|
this.getMsgList();
|
|
|
})
|
|
|
|
|
|
},
|
|
|
onShow(){
|
|
|
this.scrollTop = 9999999;
|
...
|
...
|
@@ -282,6 +269,57 @@ |
|
|
}
|
|
|
},
|
|
|
methods:{
|
|
|
getTimInfo(){
|
|
|
if(uni.getStorageSync('toUserItem') && uni.getStorageSync('toRoomType') == 'toUserItem'){
|
|
|
this.$store.commit('updateConversationActive', JSON.parse(uni.getStorageSync('toUserItem')))
|
|
|
}
|
|
|
if(uni.getStorageSync('toUserId') && uni.getStorageSync('toRoomType') == 'toUserId'){
|
|
|
this.$store.commit('createConversationActive',uni.getStorageSync('toUserId'))
|
|
|
}
|
|
|
this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
|
|
|
this.toUserId = this.$store.state.toUserId
|
|
|
this.conversationActive = this.$store.state.conversationActive
|
|
|
this.TIM = this.$TIM
|
|
|
|
|
|
//获取聊天对象的用户信息
|
|
|
this.$request('/user/userInfo',{user_id:this.toUserId}).then((res)=>{
|
|
|
console.log('获取聊天对象的用户信息',res)
|
|
|
this.toUserInfo = res.data
|
|
|
uni.setNavigationBarTitle({
|
|
|
title:this.toUserInfo.nickname
|
|
|
})
|
|
|
this.getMsgList();
|
|
|
})
|
|
|
},
|
|
|
loginTim(){
|
|
|
let userID = this.userinfo.id.toString()
|
|
|
let userSig = this.userinfo.user_sign
|
|
|
let userInfo = {
|
|
|
user: this.userinfo.nickname,
|
|
|
userId:this.userinfo.id,
|
|
|
img:this.userinfo.avatar,
|
|
|
userSig:this.userinfo.user_sign
|
|
|
}
|
|
|
//登录腾讯IM及时通讯
|
|
|
let promise = this.tim.login({
|
|
|
userID: userID,
|
|
|
userSig: userSig
|
|
|
});
|
|
|
promise.then((res) => {
|
|
|
console.warn('腾讯云即时通讯登录成功', res);
|
|
|
//登录成功后 更新登录状态
|
|
|
this.$store.commit("toggleIsLogin", true);
|
|
|
//自己平台的用户基础信息
|
|
|
uni.setStorageSync('userInfo', JSON.stringify(userInfo))
|
|
|
//tim 返回的用户信息
|
|
|
uni.setStorageSync('userTIMInfo', JSON.stringify(res.data))
|
|
|
setTimeout(()=>{
|
|
|
this.getTimInfo()
|
|
|
},1000)
|
|
|
}).catch((err) => {
|
|
|
console.warn('腾讯云即时通讯登录报错', err);
|
|
|
});
|
|
|
},
|
|
|
//聊天的节点加上外层的div
|
|
|
nodesFliter(str){
|
|
|
let nodeStr = '<div style="align-items: center;word-wrap:break-word;">'+str+'</div>'
|
...
|
...
|
|