地址簿容器
地址簿容器是通讯录模块的底层基础组件(EmContactContainer 内部即由其组合好友列表 / 群组列表 / 通知子视图),适合需要完全自定义子视图内容的场景,或单独作为「聚合入口 + 内容区」的壳使用。
使用方式
组件以 EmAddressBookContainer 为名导出。需在 EmUIKitProvider 内使用:
vue
<script setup lang="ts">
import { EmUIKitProvider } from '@easemob-community/uikit-im'
const customEntries = [
{ key: 'blacklist', label: '黑名单', icon: 'people/person_remove', count: 2 },
{ key: 'tags', label: '我的标签', icon: 'misc/tag', to: false },
]
</script>
<template>
<EmUIKitProvider
app-key="your-app-key"
:auto-init="true"
>
<div style="height: 100vh; width: 360px;">
<em-address-book-container
title="通讯录"
:entries="customEntries"
:notice-count="3"
>
<!-- 自定义入口对应的子视图内容 -->
<template #default="{ view }">
<div v-if="view === 'blacklist'" style="padding: 16px;">
黑名单内容
</div>
</template>
</em-address-book-container>
</div>
</EmUIKitProvider>
</template>默认插槽接收
{ view },按当前视图渲染对应子视图内容;「通知」视图不传#notice插槽时会渲染内置通知列表。
API
AddressBookContainer API
Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| showHeader | boolean | true | 是否展示头部,默认 true |
| title | string | — | Header 标题 |
| headerAlign | 'left' | 'center' | 'right' | 'left' | Header 对齐方式,默认 left |
| showHomeAddButton | boolean | true | 是否在 home 头部展示「添加好友」按钮,默认 true |
| showSearch | boolean | false | 是否展示搜索框(home 生效),默认 false |
| class | string | — | 自定义根元素 class |
| style | Record<string, string> | — | 自定义根元素 style |
| transition | AddressBookContainerTransition | 'slide' | 视图切换过场,默认 'slide' |
| entries | AddressBookContainerEntry[] | — | 自定义入口列表,传入后按数组顺序展示,可与内置入口共存 |
| showNotice | boolean | true | 是否展示「通知」入口,默认 true |
| showGroup | boolean | true | 是否展示「群组」入口,默认 true(Provider.enableGroup=false 时强制隐藏) |
| showContact | boolean | true | 是否展示「联系人」入口,默认 true |
| showBlocklist | boolean | true | 是否展示「黑名单」入口,默认 true(Provider.enableBlocklist=false 时强制隐藏) |
| noticeCount | number | undefined | 「通知」徽标数量,默认 0(外部注入) |
| groupCount | number | — | 「群组」入口右侧数量,不传默认取 store 实际数量;传 0 则不展示 |
| contactCount | number | — | 「联系人」入口右侧数量,不传默认取 store 实际数量;传 0 则不展示 |
| autoEntryCount | boolean | true | 是否自动从 store 推断 groupCount/contactCount(仅未显式传入时生效),默认 true |
| entryOrder | AddressBookContainerEntryKey[] | () => ['contact', 'group', 'notice', 'blocklist'] as const | 入口顺序,默认 ['contact', 'group', 'notice', 'blocklist'] |
| noticeLabel | string | — | 自定义入口标签,不传则走 i18n |
| groupLabel | string | — | — |
| contactLabel | string | — | — |
| blocklistLabel | string | — | — |
| noticeIcon | string | — | 自定义入口图标 |
| groupIcon | string | — | — |
| contactIcon | string | — | — |
| blocklistIcon | string | — | — |
| noticePersistInvites | boolean | 'local' | 'session' | false | 是否持久化未处理通知(好友申请 + 群邀请),开启后首页徽标在刷新后也能立即显示红点 |
| initialView | AddressBookContainerView | — | 初始视图(默认 home) |
| showContactAddButton | boolean | true | 是否在联系人子视图头部展示添加好友按钮,默认 true |
| showNoticeAddButton | boolean | false | 是否在「新请求」子视图头部展示添加好友按钮,默认 false(Figma「新-Demo」2772:28346) |
| showGroupCreateButton | boolean | true | 是否在群组子视图头部展示创建群组按钮,默认 true |
| showBlocklistAddButton | boolean | true | 是否在黑名单子视图头部展示「添加黑名单」按钮,默认 true |
Events
| 事件名 | 参数 | 说明 |
|---|---|---|
view-change | view: AddressBookContainerView | — |
notice-click | — | — |
entry-click | key: string | — |
home-search | keyword: string | — |
add-contact | — | — |
create-group | — | — |
blocklist-click | — | — |
blocklist-add | — | — |
Slots
| 插槽名 | 说明 |
|---|---|
header | — |
header-extra | — |
nav | — |
nav-entry | — |
nav-entry-extra | — |
home-body | — |
home-footer | — |
watermark | — |
back-icon | — |
subheader-extra | — |
notice | — |
语义注记:
showBlocklist:仅黑名单一个入口启用时自动降级为黑名单子视图。initialView:单入口时自动降级为该入口视图。entries元素类型AddressBookContainerEntry:key/label/count(0 时不展示)/icon/visible(false 不渲染)/to(false 时仅触发entry-click,不自动切换视图)/sort(排序权重,越小越靠前)。noticeCount不给默认值(外部注入);groupCount/contactCount不传默认取 store 实际数量。blocklist-add:点击黑名单子视图头部的「添加黑名单」按钮(通讯录聚合容器内默认打开添加黑名单选人弹窗)。
插槽
header/header-extra:头部与头部附加内容nav:首页导航整体自定义,接收{ entries, onEntryClick }nav-entry/nav-entry-extra:单个入口项自定义home-body/home-footer:首页入口下方 / 底部内容back-icon:子视图返回按钮subheader-extra:子视图头部附加操作,接收{ view }default:子视图内容,接收{ view }notice:「通知」视图内容(不传则渲染内置通知列表)
实例方法
goHome()/goContact()/goGroup()/goNotice()/goBlocklist()/goTo(key):命令式切换视图view:只读当前视图 ref
