zhangwei
2024-09-23 208b5a9f559dd2c7298759fdfe37d07c926cbd4d
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:  163,营业执照号:  9 1510 1 3  1  332 006 1   9 3  K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-list__cell" :class="{'fui-highlight':highlight,'fui-list__cell-background':!background}"
        :style="{paddingTop:getPadding[0] || 0,paddingRight:getPadding[1] || 0,paddingBottom:getPadding[2] || getPadding[0] || 0,paddingLeft:getPadding[3] || getPadding[1] || 0,background:background,marginTop:marginTop+'rpx',marginBottom:marginBottom+'rpx',borderRadius:radius}"
        @tap="handleClick">
        <view v-if="topBorder" :style="{background:getBorderColor,left:topLeft+'rpx',right:topRight+'rpx'}"
            class="fui-cell__border-top" :class="{'fui-cell__border-color':!getBorderColor}"></view>
        <slot></slot>
        <view v-if="bottomBorder" :style="{background:getBorderColor,left:getBottomLeft+'rpx',right:bottomRight+'rpx'}"
            class="fui-cell__border-bottom" :class="{'fui-cell__border-color':!getBorderColor}"></view>
        <view class="fui-cell__arrow" v-if="arrow" :style="{'border-color':getArrowColor}">
        </view>
    </view>
</template>
 
<script>
    export default {
        name: "fui-list-cell",
        emits: ['click'],
        props: {
            //padding值,上、右、下、左,nvue下padding-right(右)无效
            padding: {
                type: Array,
                default () {
                    return []
                }
            },
            //margin-top 单位rpx
            marginTop: {
                type: [Number, String],
                default: 0
            },
            //margin-bottom 单位rpx
            marginBottom: {
                type: [Number, String],
                default: 0
            },
            //背景颜色
            // #ifdef APP-NVUE
            background: {
                type: String,
                default: '#fff'
            },
            // #endif
            // #ifndef APP-NVUE
            background: {
                type: String,
                default: ''
            },
            // #endif
            //是否有点击效果
            highlight: {
                type: Boolean,
                default: true
            },
            //是否需要右侧箭头
            arrow: {
                type: Boolean,
                default: false
            },
            arrowColor: {
                type: String,
                default: ''
            },
            //是否显示上边框
            topBorder: {
                type: Boolean,
                default: false
            },
            //是否显示下边框
            bottomBorder: {
                type: Boolean,
                default: true
            },
            //边框颜色,非nvue下传值则全局默认样式失效
            borderColor: {
                type: String,
                default: ''
            },
            //上边框left值,单位rpx
            topLeft: {
                type: [Number, String],
                default: 0
            },
            //上边框right值,单位rpx
            topRight: {
                type: [Number, String],
                default: 0
            },
            //下边框left值,单位rpx
            bottomLeft: {
                type: [Number, String],
                default: -1
            },
            //下边框right值,单位rpx
            bottomRight: {
                type: [Number, String],
                default: 0
            },
            //border-radius圆角值
            radius: {
                type: String,
                default: '0'
            },
            index: {
                type: Number,
                default: 0
            }
        },
        computed: {
            getPadding() {
                let padding = this.padding
                if (Array.isArray(padding) && padding.length === 0) {
                    const app = uni && uni.$fui && uni.$fui.fuiListCell;
                    padding = app && app.padding;
                    if (!padding || (Array.isArray(padding) && padding.length === 0)) {
                        padding = ['32rpx', '32rpx']
                    }
                }
                return padding;
            },
            getArrowColor() {
                const app = uni && uni.$fui && uni.$fui.fuiListCell;
                return this.arrowColor || (app && app.arrowColor) || '#B2B2B2'
            },
            getBorderColor() {
                let color = this.borderColor;
                // #ifdef APP-NVUE
                if (!color || color === true) {
                    const app = uni && uni.$fui && uni.$fui.fuiListCell;
                    color = (app && app.borderColor) || '#EEEEEE'
                }
                // #endif
                return color;
            },
            getBottomLeft() {
                const app = uni && uni.$fui && uni.$fui.fuiListCell;
                let left = this.bottomLeft;
                const c_left = app && app.bottomLeft
                if (left === -1) {
                    left = (c_left === undefined || c_left === null) ? 32 : c_left
                }
                return left
            }
        },
        methods: {
            handleClick() {
                this.$emit('click', {
                    index: this.index
                });
            }
        }
    }
</script>
 
<style scoped>
    .fui-list__cell {
        position: relative;
        flex: 1;
        /* #ifndef APP-NVUE */
        width: 100%;
        display: flex;
        box-sizing: border-box;
        /* #endif */
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
 
    /* #ifdef APP-NVUE */
    .fui-list__item {
        flex: 1;
    }
 
    /* #endif */
    .fui-cell__arrow {
        height: 40rpx;
        width: 40rpx;
        border-width: 3px 3px 0 0;
        border-style: solid;
        transform: rotate(45deg) scale(0.5);
        /* #ifndef APP-NVUE */
        border-radius: 4rpx;
        flex-shrink: 0;
        margin-left: auto;
        box-sizing: border-box;
        /* #endif */
        /* #ifdef APP-NVUE */
        border-top-right-radius: 3rpx;
        /* #endif */
        transform-origin: center center;
        margin-right: -5.8579rpx;
    }
 
    .fui-cell__border-top {
        position: absolute;
        top: 0;
        /* #ifdef APP-NVUE */
        height: 0.5px;
        z-index: -1;
        /* #endif */
 
        /* #ifndef APP-NVUE */
        height: 1px;
        -webkit-transform: scaleY(0.5);
        transform: scaleY(0.5);
        transform-origin: 0 0;
        z-index: 1;
        /* #endif */
    }
 
    .fui-cell__border-bottom {
        position: absolute;
        bottom: 0;
        /* #ifdef APP-NVUE */
        height: 0.5px;
        z-index: -1;
        /* #endif */
        /* #ifndef APP-NVUE */
        height: 1px;
        -webkit-transform: scaleY(0.5) translateZ(0);
        transform: scaleY(0.5) translateZ(0);
        transform-origin: 0 100%;
        z-index: 1;
        /* #endif */
    }
 
    /* #ifndef APP-NVUE */
    .fui-cell__border-color {
        background-color: var(--fui-color-border, #EEEEEE) !important;
    }
 
    .fui-list__cell-background {
        background-color: var(--fui-bg-color, #fff);
    }
 
    /* #endif */
    .fui-highlight:active {
        /* #ifdef APP-NVUE */
        background-color: rgba(0, 0, 0, 0.2) !important;
        /* #endif */
 
        /* #ifndef APP-NVUE */
        background-color: var(--fui-bg-color-hover, rgba(0, 0, 0, 0.2)) !important;
        /* #endif */
    }
</style>