Commit f729bbf2 by Sendya

feat: avatar list

parent f9c51edf
<template>
<div>
item
</div>
<li :class="[prefixCls, size]">
<slot>
<tooltip>
<template slot="title">{{ tips }}</template>
<avatar :size="size !== 'mini' && size || 20" :src="src" />
</tooltip>
</slot>
</li>
</template>
<script>
import Avatar from 'ant-design-vue/es/avatar'
import Tooltip from 'ant-design-vue/es/tooltip'
export default {
name: "AvatarItem",
components: {
Avatar,
Tooltip
},
props: {
prefixCls: {
type: String,
default: 'ant-pro-avatar-list-item'
},
tips: {
type: String,
default: '',
......@@ -15,12 +31,18 @@
},
src: {
type: String,
required: true
default: ''
}
},
data () {
return {
size: this.$parent.size
}
},
watch: {
'$parent.size' (val) {
this.size = val
}
}
}
</script>
<style scoped>
</style>
\ No newline at end of file
</script>
\ No newline at end of file
<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>
</template>
<script>
import Avatar from 'ant-design-vue/es/avatar'
import AvatarListItem from './Item'
import AvatarItem from './Item'
export default {
AvatarItem,
name: "AvatarList",
components: {
Avatar,
AvatarListItem
AvatarItem
},
props: {
prefixCls: {
type: String,
default: 'ant-pro-avatar-list'
},
/**
* 头像大小 类型: large、small 、mini, default
* 默认值: default
*/
size: {
type: String,
type: [String, Number],
default: 'default'
},
/**
......@@ -28,24 +40,40 @@
*/
maxLength: {
type: Number,
default: 3
default: 0
},
/**
* 额外 CSS 风格
* 多余的项目风格
*/
excessItemsStyle: {
type: Object,
default: () => {}
default: () => {
return {
color: '#f56a00',
backgroundColor: '#fde3cf'
}
}
}
},
data () {
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>
<style scoped>
<style lang="less" scoped>
</style>
\ No newline at end of file
import AvatarList from './List'
import "./index.less"
export default AvatarList
\ No newline at end of file
......@@ -7,8 +7,10 @@
display: inline-block;
ul {
list-style: none;
display: inline-block;
margin-left: 8px;
padding: 0;
margin: 0 0 0 8px;
font-size: 0;
}
}
......@@ -23,20 +25,21 @@
:global {
.ant-avatar {
border: 1px solid #fff;
cursor: pointer;
}
}
.large {
&.large {
width: @avatar-size-lg;
height: @avatar-size-lg;
}
.small {
&.small {
width: @avatar-size-sm;
height: @avatar-size-sm;
}
.mini {
&.mini {
width: 20px;
height: 20px;
......@@ -53,4 +56,5 @@
}
}
}
}
\ No newline at end of file
}
......@@ -43,8 +43,27 @@
</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>
</template>
......@@ -52,11 +71,16 @@
// @ is an alias to /src
import Trend from '@/components/Trend'
import AvatarList from '@/components/AvatarList'
const AvatarListItem = AvatarList.AvatarItem
export default {
name: 'Home',
components: {
Trend
Trend,
AvatarList,
AvatarListItem
}
}
</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