zhangwei
2024-08-14 9d8994790fe403935ed46ad478f83ae110bb7a01
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:1 6 3,营业执照号:9   15 10131 3 320     06  19 3   K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view v-if="width" :style="'width:'+width+';'+(height?'height:'+height:'')" class="fui-grid__item">
        <view :class="{ 'fui-grid__item-border': showBorder, 'fui-highlight': highlight }"
            :style="{'border-right-color': borderColor ,'border-bottom-color': borderColor ,'border-top-color': borderColor,backgroundColor:backgroundColor }"
            class="fui-grid__item-box" @click="handleClick">
            <slot></slot>
        </view>
    </view>
</template>
 
<script>
    export default {
        name: "fui-grid-item",
        emits: ['click'],
        inject: ['grid'],
        // #ifdef MP-WEIXIN
        options: {
            virtualHost: true
        },
        // #endif
        props: {
            //是否有点击效果
            highlight: {
                type: Boolean,
                default: true
            },
            backgroundColor: {
                type: String,
                default: 'transparent'
            },
            //索引
            index: {
                type: Number,
                default: 0
            }
        },
        data() {
            return {
                columns: 0,
                showBorder: true,
                width: 0,
                height: 0,
                borderColor: '#eaeef1'
            };
        },
        created() {
            this.init()
        },
        // #ifndef VUE3
        beforeDestroy() {
            if (this.grid) {
                this.grid.children.forEach((item, index) => {
                    if (item === this) {
                        this.grid.children.splice(index, 1)
                    }
                })
            }
        },
        // #endif
        // #ifdef VUE3
        beforeUnmount() {
            if (this.grid) {
                this.grid.children.forEach((item, index) => {
                    if (item === this) {
                        this.grid.children.splice(index, 1)
                    }
                })
            }
        },
        // #endif
        methods: {
            init() {
                if (this.grid) {
                    this.columns = this.grid.columns
                    this.showBorder = this.grid.showBorder
                    this.borderColor = this.grid.borderColor
                    this.grid.children.push(this)
                    this.width = this.grid.width
                    this.height = this.grid.height
                }
            },
            handleClick() {
                const e = {
                    detail: {
                        index: this.index
                    }
                }
                this.grid && this.grid.handleClick(e)
                this.$emit('click', e)
            }
        }
    }
</script>
 
<style scoped>
    .fui-grid__item {
        /* #ifndef APP-NVUE */
        height: 100%;
        display: flex;
        box-sizing: border-box;
        flex-shrink: 0;
        /* #endif */
        flex-direction: column;
        /* #ifdef H5 */
        cursor: pointer;
        /* #endif */
    }
 
    .fui-grid__item-box {
        /* #ifndef APP-NVUE */
        display: flex;
        width: 100%;
        /* #endif */
        position: relative;
        flex: 1;
        flex-direction: column;
        /* #ifndef APP-NVUE */
        box-sizing: border-box;
        /* #endif */
    }
 
    .fui-grid__item-border {
        position: relative;
        /* #ifdef APP-NVUE */
        border-bottom-color: #EEEEEE;
        border-bottom-style: solid;
        border-bottom-width: 0.5px;
        border-right-color: #EEEEEE;
        border-right-style: solid;
        border-right-width: 0.5px;
        /* #endif */
        /* #ifndef APP-NVUE */
        z-index: 0;
        border-bottom: 0;
        border-right: 0;
        /* #endif */
    }
 
 
 
    /* #ifndef APP-NVUE */
    .fui-grid__item-border::before {
        content: " ";
        position: absolute;
        right: 0;
        top: 0;
        width: 1px;
        bottom: 0;
        border-right: 1px solid var(--fui-color-border, #EEEEEE);
        -webkit-transform-origin: 100% 0;
        transform-origin: 100% 0;
        -webkit-transform: scaleX(0.5);
        transform: scaleX(0.5);
    }
 
    .fui-grid__item-border::after {
        content: " ";
        position: absolute;
        left: 0;
        bottom: 0;
        right: 0;
        height: 1px;
        border-bottom: 1px solid var(--fui-color-border, #EEEEEE);
        -webkit-transform-origin: 0 100%;
        transform-origin: 0 100%;
        -webkit-transform: scaleY(0.5);
        transform: scaleY(0.5);
    }
 
    /* #endif */
 
    .fui-highlight:active {
        /* #ifdef APP-NVUE */
        background-color: rgba(0, 0, 0, 0.2) !important;
        /* #endif */
 
        /* #ifndef APP-NVUE */
        background-color: var(--fui-color-hover, rgba(0, 0, 0, 0.2)) !important;
        /* #endif */
    }
</style>