1 changed files with 100 additions and 0 deletions
@ -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> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue