领峰UI库,封装一些经常使用到的组件,自定义样式,模块化js函数,调用简单快速上手。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

102 lines
2.0 KiB

<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% !important;
height: max-content;
margin-top: 20rpx;
padding: 0 !important;
box-sizing: border-box;
.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>