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.
129 lines
2.3 KiB
129 lines
2.3 KiB
<template>
|
|
<view class="grid-item" :class="{hover}" :style="{width:center?'':width,padding: getPadding}">
|
|
<view class="grid-item__wrapper">
|
|
<image :style="{width:rect,height:rect,}"
|
|
class="grid-item__icon"
|
|
:class="{circle}"
|
|
v-if="type=='icon'&&icon"
|
|
:src="icon" mode="aspectFill"></image>
|
|
<view class="grid-item__text" :style="{padding: top}">
|
|
<text v-if="always">{{text}}</text>
|
|
<slot><text v-if="!always">{{text}}</text></slot>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: "niu-grid-item",
|
|
props: {
|
|
always:{
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
icon:{
|
|
type: String,
|
|
default: '',
|
|
},
|
|
circle:{
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
button:{
|
|
type: String,
|
|
default: '',
|
|
},
|
|
topText:{
|
|
type: String,
|
|
default: '',
|
|
},
|
|
text:{
|
|
type: String,
|
|
default: '',
|
|
},
|
|
padding: {
|
|
type: String,
|
|
default: '15rpx 20rpx',
|
|
},
|
|
top: {
|
|
type: String,
|
|
default: '',
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
num: 5,
|
|
rect: '80rpx',
|
|
type: 'icon',
|
|
hover: true,
|
|
center: false
|
|
}
|
|
},
|
|
computed: {
|
|
width(){
|
|
if(this.num == 0) return 0 + '%';
|
|
return 100/this.num + '%';
|
|
},
|
|
getPadding(){
|
|
return this.padding
|
|
}
|
|
},
|
|
mounted() {
|
|
let parent = this.$n.util.getParent('niu-grid',this);
|
|
if(parent){
|
|
this.num = parent.num;
|
|
this.rect = parent.rect;
|
|
this.type = parent.type;
|
|
this.hover = parent.hover;
|
|
this.center = parent.center;
|
|
// 将子组件注册到父组件显示
|
|
parent.registerGridItem()
|
|
}
|
|
},
|
|
methods: {
|
|
bindGetUserInfo(e) {
|
|
this.$emit("userinfo",e)
|
|
}
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.grid-item{
|
|
display: inline-flex;
|
|
box-sizing: border-box;
|
|
&.hover:active{
|
|
background-color: #f5f5f5;
|
|
}
|
|
&__icon{
|
|
margin-bottom: 12rpx;
|
|
&.circle{
|
|
border-radius: 50%;
|
|
}
|
|
}
|
|
.grid-item__wrapper{
|
|
margin: auto;
|
|
width: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
text-align: center;
|
|
position: relative;
|
|
.grid-item__text{
|
|
// white-space: nowrap;
|
|
width: 100%;
|
|
@include ellipsis(2);
|
|
}
|
|
.button{
|
|
position: absolute;
|
|
left: 0;
|
|
bottom: 0;
|
|
top: 0;
|
|
right: 0;
|
|
z-index: 1;
|
|
opacity: 0;
|
|
}
|
|
}
|
|
}
|
|
</style>
|