好友申请通知优化

This commit is contained in:
2022-02-23 17:01:26 +08:00
parent 8a8e55600f
commit 103679c372
3 changed files with 54 additions and 42 deletions

View File

@@ -36,7 +36,6 @@
methods: {
resolve() {
resolveFriend(this.message.sourceUserId).then(res => {
this.clearMessages()
uni.showToast({
icon: 'none',
title: '通过好友申请'
@@ -47,6 +46,8 @@
icon: 'none',
title: err.message
})
}).finally(() => {
this.clearMessages()
})
},
reject() {
@@ -70,9 +71,9 @@
clearMessages() {
RongIMLib.deleteMessages(RongIMLib.ConversationType.SYSTEM, this.message.sourceUserId)
this.$emit('success')
uni.$emit('onNewContactConversation', message)
uni.$emit('onNewContactFriends', message)
uni.$emit('onNewContactPendings', message)
uni.$emit('onNewContactConversation')
uni.$emit('onNewContactFriends')
uni.$emit('onNewContactPendings')
}
}
}

View File

@@ -12,15 +12,21 @@
</view>
<block v-if="friends.length > 0">
<u-index-item v-for="(item, fkey) in friends" :key="fkey">
<u-index-anchor :text="indexs[fkey]" bgColor="#f9f9f9" height="20" size="12" color="#666" class="anchor" />
<view v-for="(friendItem, index) in item" :key="index" class="friend-flex" @click="toFriend(friendItem.targetId)">
<u-avatar class="avatar-img" size="40" shape="square" :src="contact(friendItem.targetId).portraitUrl" />
<view class="info"> <view class="name">{{ contact(friendItem.targetId).name }}</view> </view>
<u-index-anchor :text="indexs[fkey]" bgColor="#f9f9f9" height="20" size="12" color="#666"
class="anchor" />
<view v-for="(friendItem, index) in item" :key="index" class="friend-flex"
@click="toFriend(friendItem.targetId)">
<u-avatar class="avatar-img" size="40" shape="square"
:src="contact(friendItem.targetId).portraitUrl" />
<view class="info">
<view class="name">{{ contact(friendItem.targetId).name }}</view>
</view>
</view>
</u-index-item>
</block>
<view class="no-lists" v-else>
<u-image class="cover" radius="4" width="400rpx" height="400rpx" :src=" require('@/static/imgs/no-friend.png')" :lazy-load="true" />
<u-image class="cover" radius="4" width="400rpx" height="400rpx"
:src=" require('@/static/imgs/no-friend.png')" :lazy-load="true" />
<span>暂无好友列表~</span>
</view>
</u-index-list>
@@ -28,7 +34,9 @@
</template>
<script>
import {getFriendsLetter} from '@/apis/interfaces/im';
import {
getFriendsLetter
} from '@/apis/interfaces/im';
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import im from '@/utils/im/index.js'
@@ -47,18 +55,19 @@
}
}
},
onLoad() {
uni.$on('onNewContactFriends', this.checkNewFriendPending)
},
onShow() {
this.getFriendList()
this.checkNewFriendPending()
uni.$on('onContactNotification', this.checkNewFriendPending)
},
onUnload() {
uni.$off("onContactNotification")
uni.$off("onNewContactFriends")
},
methods: {
getFriendList() {
getFriendsLetter().then(res => {
console.log(res)
this.indexs = res.indexList
this.friends = res.itemArr
})
@@ -70,10 +79,7 @@
},
toGroup() {
uni.navigateTo({
url: '/pages/im/group/index',
fail(err) {
console.log(err);
}
url: '/pages/im/group/index'
})
},
toFriend(targetId) {
@@ -85,13 +91,13 @@
toPending() {
uni.navigateTo({
url: '/pages/im/friends/pending'
});
})
}
},
onNavigationBarButtonTap(e) {
uni.navigateTo({
url: '/pages/im/friends/search'
});
})
}
};
</script>
@@ -160,6 +166,7 @@
line-height: 24px;
background-color: #fff;
}
.no-lists {
padding-top: $padding * 3;
display: flex;

View File

@@ -57,7 +57,11 @@
// 好友申请数量
this.checkNewFriendPending()
// 监听新的好友申请
uni.$on('onNewContactConversation', this.checkNewFriendPending)
uni.$on('onNewContactConversation', () => {
console.log('更新好友申请数量');
// 更新好友申请数量
this.checkNewFriendPending()
})
},
onShow() {
if (this.$store.state.token !== '') {