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
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
248
249
250
251
252
253
254
255
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:16  3,营业执照号: 91510 1  3   1332 006 19       3 K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-bottom__popup-wrap" :class="{'fui-bottom__popwrap-show':show}"
        :style="{ zIndex: zIndex,background:maskBackground}" @tap.stop="handleClose" v-if="isShow || !isNvue"
        ref="fui_bp_mk_ani">
        <!-- @touchmove.stop.prevent="stop" -->
        <!-- #ifdef APP-NVUE -->
        <view class="fui-bottom__popup-border" :style="{height:radius+'rpx',background: background}" v-if="radius">
        </view>
        <!-- #endif -->
        <view ref="fui_bp_ani" class="fui-bottom__popup"
            :class="{ 'fui-bottom__popup-show': show,'fui-bp__safe-weex':iphoneX && safeArea}"
            :style="{borderTopLeftRadius:radius+'rpx',borderTopRightRadius:radius+'rpx' ,background: background}"
            @tap.stop="stop($event,true)">
            <slot></slot>
        </view>
    </view>
</template>
 
<script>
    // #ifdef APP-NVUE
    const animation = uni.requireNativePlugin('animation');
    // #endif
    /*如果底部有自定义导航栏,可适当设置内容padding-bottom值*/
    export default {
        name: 'fui-bottom-popup',
        emits: ['close'],
        props: {
            show: {
                type: Boolean,
                default: false
            },
            //背景颜色
            background: {
                type: String,
                default: '#fff'
            },
            //圆角
            radius: {
                type: [Number, String],
                default: 24
            },
            zIndex: {
                type: [Number, String],
                default: 996
            },
            //点击遮罩 是否可关闭
            maskClosable: {
                type: Boolean,
                default: true
            },
            maskBackground: {
                type: String,
                default: 'rgba(0,0,0,.6)'
            },
            //是否适配底部安全区
            safeArea: {
                type: Boolean,
                default: true
            }
        },
        data() {
            let isAndroid = false;
            let isNvue = false;
            // #ifdef APP-NVUE
            isNvue = true;
            const res = uni.getSystemInfoSync();
            isAndroid = res.platform.toLocaleLowerCase() == "android"
            // #endif
            return {
                iphoneX: false,
                isNvue: isNvue,
                isShow: false,
                isAndroid: isAndroid
            }
        },
        // #ifdef APP-NVUE
        watch: {
            show: {
                handler(newVal) {
                    if (newVal) {
                        this.open();
                    } else {
                        this.close();
                    }
                },
                immediate: true
            }
        },
        // #endif
        created() {
            // #ifdef APP-NVUE || MP-TOUTIAO
            this.iphoneX = this.isPhoneX();
            // #endif
        },
        methods: {
            handleClose(e) {
                if (!this.maskClosable) return;
                this.$emit('close', {});
            },
            // #ifdef APP-NVUE || MP-TOUTIAO
            isPhoneX() {
                if (!this.safeArea) return false;
                //34px
                const res = uni.getSystemInfoSync();
                let iphonex = false;
                let models = ['iphonex', 'iphonexr', 'iphonexsmax']
                for (let i = 11; i < 20; i++) {
                    models.push(`iphone${i}`)
                    models.push(`iphone${i}mini`)
                    models.push(`iphone${i}pro`)
                    models.push(`iphone${i}promax`)
                }
                const model = res.model.replace(/\s/g, "").toLowerCase()
                const newModel = model.split('<')[0]
                if (models.includes(model) || models.includes(newModel) || (res.safeAreaInsets && res.safeAreaInsets
                        .bottom > 0)) {
                    iphonex = true;
                }
                return iphonex;
            },
            // #endif
            // #ifdef APP-NVUE
            open() {
                this.isShow = true;
                this.$nextTick(() => {
                    setTimeout(() => {
                        this._animation(true);
                    }, 50);
                })
            },
            close() {
                this._animation(false);
            },
            _animation(type) {
                if (!this.$refs['fui_bp_ani'] || !this.$refs['fui_bp_mk_ani']) return;
                animation.transition(
                    this.$refs['fui_bp_mk_ani'].ref, {
                        styles: {
                            opacity: type ? 1 : 0
                        },
                        duration: 250,
                        timingFunction: 'ease-in-out',
                        needLayout: false,
                        delay: 0 //ms
                    },
                    () => {
                        if (!type) {
                            this.isShow = false
                        }
                    }
                );
                //nvue android 部分手机隐藏时动画有抖动感,调整duration去动画
                animation.transition(
                    this.$refs['fui_bp_ani'].ref, {
                        styles: {
                            transform: `translateY(${type ? '0' : '100%'})`
                        },
                        duration: !type && this.isAndroid ? 20 : 250,
                        timingFunction: 'ease-in-out',
                        needLayout: false,
                        delay: 0 //ms
                    },
                    () => {}
                );
            },
            // #endif
            stop(e, tap) {
                // #ifdef APP-NVUE
                tap && e.stopPropagation();
                // #endif
            }
        }
    };
</script>
 
<style scoped>
    .fui-bottom__popup-wrap {
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 1001;
        /* #ifndef APP-NVUE */
        display: flex;
        /* #endif */
        flex-direction: row;
        align-items: flex-end;
        justify-content: center;
        /* #ifndef APP-NVUE */
        transition: all ease-in-out .2s;
        visibility: hidden;
        border-bottom-width: 0;
        overflow: hidden;
        opacity: 0;
        /* #endif */
 
        /* #ifdef APP-NVUE */
        opacity: 0.001;
        /* #endif */
 
    }
 
    /* #ifdef APP-NVUE */
    .fui-bottom__popup-border {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
    }
 
    /* #endif */
 
    /* #ifndef APP-NVUE */
    .fui-bottom__popwrap-show {
        opacity: 1;
        visibility: visible;
    }
 
    /* #endif */
    .fui-bottom__popup {
        /* #ifndef APP-NVUE */
        width: 100%;
        transform: translate3d(0, 100%, 0);
        transition: all 0.3s ease-in-out;
        min-height: 20rpx;
        overflow: hidden;
        /* #endif */
 
        /* #ifndef APP-NVUE || MP-TOUTIAO */
        padding-bottom: constant(safe-area-inset-bottom);
        padding-bottom: env(safe-area-inset-bottom);
        /* #endif */
        flex: 1;
        /* #ifdef APP-NVUE */
        transform: translateY(100%);
        flex-direction: row;
        /* #endif */
    }
 
    /* #ifndef APP-NVUE */
    .fui-bottom__popup-show {
        transform: translate3d(0, 0, 0);
    }
 
    /* #endif */
 
    /* #ifdef APP-NVUE || MP-TOUTIAO */
    .fui-bp__safe-weex {
        padding-bottom: 34px;
    }
 
    /* #endif */
</style>