-
zhangwei
2024-08-16 ae95604f4d0f8211ffa79587ca3f42da16842609
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
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:  163,营业执照号:9           15 1   013133 2 006193K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-top__popup-wrap" :class="{'fui-top__popwrap-show':show}"
        :style="{ zIndex: zIndex,background:maskBackground }" @tap.stop="handleClose" v-if="isShow || !isNvue"
        ref="fui_tp_mk_ani">
        <!-- @touchmove.stop.prevent="stop" -->
        <view ref="fui_tp_ani" class="fui-top__popup" :class="{ 'fui-top__popup-show': show}"
            :style="{borderBottomLeftRadius:radius+'rpx',borderBottomRightRadius:radius+'rpx' ,background: background}"
            @tap.stop="stop($event,true)">
            <slot></slot>
        </view>
    </view>
</template>
 
<script>
    // #ifdef APP-NVUE
    const animation = uni.requireNativePlugin('animation');
    // #endif
    /*顶部状态栏部分可使用fui-status-bar组件占位*/
    export default {
        name: 'fui-top-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)'
            }
        },
        data() {
            let isNvue = false;
            // #ifdef APP-NVUE
            isNvue = true;
            // #endif
            return {
                isNvue: isNvue,
                isShow: false
            }
        },
        // #ifdef APP-NVUE
        watch: {
            show: {
                handler(newVal) {
                    if (newVal) {
                        this.open();
                    } else {
                        this.close();
                    }
                },
                immediate: true
            }
        },
        // #endif
        methods: {
            handleClose(e) {
                if (!this.maskClosable) return;
                this.$emit('close', {});
            },
            // #ifdef APP-NVUE
            open() {
                this.isShow = true;
                this.$nextTick(() => {
                    setTimeout(() => {
                        this._animation(true);
                    }, 50);
                })
            },
            close() {
                this._animation(false);
            },
            _animation(type) {
                if (!this.$refs['fui_tp_ani'] || !this.$refs['fui_tp_mk_ani']) return;
                animation.transition(
                    this.$refs['fui_tp_mk_ani'].ref, {
                        styles: {
                            opacity: type ? 1 : 0
                        },
                        duration: 250,
                        timingFunction: 'ease-in-out',
                        needLayout: false,
                        delay: 0 //ms
                    },
                    () => {
                        if (!type) {
                            this.isShow = false
                        }
                    }
                );
                //android 部分手机隐藏时动画有抖动感,可调整duration去动画
                animation.transition(
                    this.$refs['fui_tp_ani'].ref, {
                        styles: {
                            transform: `translateY(${type ? '0' : '-100%'})`
                        },
                        duration: 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-top__popup-wrap {
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 996;
        /* #ifndef APP-NVUE */
        display: flex;
        /* #endif */
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        /* #ifndef APP-NVUE */
        transition: all ease-in-out .2s;
        visibility: hidden;
        overflow: hidden;
        /* #endif */
        opacity: 0;
    }
 
    /* #ifndef APP-NVUE */
    .fui-top__popwrap-show {
        opacity: 1;
        visibility: visible;
    }
 
    /* #endif */
    .fui-top__popup {
        /* #ifndef APP-NVUE */
        width: 100%;
        transform: translate3d(0, -100%, 0);
        transition: all 0.3s ease-in-out;
        min-height: 20rpx;
        overflow: hidden;
        /* #endif */
        flex: 1;
        /* #ifdef APP-NVUE */
        transform: translateY(-100%);
        flex-direction: row;
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        /* #endif */
    }
 
    /* #ifndef APP-NVUE */
    .fui-top__popup-show {
        transform: translate3d(0, 0, 0);
    }
 
    /* #endif */
</style>