Merge pull request 'xbx' (#210) from xbx into master

Reviewed-on: http://git.luyuan.tk/luyuan/deming/pulls/210
This commit is contained in:
luyuan 2020-08-15 15:48:11 +08:00
commit 718e3ff45d
4 changed files with 48 additions and 37 deletions

View File

@ -437,6 +437,10 @@ export default {
friend_tomid:id friend_tomid:id
}); });
}, },
//获取默认头像
getDefaultAvatar(){
return vm.$u.post("member/getDefaultAvatar")
}
} }
} }

View File

@ -222,6 +222,7 @@
import zhiboItem from "@/components/index/zhibo-item/index" import zhiboItem from "@/components/index/zhibo-item/index"
import indexad from "@/components/index/ad/index" import indexad from "@/components/index/ad/index"
import darenItem from "@/components/index/daren-item/index" import darenItem from "@/components/index/daren-item/index"
import chatVue from '../../pageD/chat/chat.vue'
export default { export default {
name: "index", name: "index",
@ -281,7 +282,16 @@
// console.log(user) // console.log(user)
this.imService.login(user.member.member_id,user.member.member_nickname,user.member.member_avatar) this.imService.login(user.member.member_id,user.member.member_nickname,user.member.member_avatar)
this.imService.connectIM() this.imService.connectIM()
let that = this
}else{
this.$u.api.getDefaultAvatar().then((res)=>{
console.log(res)
uni.setStorageSync("morenimg",res.data.avatar)
this.imService.login(new Date().getTime(),"123",res.data.avatar)
this.imService.connectIM()
})
}
let that = this
setTimeout(function(){ setTimeout(function(){
that.imService.disconnect() that.imService.disconnect()
// console.log("guanbi") // console.log("guanbi")
@ -289,8 +299,7 @@
setTimeout(function(){ setTimeout(function(){
// console.log("lianjie") // console.log("lianjie")
that.imService.connectIM() that.imService.connectIM()
},2000) },2000)
}
}, },
onPullDownRefresh() { onPullDownRefresh() {
this.page = 1; this.page = 1;

View File

@ -418,40 +418,37 @@ export default {
} }
}) })
//当前用户 //当前用户
try { var currentUser = {}
uni.request({ if(this.$store.state.hasLogin){
url:"https://dmmall.sdbairui.com/api/Member/MemberInfo", const user = uni.getStorageSync('user_info');
method:"POST", currentUser = {
header:{ id : user.member.member_id,
'Authorization' : 'Bearer' + " " + token nickname : user.member.member_nickname,
}, avatar: user.member.member_avatar
success(res){ };
console.log(res,111) }else{
var currentUser = { const user = uni.getStorageSync('morenimg');
id : res.data.data.MemberArray.member_mobile + "", currentUser = {
nickname : res.data.data.MemberArray.member_nickname, id : new Date().getTime(),
avatar: res.data.data.MemberArray.member_avatar nickname : "123",
}; avatar: user
};
var room = {
id : a.rid + "",
name : a.rid + ""
};
that.chatRoomService = getApp().globalData.im
console.log(room,currentUser)
//构造chatRoomService
that.chatRoomService.subscribeRoomMessage(room,currentUser)
//获取当前聊天室数据
that.room = that.chatRoomService.room;
that.chatRoomService.initialWhenOnlineUserChange(that.newpeople)
that.chatRoomService.initialWhenNewMessage(that.whenNewMessage);
console.log(that.room)
}
})
} catch (error) {
console.log("错误")
} }
var room = {
id : a.rid + "",
name : a.rid + ""
};
that.chatRoomService = getApp().globalData.im
console.log(room,currentUser)
//构造chatRoomService
that.chatRoomService.subscribeRoomMessage(room,currentUser)
//获取当前聊天室数据
that.room = that.chatRoomService.room;
that.chatRoomService.initialWhenOnlineUserChange(that.newpeople)
that.chatRoomService.initialWhenNewMessage(that.whenNewMessage);
this.$forceUpdate();
console.log(that.room)
}, },
onBackPress () {//返回取消订阅 onBackPress () {//返回取消订阅
@ -467,6 +464,7 @@ export default {
}, },
newpeople(list){ newpeople(list){
this.room.onlineUsers = list this.room.onlineUsers = list
console.log(list.users.length)
this.$forceUpdate(); this.$forceUpdate();
}, },
sendMessage (messageType, content) {//发送消息 sendMessage (messageType, content) {//发送消息

View File

@ -800,7 +800,6 @@ IMService.prototype.listenerGroupPresence = function () {
this.im.on(GoEasyIM.EVENT.GROUP_PRESENCE, (event) => { this.im.on(GoEasyIM.EVENT.GROUP_PRESENCE, (event) => {
//更新在线用户数 //更新在线用户数
this.room.onlineUsers.count = event.groupOnlineCount; this.room.onlineUsers.count = event.groupOnlineCount;
if (event.action == 'join' || event.action == 'online') { if (event.action == 'join' || event.action == 'online') {
let userData = JSON.parse(event.userData); let userData = JSON.parse(event.userData);
//添加新用户 //添加新用户
@ -887,6 +886,7 @@ IMService.prototype.subscribeRoomMessage = function (room, user) {
this.subscribePresence(this.room.id); this.subscribePresence(this.room.id);
//订阅聊天室消息 //订阅聊天室消息
// this.subscribeRoomMessage(this.room.id); // this.subscribeRoomMessage(this.room.id);
this.initialOnlineUsers(this.room.id)
this.im.subscribeGroup([this.room.id]) this.im.subscribeGroup([this.room.id])
.then(result => { .then(result => {
console.log('消息订阅成功') console.log('消息订阅成功')