根据事件广播,更新好友申请的数量提醒

This commit is contained in:
2022-02-09 12:01:36 +08:00
parent fbf9d7db31
commit 1678fd6e80
8 changed files with 200 additions and 92 deletions

View File

@@ -1,18 +1,16 @@
<template>
<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">
<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>
<view class="name">
新的朋友 ({{ pendingCount }})
</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>
</view>
<block v-if="friends.length > 0">
<template v-for="(item, fkey) in friends">
<!-- #ifdef APP-NVUE -->
@@ -24,8 +22,8 @@
<u-index-anchor :text="indexs[fkey]" bgColor="#F3F6FB" height="20" size="12" color="#666">
</u-index-anchor>
<!-- #endif -->
<view v-for="(friendItem, index) in item" :key="friendItem.userId"
class="friend-flex u-border-bottom" @click="toFriend(friendItem.userId)">
<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>
@@ -42,10 +40,10 @@
<script>
import {
getFriendsLetter,
getPendingCount
getFriendsLetter
} from '@/apis/interfaces/im';
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
export default {
data() {
return {
@@ -62,16 +60,27 @@
}
},
onLoad() {
uni.$on('onContactNotification', this.checkNewFriendPending)
this.checkNewFriendPending()
getFriendsLetter().then(res => {
this.indexs = res.indexList
this.friends = res.itemArr
})
getPendingCount().then(res => {
console.log(res);
this.pendingCount = res
})
},
onUnload() {
uni.$off('onContactNotification')
},
methods: {
checkNewFriendPending() {
// 获取是否有新的好友申请
RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], 1000, 0, (res) => {
if (res.code === 0) {
this.pendingCount = res.conversations.filter((item) => {
return item.objectName == RongIMLib.ObjectName.ContactNotification
}).length
}
})
},
showToast() {
uni.showToast({
title: '群聊功能暂未开放,敬请期待',

View File

@@ -1,11 +1,3 @@
<!--
* @Description:新朋友即新增好友申请列表 可以搜索跳转
* @Author: Aimee·Zhang
* @Date: 2022-01-24 10:49:15
* @LastEditors: Aimee·Zhang
* @LastEditTime: 2022-01-25 10:18:26
-->
<template>
<view class="pending">
<u-sticky>
@@ -14,67 +6,42 @@
:disabled="true" :show-action="false" />
</view>
</u-sticky>
<block v-if="pedings.length > 0">
<applyFriend :lists="pedings" :isAgree="true" :isReject="false" @action="action" />
</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" />
<span>暂无申请记录~</span>
<view v-for="(item, index) in pendings" :key="index">
<apply-cell :message="item.latestMessage" @success="getPendingList" />
</view>
</view>
</template>
<script>
import {
getPedings,
resolveFriend,
rejectFriend
} from '@/apis/interfaces/im.js'
import * as RongIMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index"
import applyFriend from '@/components/friend-apply-reject-agree'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import applyCell from '../components/friendApplyCell'
export default {
components: {
applyFriend
applyCell
},
data() {
return {
pedings: []
pendings: []
}
},
onLoad() {
this.getPeddingList()
this.getPendingList()
uni.$on('onContactNotification', this.getPendingList)
},
onUnload() {
uni.$off('onContactNotification')
},
methods: {
// 操作同意或拒绝
action(e) {
let url = e.type === 'agree' ? resolveFriend : rejectFriend
uni.showModal({
title: e.type === 'agree' ? '通过' : '拒绝',
content: e.type === 'agree' ? '通过后即可与该用户畅所欲言' : '拒绝后将不会收到该用户发来信息',
success: res => {
if (res.confirm) {
url(e.item.userId).then(res => {
this.getPeddingList()
})
}
getPendingList() {
// 获取系统中的好友关系会话列表
RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], 1000, 0, (res) => {
if (res.code === 0) {
this.pendings = res.conversations.filter((item) => {
return item.objectName == RongIMLib.ObjectName.ContactNotification
})
}
})
},
getPeddingList() {
// 获取系统中的好友关系会话列表
// RongIMLib.getConversationList([RongIMLib.ConversationType.SYSTEM], 50, 0, (res) => {
// if (res.code === 0) {
// this.pedings = res.conversations.filter((item) => {
// return item.objectName == RongIMLib.ObjectName.ContactNotification
// })
// }
// })
getPedings().then(res => {
console.log(res)
this.pedings = res
})
}
}
};

View File

@@ -31,7 +31,7 @@
searchFriend,
pedingFriend
} from '@/apis/interfaces/im.js';
import applyFriend from '@/components/friend-apply-reject-agree';
import applyFriend from '../components/friendApplyList.vue';
export default {
components: {
applyFriend