Browse Source

[完善] 重叠头像组件

master
邓平艺 5 years ago
parent
commit
77c3a29bbe
  1. 68
      components/lf-nolanPhoto/lf-nolanPhoto.vue

68
components/lf-nolanPhoto/lf-nolanPhoto.vue

@ -1,24 +1,68 @@
<template> <template>
<view class="content"> <view class="content">
<view class="image-item" v-for="item in 5" :key="item">
<image src="https://picsum.photos/200"></image>
<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>
<view class="image-item image-surplus"
:style="{'background': themeColor}"
v-if="list.length > count">
<text>{{ surplusNum }}</text>
</view>
</block>
</view> </view>
</template> </template>
<script> <script>
export default { 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(){ data(){
return { return {
show: false,
count: 0
} }
}, },
onLoad(){
// TODO +
// http://www.bootstrapmb.com/item/2739
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: { methods: {
clickImage(index){
this.$emit('click', index);
}
} }
} }
</script> </script>
@ -28,7 +72,7 @@
display: flex; display: flex;
flex-wrap: nowrap; flex-wrap: nowrap;
width: 100%; width: 100%;
height: 60rpx;
height: max-content;
margin-top: 20rpx; margin-top: 20rpx;
.image-item{ .image-item{
width: 60rpx; width: 60rpx;
@ -44,5 +88,13 @@
height: 100%; height: 100%;
} }
} }
.image-surplus{
border: none;
display: flex;
justify-content: center;
align-items: center;
color: #FFFFFF;
font-size: 20rpx;
}
} }
</style> </style>
Loading…
Cancel
Save