cdk
2025-03-24 06e6cf5719a7de9d7919cee2f6fcc3cfc6f9eb9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<template>
    <view v-if="width" :style="'width:'+(100/column+'%')+';'+(square?'height:'+width:'')" class="uni-grid-item">
        <view :class="{ 'uni-grid-item--border': showBorder,  'uni-grid-item--border-top': showBorder && index < column, 'uni-highlight': highlight }"
         :style="{  'border-right-color': borderColor ,'border-bottom-color': borderColor ,'border-top-color': borderColor }"
         class="uni-grid-item__box" @click="_onClick">
            <slot />
        </view>
    </view>
</template>
 
<script>
    export default {
        name: 'UniGridItem',
        inject: ['grid'],
        props: {
            index:{
                type: Number,
                default: 0
            }
        },
        data() {
            return {
                column: 0,
                showBorder: true,
                square: true,
                highlight: true,
                left: 0,
                top: 0,
                openNum: 2,
                width: 0,
                borderColor: '#e5e5e5'
            }
        },
        created() {
            this.column = this.grid.column
            this.showBorder = this.grid.showBorder
            this.square = this.grid.square
            this.highlight = this.grid.highlight
            this.top = this.hor === 0 ? this.grid.hor : this.hor
            this.left = this.ver === 0 ? this.grid.ver : this.ver
            this.borderColor = this.grid.borderColor
            this.grid.children.push(this)
            // this.grid.init()
            this.width = this.grid.width
        },
        beforeDestroy() {
            this.grid.children.forEach((item, index) => {
                if (item === this) {
                    this.grid.children.splice(index, 1)
                }
            })
        },
        methods: {
            _onClick() {
                this.grid.change({
                    detail: {
                        index: this.index
                    }
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .uni-grid-item {
        /* #ifndef APP-NVUE */
        height: 100%;
        display: flex;
        /* #endif */
    }
 
    .uni-grid-item__box {
        /* #ifndef APP-NVUE */
        display: flex;
        width: 100%;
        /* #endif */
        position: relative;
        flex: 1;
        flex-direction: column;
        // justify-content: center;
        // align-items: center;
    }
 
    .uni-grid-item--border {
        position: relative;
        border-bottom-color: $uni-border-color;
        border-bottom-style: solid;
        border-bottom-width: 1px;
        border-right-color: $uni-border-color;
        border-right-style: solid;
        border-right-width: 1px;
    }
 
    .uni-grid-item--border-top {
        border-top-color: $uni-border-color;
        border-top-style: solid;
        border-top-width: 1px;
        /* #ifndef APP-NVUE */
        height: 100%;
        box-sizing: border-box;
        /* #endif */
    }
 
    .uni-highlight:active {
        background-color: $uni-bg-color-hover;
    }
</style>