好友列表调整

This commit is contained in:
2022-02-09 13:16:12 +08:00
parent 1678fd6e80
commit 699c178bd7
4 changed files with 65 additions and 38 deletions

View File

@@ -1,37 +1,32 @@
<template> <template>
<view> <view>
<view class="friend-flex u-border-bottom" @click="toPending">
<u-avatar class="cover" size="40" shape="square" :src="require('@/static/im/im_01.png')"></u-avatar>
<u-badge max="99" absolute :offset="[23, 20]" :value="pendingCount" />
<view class="name">新的朋友</view>
</view>
<view class="friend-flex" @click="showToast">
<u-avatar class="cover" size="40" shape="square" :src="require('@/static/im/im_00.png')"></u-avatar>
<view class="name">我的群聊</view>
</view>
<u-index-list :index-list="indexs" inactiveColor="#666" activeColor="#34CE98"> <u-index-list :index-list="indexs" inactiveColor="#666" activeColor="#34CE98">
<view class="friend-flex u-border-bottom" @click="toPending">
<u-avatar class="cover" size="40" shape="square" :src="require('@/static/im/im_01.png')"></u-avatar>
<u-badge max="99" absolute :offset="[23, 20]" :value="pendingCount" />
<view class="info">新的朋友</view>
</view>
<view class="friend-flex" @click="showToast">
<u-avatar class="cover" size="40" shape="square" :src="require('@/static/im/im_00.png')"></u-avatar>
<view class="info">我的群聊</view>
</view>
<block v-if="friends.length > 0"> <block v-if="friends.length > 0">
<template v-for="(item, fkey) in friends"> <u-index-item v-for="(item, fkey) in friends" :key="fkey">
<!-- #ifdef APP-NVUE -->
<u-index-anchor :text="indexs[fkey]" bgColor="#F3F6FB" height="20" size="12" color="#666"> <u-index-anchor :text="indexs[fkey]" bgColor="#F3F6FB" height="20" size="12" color="#666">
</u-index-anchor> </u-index-anchor>
<!-- #endif -->
<u-index-item> <view v-for="(friendItem, index) in item" :key="index" class="friend-flex u-border-bottom"
<!-- #ifndef APP-NVUE --> @click="toFriend(friendItem.userId)">
<u-index-anchor :text="indexs[fkey]" bgColor="#F3F6FB" height="20" size="12" color="#666"> <u-avatar size="40" shape="square" :src="friend(friendItem.userId).portraitUrl" />
</u-index-anchor> <view class="info">
<!-- #endif -->
<view v-for="(friendItem, index) in item" :key="index" class="friend-flex u-border-bottom"
@click="toFriend(friendItem.userId)">
<u-avatar size="40" shape="square" :src="friend(friendItem.userId).portraitUrl" />
<view class="name">{{ friend(friendItem.userId).name }}</view> <view class="name">{{ friend(friendItem.userId).name }}</view>
<view class="address">{{ friendItem.address }}</view>
</view> </view>
</u-index-item> </view>
</template> </u-index-item>
</block> </block>
<block v-else> <block v-else>
<u-empty class="pages-null" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无好友"> <u-empty class="pages-null" mode="data" text="暂无好友">
</u-empty> </u-empty>
</block> </block>
</u-index-list> </u-index-list>
@@ -60,17 +55,23 @@
} }
}, },
onLoad() { onLoad() {
uni.$on('onContactNotification', this.checkNewFriendPending) this.getFriendList()
this.checkNewFriendPending() this.checkNewFriendPending()
getFriendsLetter().then(res => { uni.$on('onContactNotification', () => {
this.indexs = res.indexList this.checkNewFriendPending()
this.friends = res.itemArr this.getFriendList()
}) })
}, },
onUnload() { onUnload() {
uni.$off('onContactNotification') uni.$off('onContactNotification')
}, },
methods: { methods: {
getFriendList() {
getFriendsLetter().then(res => {
this.indexs = res.indexList
this.friends = res.itemArr
})
},
checkNewFriendPending() { checkNewFriendPending() {
// 获取是否有新的好友申请 // 获取是否有新的好友申请
RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], 1000, 0, (res) => { RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], 1000, 0, (res) => {
@@ -121,13 +122,22 @@
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
.name { .info {
flex: 1; flex: 1;
padding-left: $padding; margin-left: $padding;
font-size: $title-size + 2;
font-size: $title-size + 2; .name {
color: #454545 !important; font-size: $title-size + 2;
@extend .nowrap; font-size: $title-size + 2;
color: #454545 !important;
@extend .nowrap;
}
.address {
color: $text-gray-m;
font-size: $title-size-m - 5;
}
} }
} }
</style> </style>

View File

@@ -159,6 +159,7 @@
success: e => { success: e => {
if (e.confirm) { if (e.confirm) {
deleteFriend(this.targetId).then(res => { deleteFriend(this.targetId).then(res => {
uni.$emit('onContactNotification')
// 删除聊天记录 // 删除聊天记录
RongIMLib.deleteMessages(1, this.targetId); RongIMLib.deleteMessages(1, this.targetId);
RongIMLib.removeConversation(1, this.targetId); RongIMLib.removeConversation(1, this.targetId);

16
utils/im/data.js Normal file
View File

@@ -0,0 +1,16 @@
// 获取新好友申请数量
const getPendingCount = (callback) => {
RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], 100, 0, (res) => {
if (res.code === 0) {
const pendingCount = res.conversations.filter((item) => {
return item.objectName == RongIMLib.ObjectName.ContactNotification
}).length
callback(pendingCount)
}
})
}
export default {
getPendingCount
}

View File

@@ -2,7 +2,7 @@ import store from '@/store/index.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index' import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
const getMessageList = (conversationType, targetId, timeStamp, count, isForward, callback) => { const getMessageList = (conversationType, targetId, timeStamp, count, isForward, callback) => {
// 获取消息列表 // 获取消息列表 https://doc.rongcloud.cn/imserver/server/v1/message/objectname#objectName
const objectNames = [ const objectNames = [
'RC:TxtMsg', 'RC:TxtMsg',
'RC:VcMsg', 'RC:VcMsg',