聊天列表

This commit is contained in:
luyuan 2020-08-05 17:00:04 +08:00
parent 045f6e6e01
commit b0f224d79b
Signed by: theluyuan
GPG Key ID: A7972FD973317FF3
3 changed files with 71 additions and 23 deletions

View File

@ -18,11 +18,11 @@
<view id="information"> <view id="information">
<view class="information_dl" v-for="(item,index) in information_dl" :key="index" > <view class="information_dl" v-for="(item,index) in information_dl" :key="index" >
<view> <view>
<image :src="item.url"></image> <image :src="item.avatar"></image>
</view> </view>
<view class="title">{{item.title}}</view> <view class="title">{{item.name}}</view>
<view class="contentes">{{item.contentes}}</view> <view class="contentes">{{item.text}}</view>
<view class="times">{{item.title}}</view> <view class="times">{{item.time}}</view>
</view> </view>
</view> </view>
</view> </view>
@ -88,6 +88,10 @@
show: false show: false
}; };
}, },
onShow(){
this.information_dl = this.imService.friends;
this.imService.onFriendListChange=this.onFriendListChange;
},
onLoad() { onLoad() {
// / // /
this.messageIndex() this.messageIndex()
@ -99,13 +103,22 @@
let that = this let that = this
setTimeout(function(){ setTimeout(function(){
that.imService.disconnect() that.imService.disconnect()
console.log("guanbi")
},1000) },1000)
setTimeout(function(){ setTimeout(function(){
console.log("lianjie")
that.imService.connectIM() that.imService.connectIM()
},2000) },2000)
} }
}, },
methods: { methods: {
onFriendListChange(onlineFriends) {
//todo:UniappMAPH5H5
//
this.information_dl = this.imService.friends;
this.$forceUpdate();
},
// checkbox // checkbox
checkboxChange(e) { checkboxChange(e) {
//console.log(e); //console.log(e);

4
static/goeasy-1.0.17.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -14,6 +14,8 @@ function Friend(uuid, name, avatar) {
this.avatar = avatar; this.avatar = avatar;
this.online = false; this.online = false;
this.unReadMessage = 0; this.unReadMessage = 0;
this.text = "";
this.time = "";
} }
function Group(uuid, name, avatar) { function Group(uuid, name, avatar) {
@ -144,24 +146,35 @@ IMService.prototype.resetFriendUnReadMessage = function (friend) {
//连接GoEasy //连接GoEasy
IMService.prototype.connectIM = function () { IMService.prototype.connectIM = function () {
//初始化IM相关的监听器 //初始化IM相关的监听器
try {
this.initialIMListeners(); this.initialIMListeners();
this.im.connect({
id: this.currentUser.uuid, } catch (error) {
data: { console.log(123)
avatar: this.currentUser.avatar, }
name: this.currentUser.name try {
} this.im.connect({
}).then(() => { id: this.currentUser.uuid,
console.log('连接成功') data: {
//订阅与自己相关的群信息 avatar: this.currentUser.avatar,
this.subscribeGroupMessage(); name: this.currentUser.name
//初始化好友们的在线状态 }
this.initialFriendOnlineStatus(); }).then(() => {
//订阅我的好友们的上下线信息 console.log('连接成功')
this.subscribeFriendsPresence(); //订阅与自己相关的群信息
}).catch(error => { this.subscribeGroupMessage();
console.log('连接失败,请确保网络正常appkey和host正确code:' + error.code + " content:" + error.content); //初始化好友们的在线状态
}); this.initialFriendOnlineStatus();
//订阅我的好友们的上下线信息
this.subscribeFriendsPresence();
}).catch(error => {
console.log('连接失败,请确保网络正常appkey和host正确code:' + error.code + " content:" + error.content);
this.connectIM()
});
} catch (error) {
console.log(12323)
}
}; };
//IM监听 //IM监听
@ -192,9 +205,12 @@ IMService.prototype.initialIMListeners = function () {
//如果不是自己发的,朋友未读消息数 +1 //如果不是自己发的,朋友未读消息数 +1
if (message.senderId != this.currentUser.uuid) { if (message.senderId != this.currentUser.uuid) {
let friend = this.friends[message.senderId]; let friend = this.friends[message.senderId];
if(friend && friend == undefined){ console.log(friend)
// return ;
let that = this
if(!friend && friend == undefined){
const token = uni.getStorageSync('token'); const token = uni.getStorageSync('token');
console.log(token,that.id) console.log(token)
uni.request({ uni.request({
url:"https://dmmall.sdbairui.com/api/Specialci/getAtwillUserInfo", url:"https://dmmall.sdbairui.com/api/Specialci/getAtwillUserInfo",
data:{ data:{
@ -206,13 +222,28 @@ IMService.prototype.initialIMListeners = function () {
}, },
success(res){ success(res){
console.log(res) console.log(res)
that.friends[message.senderId] = new Friend(res.data.data.member_id, res.data.data.member_nickname, res.data.data.member_avatar);
friend = that.friends[message.senderId];
console.log(friend)
friend.unReadMessage++;
friend.text = message.type != "text" ? "其他消息" : message.payload.text
let time = new Date(message.timestamp)
friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()
that.onFriendListChange(that.friends);
console.log(that.friends)
} }
}) })
}else{ }else{
console.log(friend)
friend.unReadMessage++; friend.unReadMessage++;
friend.text = message.type != "text" ? "其他消息" : message.payload.text
let time = new Date(message.timestamp)
friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()
this.onFriendListChange(this.friends); this.onFriendListChange(this.friends);
console.log(this.friends)
} }
} }
//更新私聊消息记录 //更新私聊消息记录
let friendId; let friendId;