widget-avatar-group.vue
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<div v-if="avatars" class="avatar-list-wrap">
<ul v-if="avatarList" class="avatar-list">
<li v-for="(item, index) in avatarList" :key="index" :style="item.style">
<WidgetAvatar :src="item.src" width="100" height="100"></WidgetAvatar>
</li>
<li v-if="hasMore">
<img src="//img12.static.yhbimg.com/evidenceImages/2019/01/30/17/02fdbbddfc30f18868f91406eed8a70fb9.png?imageMogr2/thumbnail/130x130/extent/130x130/background/d2hpdGU=/position/center/quality/90">
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'WidgetAvatarGroup',
props: {
avatars: Array,
option: {
type: Object,
default() {
return {
srcKey: 'src',
maxDisplayNum: 0
};
}
}
},
data() {
return {
hasMore: false
}
},
computed: {
avatarList() {
let list = [];
let length = this.avatars && this.avatars.length;
if (this.option.maxDisplayNum > 0 && this.avatars.length > this.option.maxDisplayNum) {
length = this.option.maxDisplayNum;
this.hasMore = true;
}
for (let i = 0; i < length; i++) {
let avt = this.avatars[i];
let src = avt;
if (this.option.srcKey && typeof avt !== 'string') {
src = avt[this.option.srcKey] || '';
}
list.push({
src: src,
style: `z-index: ${length - i};`
});
}
return list;
}
}
};
</script>
<style type="css">
.avatar-list-wrap {
display: inline-block;
vertical-align: middle;
}
.avatar-list {
display: flex;
li {
width: 60px;
height: 60px;
border: 1px solid #fff;
border-radius: 50%;
overflow: hidden;
margin-left: -18px;
position: relative;
&:first-child {
margin-left: 0;
}
img {
display: block;
width: 100%;
height: 100%;
}
}
}
</style>