|
|
@@ -0,0 +1,236 @@
|
|
|
+<template>
|
|
|
+ <div class="contacts-page">
|
|
|
+ <van-nav-bar title="通讯录" fixed placeholder class="wechat-nav">
|
|
|
+ <template #right>
|
|
|
+ <van-icon name="user-plus-o" size="22" color="#181818" @click="$toast('添加联系人')" />
|
|
|
+ </template>
|
|
|
+ </van-nav-bar>
|
|
|
+
|
|
|
+ <van-search v-model="searchKey" placeholder="搜索" class="wechat-search" />
|
|
|
+
|
|
|
+ <div class="top-services">
|
|
|
+ <van-cell title="新的朋友" is-link class="wechat-cell">
|
|
|
+ <template #icon>
|
|
|
+ <div class="service-icon-wrapper orange">
|
|
|
+ <van-icon name="friends-o" />
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </van-cell>
|
|
|
+ <van-cell title="仅聊天的朋友" is-link class="wechat-cell">
|
|
|
+ <template #icon>
|
|
|
+ <div class="service-icon-wrapper blue">
|
|
|
+ <van-icon name="comment-circle-o" />
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </van-cell>
|
|
|
+ <van-cell title="群聊" is-link class="wechat-cell">
|
|
|
+ <template #icon>
|
|
|
+ <div class="service-icon-wrapper green">
|
|
|
+ <van-icon name="cluster-o" />
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </van-cell>
|
|
|
+ <van-cell title="标签" is-link class="wechat-cell">
|
|
|
+ <template #icon>
|
|
|
+ <div class="service-icon-wrapper blue-dark">
|
|
|
+ <van-icon name="label-o" />
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </van-cell>
|
|
|
+ <van-cell title="公众号" is-link class="wechat-cell">
|
|
|
+ <template #icon>
|
|
|
+ <div class="service-icon-wrapper blue-light">
|
|
|
+ <van-icon name="service-o" />
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </van-cell>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <van-index-bar :index-list="indexList" highlight-color="#07c160" class="wechat-index-bar">
|
|
|
+ <div v-for="group in filteredContacts" :key="group.letter">
|
|
|
+ <van-index-anchor :index="group.letter" class="wechat-anchor" />
|
|
|
+
|
|
|
+ <van-cell
|
|
|
+ v-for="user in group.list"
|
|
|
+ :key="user.id"
|
|
|
+ :title="user.name"
|
|
|
+ class="wechat-cell contact-item"
|
|
|
+ @click="goChat(user)"
|
|
|
+ >
|
|
|
+ <template #icon>
|
|
|
+ <van-image
|
|
|
+ radius="4"
|
|
|
+ width="40"
|
|
|
+ height="40"
|
|
|
+ :src="user.avatar"
|
|
|
+ class="contact-avatar"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </van-cell>
|
|
|
+ </div>
|
|
|
+ </van-index-bar>
|
|
|
+
|
|
|
+ <div class="contact-footer" v-if="!searchKey">{{ totalContacts }} 位联系人</div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ searchKey: '',
|
|
|
+ contactData: [
|
|
|
+ {
|
|
|
+ letter: 'A',
|
|
|
+ list: [{ id: 1, name: '阿强', avatar: 'https://img01.yzcdn.cn/vant/cat.jpeg' }]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ letter: 'B',
|
|
|
+ list: [{ id: 2, name: '白老板', avatar: 'https://img01.yzcdn.cn/vant/apple-1.jpg' }]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ letter: 'G',
|
|
|
+ list: [{ id: 3, name: 'Gemini', avatar: 'https://img01.yzcdn.cn/vant/apple-2.jpg' }]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ letter: 'L',
|
|
|
+ list: [
|
|
|
+ { id: 4, name: '老王', avatar: 'https://img01.yzcdn.cn/vant/cat.jpeg' },
|
|
|
+ { id: 5, name: '李四', avatar: 'https://img01.yzcdn.cn/vant/apple-3.jpg' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ letter: 'Z',
|
|
|
+ list: [{ id: 6, name: '张三', avatar: 'https://img01.yzcdn.cn/vant/apple-1.jpg' }]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ indexList() {
|
|
|
+ return this.filteredContacts.map((item) => item.letter)
|
|
|
+ },
|
|
|
+ filteredContacts() {
|
|
|
+ if (!this.searchKey) return this.contactData
|
|
|
+ return this.contactData
|
|
|
+ .map((group) => ({
|
|
|
+ ...group,
|
|
|
+ list: group.list.filter((user) => user.name.includes(this.searchKey))
|
|
|
+ }))
|
|
|
+ .filter((group) => group.list.length > 0)
|
|
|
+ },
|
|
|
+ totalContacts() {
|
|
|
+ return this.contactData.reduce((acc, cur) => acc + cur.list.length, 0)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ goChat(user) {
|
|
|
+ this.$router.push({ path: '/chat/dialog', query: { userId: user.id, name: user.name } })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped lang="less">
|
|
|
+/* 微信配色变量 */
|
|
|
+@wechat-bg: #ededed;
|
|
|
+@wechat-green: #07c160;
|
|
|
+@wechat-anchor-bg: #ededed;
|
|
|
+@wechat-border: #e5e5e5;
|
|
|
+
|
|
|
+.contacts-page {
|
|
|
+ background-color: @wechat-bg;
|
|
|
+ min-height: 100vh;
|
|
|
+
|
|
|
+ .wechat-search {
|
|
|
+ background-color: @wechat-bg;
|
|
|
+ padding: 10px 12px;
|
|
|
+ ::v-deep .van-search__content {
|
|
|
+ background-color: #fff;
|
|
|
+ border-radius: 6px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .top-services {
|
|
|
+ margin-bottom: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 微信风格的服务图标 */
|
|
|
+ .service-icon-wrapper {
|
|
|
+ width: 40px;
|
|
|
+ height: 40px;
|
|
|
+ border-radius: 6px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ margin-right: 12px;
|
|
|
+ color: #fff;
|
|
|
+ font-size: 24px;
|
|
|
+
|
|
|
+ &.orange {
|
|
|
+ background-color: #fa9d3b;
|
|
|
+ }
|
|
|
+ &.blue {
|
|
|
+ background-color: #2782d7;
|
|
|
+ }
|
|
|
+ &.green {
|
|
|
+ background-color: #07c160;
|
|
|
+ }
|
|
|
+ &.blue-dark {
|
|
|
+ background-color: #576b95;
|
|
|
+ }
|
|
|
+ &.blue-light {
|
|
|
+ background-color: #2782d7;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .contact-avatar {
|
|
|
+ margin-right: 12px;
|
|
|
+ border-radius: 4px; // 微信头像偏向方圆
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 单元格样式覆盖 */
|
|
|
+ .wechat-cell {
|
|
|
+ padding: 10px 16px;
|
|
|
+ align-items: center;
|
|
|
+ &::after {
|
|
|
+ left: 68px; // 线条避开头像
|
|
|
+ border-bottom: 1px solid @wechat-border;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 索引锚点样式 */
|
|
|
+ .wechat-anchor {
|
|
|
+ background-color: @wechat-anchor-bg;
|
|
|
+ color: #888;
|
|
|
+ line-height: 32px;
|
|
|
+ padding: 0 16px;
|
|
|
+ font-size: 14px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .contact-footer {
|
|
|
+ text-align: center;
|
|
|
+ padding: 30px;
|
|
|
+ color: #888;
|
|
|
+ font-size: 16px;
|
|
|
+ background: #fff;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 右侧索引栏 */
|
|
|
+ .wechat-index-bar {
|
|
|
+ ::v-deep .van-index-bar__index {
|
|
|
+ padding: 2px 8px;
|
|
|
+ font-size: 11px;
|
|
|
+ line-height: 14px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/* 覆盖导航栏底色 */
|
|
|
+.wechat-nav {
|
|
|
+ background-color: @wechat-bg;
|
|
|
+ ::v-deep .van-nav-bar__title {
|
|
|
+ font-weight: 500;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|