Commit f729bbf2 by Sendya

feat: avatar list

parent f9c51edf
<template> <template>
<div> <li :class="[prefixCls, size]">
item <slot>
</div> <tooltip>
<template slot="title">{{ tips }}</template>
<avatar :size="size !== 'mini' && size || 20" :src="src" />
</tooltip>
</slot>
</li>
</template> </template>
<script> <script>
import Avatar from 'ant-design-vue/es/avatar'
import Tooltip from 'ant-design-vue/es/tooltip'
export default { export default {
name: "AvatarItem", name: "AvatarItem",
components: {
Avatar,
Tooltip
},
props: { props: {
prefixCls: {
type: String,
default: 'ant-pro-avatar-list-item'
},
tips: { tips: {
type: String, type: String,
default: '', default: '',
...@@ -15,12 +31,18 @@ ...@@ -15,12 +31,18 @@
}, },
src: { src: {
type: String, type: String,
required: true default: ''
}
},
data () {
return {
size: this.$parent.size
}
},
watch: {
'$parent.size' (val) {
this.size = val
} }
} }
} }
</script> </script>
\ No newline at end of file
<style scoped>
</style>
\ No newline at end of file
<template> <template>
<div> <div :class="[prefixCls]">
<ul>
<slot></slot>
<template v-if="maxLength > 0 && slotsSize > maxLength">
<avatar-item :size="size">
<avatar :size="size !== 'mini' && size || 20" :style="excessItemsStyle">{{ `+${maxLength}` }}</avatar>
</avatar-item>
</template>
</ul>
</div> </div>
</template> </template>
<script> <script>
import Avatar from 'ant-design-vue/es/avatar' import Avatar from 'ant-design-vue/es/avatar'
import AvatarListItem from './Item' import AvatarItem from './Item'
export default { export default {
AvatarItem,
name: "AvatarList", name: "AvatarList",
components: { components: {
Avatar, Avatar,
AvatarListItem AvatarItem
}, },
props: { props: {
prefixCls: {
type: String,
default: 'ant-pro-avatar-list'
},
/** /**
* 头像大小 类型: large、small 、mini, default * 头像大小 类型: large、small 、mini, default
* 默认值: default * 默认值: default
*/ */
size: { size: {
type: String, type: [String, Number],
default: 'default' default: 'default'
}, },
/** /**
...@@ -28,24 +40,40 @@ ...@@ -28,24 +40,40 @@
*/ */
maxLength: { maxLength: {
type: Number, type: Number,
default: 3 default: 0
}, },
/** /**
* 额外 CSS 风格 * 多余的项目风格
*/ */
excessItemsStyle: { excessItemsStyle: {
type: Object, type: Object,
default: () => {} default: () => {
return {
color: '#f56a00',
backgroundColor: '#fde3cf'
}
}
} }
}, },
data () { data () {
return { return {
slotsSize: 0
}
},
created () {
this.slotsSize = this.$slots.default.length
this.splitSlots()
},
methods: {
splitSlots () {
if (this.maxLength !== 0 && this.slotsSize > this.maxLength) {
this.$slots.default = this.$slots.default.slice(0, this.maxLength)
}
} }
} }
} }
</script> </script>
<style scoped> <style lang="less" scoped>
</style> </style>
\ No newline at end of file
import AvatarList from './List' import AvatarList from './List'
import "./index.less"
export default AvatarList export default AvatarList
\ No newline at end of file
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
display: inline-block; display: inline-block;
ul { ul {
list-style: none;
display: inline-block; display: inline-block;
margin-left: 8px; padding: 0;
margin: 0 0 0 8px;
font-size: 0; font-size: 0;
} }
} }
...@@ -23,20 +25,21 @@ ...@@ -23,20 +25,21 @@
:global { :global {
.ant-avatar { .ant-avatar {
border: 1px solid #fff; border: 1px solid #fff;
cursor: pointer;
} }
} }
.large { &.large {
width: @avatar-size-lg; width: @avatar-size-lg;
height: @avatar-size-lg; height: @avatar-size-lg;
} }
.small { &.small {
width: @avatar-size-sm; width: @avatar-size-sm;
height: @avatar-size-sm; height: @avatar-size-sm;
} }
.mini { &.mini {
width: 20px; width: 20px;
height: 20px; height: 20px;
...@@ -54,3 +57,4 @@ ...@@ -54,3 +57,4 @@
} }
} }
} }
...@@ -43,8 +43,27 @@ ...@@ -43,8 +43,27 @@
</a-card> </a-card>
<a-divider> 例子 </a-divider> <a-divider> AvatarList </a-divider>
<a-card>
<avatar-list :max-length="3">
<avatar-list-item tips="Jake" src="https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png" />
<avatar-list-item tips="Andy" src="https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png" />
<avatar-list-item tips="Niko" src="https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png" />
<avatar-list-item tips="Niko" src="https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png" />
<avatar-list-item tips="Niko" src="https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png" />
<avatar-list-item tips="Niko" src="https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png" />
<avatar-list-item tips="Niko" src="https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png" />
</avatar-list>
<a-divider type="vertical" style="margin: 0 16px" />
<avatar-list size="mini">
<avatar-list-item tips="Jake" src="https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png" />
<avatar-list-item tips="Andy" src="https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png" />
<avatar-list-item tips="Niko" src="https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png" />
</avatar-list>
</a-card>
</div> </div>
</template> </template>
...@@ -52,11 +71,16 @@ ...@@ -52,11 +71,16 @@
// @ is an alias to /src // @ is an alias to /src
import Trend from '@/components/Trend' import Trend from '@/components/Trend'
import AvatarList from '@/components/AvatarList'
const AvatarListItem = AvatarList.AvatarItem
export default { export default {
name: 'Home', name: 'Home',
components: { components: {
Trend Trend,
AvatarList,
AvatarListItem
} }
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment