wk
2024-10-18 036831ad52733ca354e65b0274b7be9b75973651
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
<template>
    <view class="xm-popup-wrap" :class="{ 
            'xm-popup-wrap-show': show,
            'xm-popup-wrap-show-content': showContent,
        }" :style="{ 
            zIndex: zIndex,
            background: maskBackground
        }" @tap.stop="toClose" @touchmove.stop.prevent="stop" :animation="animationData">
        <view class="xm-popup-cnt" :class="{ 
            'xm-popup-cnt-show-content': showContent,
            'xm-anim': anim,
        }" :style="{
                borderTopLeftRadius: radius + 'px',
                borderTopRightRadius: radius + 'px',
                background: background
        }" @tap.stop="stop">
            <slot></slot>
        </view>
    </view>
</template>
 
<script>
    export default {
        name: 'xm-popup',
        emits: ['close'],
        props: {
            // 是否显示弹出层
            show: {
                type: Boolean,
                default: false
            },
            // 弹出层内容背景颜色
            background: {
                type: String,
                default: '#FFFFFF'
            },
            // 弹出层内容圆角
            radius: {
                type: [Number, String],
                default: 0
            },
            // 弹出层的z-index
            zIndex: {
                type: [Number, String],
                default: 1992
            },
            // 点击遮罩, 是否可关闭
            maskClosable: {
                type: Boolean,
                default: true
            },
            // 遮罩的背景色
            maskBackground: {
                type: String,
                default: 'rgba(0,0,0,0.6)'
            },
            // 是否直接显示键盘
            showContent: {
                type: Boolean,
                default: false
            },
            // 是否加入动画效果
            anim: {
                type: Boolean,
                default: true
            }
        },
        data() {
            return {
                isShow: false,
                animation: {},
                animationData: {}
            }
        },
        methods: {
            toClose(e) {
                if (!this.maskClosable) return;
                this.$emit('close', {});
            },
            stop(e) {
 
            },
        },
    };
</script>
 
<style scoped lang="scss">
    .xm-popup {
        &-wrap {
            position: fixed;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            z-index: 1001;
            display: none;
            flex-direction: row;
            align-items: flex-end;
            justify-content: center;
 
            &-show {
                display: flex;
            }
 
            &-show-content {
                display: flex;
                position: unset;
                background-color: unset !important;
            }
        }
 
        &-cnt {
            width: 100%;
            min-height: 20px;
            overflow: hidden;
            padding-bottom: constant(safe-area-inset-bottom);
            padding-bottom: env(safe-area-inset-bottom);
            flex: 1;
            
            &.xm-anim{
                animation-duration: .2s;
                animation-timing-function: ease-out;
                animation-fill-mode: both;
                animation-name: xm-up;
            }
 
            &-show-content {
                padding-bottom: 0;
            }
        }
 
        @keyframes xm-up {
            0% {
                opacity: 0;
                transform: translateY(100%)
            }
 
            100% {
                opacity: 1;
                transform: translateY(0)
            }
        }
    }
</style>