<template>
<view class="u-grid-item" :hover-class="hoverClass"
:hover-stay-time="200" @tap="click" :style="{
background: bgColor,
width: width,
}">
<view class="u-grid-item-box" :class="[showBorder ? 'u-border-right u-border-bottom' : '']">
<slot />
</view>
</view>
</template>
<script>
export default {
name: "u-grid-item",
props: {
bgColor: {
type: String,
default: '#ffffff'
},
index: {
type: [Number, String],
default: ''
},
},
inject: ['uGrid'],
data() {
return {
hoverClass: '',
};
},
created() {
this.hoverClass = this.uGrid.hoverClass;
},
computed: {
colNum() {
return this.col < 2 ? 2 : this.col > 12 ? 12 : this.col;
},
width() {
return 100 / Number(this.uGrid.col) + '%';
},
showBorder() {
return this.uGrid.border;
}
},
methods: {
click() {
this.$emit('click', this.index);
this.uGrid.click(this.index);
}
},
};
</script>
<style scoped lang="scss">
@import "../../libs/css/style.components.scss";
.u-grid-item {
box-sizing: border-box;
background: #fff;
display: flex;
align-items: center;
justify-content: center;
position: relative;
flex-direction: column;
position: relative;
float: left;
}
.u-grid-item-hover {
background: #f7f7f7 !important;
}
.u-grid-marker-box {
position: absolute;
display: inline-block;
line-height: 0;
}
.u-grid-marker-wrap {
position: absolute;
}
.u-grid-item-box {
padding: 30rpx 0;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
flex: 1;
width: 100%;
height: 100%;
}
</style>