Browse Source

[新增] 头像重叠组件

master
LAPTOP-D7TKRI82\邓 5 years ago
parent
commit
2c52a21b48
  1. 100
      components/lf-nolanPhoto/lf-nolanPhoto.vue

100
components/lf-nolanPhoto/lf-nolanPhoto.vue

@ -0,0 +1,100 @@
<template>
<view class="content">
<block v-if="show">
<view class="image-item"
v-for="(item, index) in list" :key="index"
v-if="(index+1) < count"
@click="clickImage(index)">
<image :src="item"></image>
</view>
<view class="image-item image-surplus"
:style="{'background': themeColor}"
v-if="list.length > count">
<text>{{ surplusNum }}</text>
</view>
</block>
</view>
</template>
<script>
export default {
props: {
list: {
type: Array,
default: function(){
return [
"https://picsum.photos/200",
"https://picsum.photos/210",
"https://picsum.photos/220",
"https://picsum.photos/230",
"https://picsum.photos/240"
]
}
},
themeColor: {
type: String,
default: '#E21196'
}
},
data(){
return {
show: false,
count: 0
}
},
computed: {
surplusNum(){
let num = this.$props.list.length - this.count;
num = Math.floor(num);
num = num > 99 ? '99+' : '+'+ num;
return num;
}
},
mounted(){
let that = this;
let info = uni.createSelectorQuery().in(this).select(".content");
info.boundingClientRect(function(data) {
let count = Math.floor( parseInt(data.width) / 23 - 1 ); //
that.count = count;
that.show = true;
}).exec();
},
methods: {
clickImage(index){
this.$emit('click', index);
}
}
}
</script>
<style lang="scss" scoped="scoped">
.content{
display: flex;
flex-wrap: nowrap;
width: 100%;
height: max-content;
margin-top: 20rpx;
.image-item{
width: 60rpx;
height: 60rpx;
border-radius: 50%;
border: 2rpx solid #FFFFFF;
overflow: hidden;
&:nth-child(n+2){
margin-left: -16rpx;
}
image{
width: 100%;
height: 100%;
}
}
.image-surplus{
border: none;
display: flex;
justify-content: center;
align-items: center;
color: #FFFFFF;
font-size: 20rpx;
}
}
</style>
Loading…
Cancel
Save