From 3eb7b804968bbc638cb17bf85bbcc681f1fce97d Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 16 Feb 2022 18:00:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A5=BD=E5=8F=8B=E6=8F=90=E9=86=92?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/im/friends/index.vue | 18 ++++++------------ pages/im/friends/pending.vue | 3 --- pages/im/index.vue | 18 ++++++++++++------ utils/im/index.js | 3 ++- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/pages/im/friends/index.vue b/pages/im/friends/index.vue index 10e3e9f..b56a22f 100644 --- a/pages/im/friends/index.vue +++ b/pages/im/friends/index.vue @@ -57,13 +57,7 @@ onLoad() { this.getFriendList() this.checkNewFriendPending() - uni.$on('onContactNotification', () => { - this.checkNewFriendPending() - this.getFriendList() - }) - }, - onUnload() { - uni.$off('onContactNotification') + uni.$on('onContactNotification', this.checkNewFriendPending) }, methods: { getFriendList() { @@ -83,11 +77,11 @@ }) }, toGroup() { - uni.navigateTo({ - url: '/pages/im/group/index', - fail(err) { - console.log(err); - } + uni.navigateTo({ + url: '/pages/im/group/index', + fail(err) { + console.log(err); + } }) }, toFriend(targetId) { diff --git a/pages/im/friends/pending.vue b/pages/im/friends/pending.vue index c25b597..efe53e6 100644 --- a/pages/im/friends/pending.vue +++ b/pages/im/friends/pending.vue @@ -29,9 +29,6 @@ this.getPendingList() uni.$on('onContactNotification', this.getPendingList) }, - onUnload() { - uni.$off('onContactNotification') - }, methods: { getPendingList() { im.getPendingList((pendings) => { diff --git a/pages/im/index.vue b/pages/im/index.vue index 56dbd3a..111ce88 100644 --- a/pages/im/index.vue +++ b/pages/im/index.vue @@ -53,16 +53,20 @@ }, onLoad() { // 好友申请数量 - this.checkNewFriendPending() - uni.$on('onConnectionStatusChange', (status) => { - this.connection = status + this.checkNewFriendPending() + // 监听新的好友申请 + uni.$on('onContactNotification', () => { + console.log('监听申请'); + this.checkNewFriendPending() }) - uni.$on('onContactNotification', this.checkNewFriendPending) }, onShow() { if (this.$store.state.token !== '') { this.getConversationList() } + uni.$on('onConnectionStatusChange', (status) => { + this.connection = status + }) // 监听新消息 uni.$on('onReceiveMessage', (msg) => { this.getConversationList() @@ -73,7 +77,9 @@ }, methods: { checkNewFriendPending() { - im.getPendingList((pendings) => { + console.log('触发新申请好友事件'); + im.getPendingList((pendings) => { + console.log(pendings); this.hasNewFriends = pendings.length }) }, @@ -91,7 +97,7 @@ const count = 1000 const timestamp = 0 RongIMLib.getConversationList([1, 3], count, timestamp, (res) => { - if (res.code === 0) { + if (res.code === 0) { this.conversations = res.conversations } }) diff --git a/utils/im/index.js b/utils/im/index.js index 53ca2e9..e508f78 100644 --- a/utils/im/index.js +++ b/utils/im/index.js @@ -159,7 +159,8 @@ const addListeners = () => { }) => { console.log('消息删除结果', code) }) - } else if (message.objectName === RongIMLib.ObjectName.ContactNotification) { + } else if (message.objectName === RongIMLib.ObjectName.ContactNotification) { + console.log('onContactNotification'); // 触发一个新好友的通知事件 uni.$emit('onContactNotification', message.content) }