好友申请通知优化

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: { methods: {
resolve() { resolve() {
resolveFriend(this.message.sourceUserId).then(res => { resolveFriend(this.message.sourceUserId).then(res => {
this.clearMessages()
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '通过好友申请' title: '通过好友申请'
@@ -47,6 +46,8 @@
icon: 'none', icon: 'none',
title: err.message title: err.message
}) })
}).finally(() => {
this.clearMessages()
}) })
}, },
reject() { reject() {
@@ -67,12 +68,12 @@
}) })
}, },
// 不管是通过还是拒绝,都要把相关的信息清理 // 不管是通过还是拒绝,都要把相关的信息清理
clearMessages() { clearMessages() {
RongIMLib.deleteMessages(RongIMLib.ConversationType.SYSTEM, this.message.sourceUserId) RongIMLib.deleteMessages(RongIMLib.ConversationType.SYSTEM, this.message.sourceUserId)
this.$emit('success') this.$emit('success')
uni.$emit('onNewContactConversation', message) uni.$emit('onNewContactConversation')
uni.$emit('onNewContactFriends', message) uni.$emit('onNewContactFriends')
uni.$emit('onNewContactPendings', message) uni.$emit('onNewContactPendings')
} }
} }
} }

View File

@@ -10,25 +10,33 @@
<u-avatar class="cover" size="40" shape="square" :src="require('@/static/im/im_00.png')" /> <u-avatar class="cover" size="40" shape="square" :src="require('@/static/im/im_00.png')" />
<view class="info">我的群聊</view> <view class="info">我的群聊</view>
</view> </view>
<block v-if="friends.length > 0"> <block v-if="friends.length > 0">
<u-index-item v-for="(item, fkey) in friends" :key="fkey"> <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" /> <u-index-anchor :text="indexs[fkey]" bgColor="#f9f9f9" height="20" size="12" color="#666"
<view v-for="(friendItem, index) in item" :key="index" class="friend-flex" @click="toFriend(friendItem.targetId)"> class="anchor" />
<u-avatar class="avatar-img" size="40" shape="square" :src="contact(friendItem.targetId).portraitUrl" /> <view v-for="(friendItem, index) in item" :key="index" class="friend-flex"
<view class="info"> <view class="name">{{ contact(friendItem.targetId).name }}</view> </view> @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> </view>
</u-index-item> </u-index-item>
</block> </block>
<view class="no-lists" v-else> <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"
<span>暂无好友列表~</span> :src=" require('@/static/imgs/no-friend.png')" :lazy-load="true" />
<span>暂无好友列表~</span>
</view> </view>
</u-index-list> </u-index-list>
</view> </view>
</template> </template>
<script> <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 * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import im from '@/utils/im/index.js' import im from '@/utils/im/index.js'
@@ -47,20 +55,21 @@
} }
} }
}, },
onLoad() {
uni.$on('onNewContactFriends', this.checkNewFriendPending)
},
onShow() { onShow() {
this.getFriendList() this.getFriendList()
this.checkNewFriendPending() this.checkNewFriendPending()
uni.$on('onContactNotification', this.checkNewFriendPending) },
}, onUnload() {
onUnload() { uni.$off("onNewContactFriends")
uni.$off("onContactNotification")
}, },
methods: { methods: {
getFriendList() { getFriendList() {
getFriendsLetter().then(res => { getFriendsLetter().then(res => {
console.log(res)
this.indexs = res.indexList this.indexs = res.indexList
this.friends = res.itemArr this.friends = res.itemArr
}) })
}, },
checkNewFriendPending() { checkNewFriendPending() {
@@ -70,10 +79,7 @@
}, },
toGroup() { toGroup() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/im/group/index', url: '/pages/im/group/index'
fail(err) {
console.log(err);
}
}) })
}, },
toFriend(targetId) { toFriend(targetId) {
@@ -85,13 +91,13 @@
toPending() { toPending() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/im/friends/pending' url: '/pages/im/friends/pending'
}); })
} }
}, },
onNavigationBarButtonTap(e) { onNavigationBarButtonTap(e) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/im/friends/search' url: '/pages/im/friends/search'
}); })
} }
}; };
</script> </script>
@@ -159,19 +165,20 @@
font-size: 14px; font-size: 14px;
line-height: 24px; line-height: 24px;
background-color: #fff; background-color: #fff;
} }
.no-lists {
padding-top: $padding * 3; .no-lists {
display: flex; padding-top: $padding * 3;
flex-direction: column; display: flex;
align-items: center; flex-direction: column;
justify-content: center; align-items: center;
box-sizing: border-box; justify-content: center;
font-size: $title-size-m; box-sizing: border-box;
color: $text-gray-m; font-size: $title-size-m;
color: $text-gray-m;
span {
padding-top: $padding; span {
} padding-top: $padding;
}
} }
</style> </style>

View File

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