|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+<template>
|
|
|
2
|
+ <transition :name="transitionName">
|
|
|
3
|
+ <view v-if="visible" class="hy-popup-wrapper" :class="positionClass" @click="handleOverlayClick">
|
|
|
4
|
+ <view class="hy-popup-overlay" :style="{ backgroundColor: overlayBackgroundColor }"></view>
|
|
|
5
|
+ <view
|
|
|
6
|
+ class="hy-popup-content"
|
|
|
7
|
+ :class="[customClass, { 'hy-popup-no-padding': noPadding }]"
|
|
|
8
|
+ @click.stop
|
|
|
9
|
+ :style="{
|
|
|
10
|
+ width: width,
|
|
|
11
|
+ maxWidth: maxWidth,
|
|
|
12
|
+ backgroundColor: backgroundColor,
|
|
|
13
|
+ borderRadius: borderRadius + 'rpx'
|
|
|
14
|
+ }"
|
|
|
15
|
+ >
|
|
|
16
|
+ <!-- 自定义头部插槽 -->
|
|
|
17
|
+ <slot name="header"></slot>
|
|
|
18
|
+
|
|
|
19
|
+ <!-- 自定义内容插槽 -->
|
|
|
20
|
+ <slot></slot>
|
|
|
21
|
+
|
|
|
22
|
+ <!-- 关闭按钮 -->
|
|
|
23
|
+ <view class="close-wrap" v-if="showClose" @click="handleClose">
|
|
|
24
|
+ <u-icon name="close-circle" size="40" color="#999"></u-icon>
|
|
|
25
|
+ <text>关闭</text>
|
|
|
26
|
+ </view>
|
|
|
27
|
+ </view>
|
|
|
28
|
+ </view>
|
|
|
29
|
+ </transition>
|
|
|
30
|
+</template>
|
|
|
31
|
+
|
|
|
32
|
+<script lang="ts" setup>
|
|
|
33
|
+import { computed } from 'vue'
|
|
|
34
|
+
|
|
|
35
|
+// 定义动画类型
|
|
|
36
|
+const AnimationType = ['scale', 'slide-up', 'slide-down', 'slide-left', 'slide-right', 'fade'] as const
|
|
|
37
|
+// eslint-disable-next-line no-redeclare
|
|
|
38
|
+type AnimationType = (typeof AnimationType)[number]
|
|
|
39
|
+
|
|
|
40
|
+// 定义弹窗位置
|
|
|
41
|
+const PositionType = ['center', 'top', 'bottom', 'left', 'right'] as const
|
|
|
42
|
+// eslint-disable-next-line no-redeclare
|
|
|
43
|
+type PositionType = (typeof PositionType)[number]
|
|
|
44
|
+
|
|
|
45
|
+// 定义组件的Props
|
|
|
46
|
+interface Props {
|
|
|
47
|
+ // v-model绑定值
|
|
|
48
|
+ modelValue: boolean
|
|
|
49
|
+ // 是否显示关闭按钮
|
|
|
50
|
+ showClose?: boolean
|
|
|
51
|
+ // 点击遮罩层是否可以关闭
|
|
|
52
|
+ closeOnClickOverlay?: boolean
|
|
|
53
|
+ // 按ESC键是否可以关闭(仅Web环境)
|
|
|
54
|
+ closeOnPressEscape?: boolean
|
|
|
55
|
+ // 自定义class
|
|
|
56
|
+ customClass?: string
|
|
|
57
|
+ // 动画类型
|
|
|
58
|
+ animationType?: AnimationType
|
|
|
59
|
+ // 弹窗位置
|
|
|
60
|
+ position?: PositionType
|
|
|
61
|
+ // 宽度
|
|
|
62
|
+ width?: string | number
|
|
|
63
|
+ // 最大宽度
|
|
|
64
|
+ maxWidth?: string | number
|
|
|
65
|
+ // 背景色
|
|
|
66
|
+ backgroundColor?: string
|
|
|
67
|
+ // 遮罩背景色
|
|
|
68
|
+ overlayBackgroundColor?: string
|
|
|
69
|
+ // 圆角大小
|
|
|
70
|
+ borderRadius?: number
|
|
|
71
|
+ // 关闭按钮颜色
|
|
|
72
|
+ closeIconColor?: string
|
|
|
73
|
+ // 关闭按钮样式
|
|
|
74
|
+ closeButtonStyle?: object
|
|
|
75
|
+ // 是否无内边距
|
|
|
76
|
+ noPadding?: boolean
|
|
|
77
|
+ // 是否显示遮罩
|
|
|
78
|
+ showOverlay?: boolean
|
|
|
79
|
+ // 是否显示已领取遮罩
|
|
|
80
|
+ showUsedReceived?: boolean
|
|
|
81
|
+}
|
|
|
82
|
+
|
|
|
83
|
+// 使用默认值定义Props
|
|
|
84
|
+const props = withDefaults(defineProps<Props>(), {
|
|
|
85
|
+ showClose: false,
|
|
|
86
|
+ closeOnClickOverlay: true,
|
|
|
87
|
+ closeOnPressEscape: true,
|
|
|
88
|
+ customClass: '',
|
|
|
89
|
+ animationType: 'scale',
|
|
|
90
|
+ position: 'center',
|
|
|
91
|
+ width: '80%',
|
|
|
92
|
+ maxWidth: '600rpx',
|
|
|
93
|
+ backgroundColor: 'transparent',
|
|
|
94
|
+ overlayBackgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
|
95
|
+ borderRadius: 24,
|
|
|
96
|
+ closeIconColor: '#fff',
|
|
|
97
|
+ closeButtonStyle: () => ({}),
|
|
|
98
|
+ noPadding: false,
|
|
|
99
|
+ showOverlay: true,
|
|
|
100
|
+ showUsedReceived: false
|
|
|
101
|
+})
|
|
|
102
|
+
|
|
|
103
|
+// 定义组件的Events
|
|
|
104
|
+const emit = defineEmits<{
|
|
|
105
|
+ 'update:modelValue': [value: boolean]
|
|
|
106
|
+ close: []
|
|
|
107
|
+ opened: []
|
|
|
108
|
+ closed: []
|
|
|
109
|
+}>()
|
|
|
110
|
+
|
|
|
111
|
+// 处理v-model的双向绑定
|
|
|
112
|
+const visible = computed({
|
|
|
113
|
+ get: () => props.modelValue,
|
|
|
114
|
+ set: (value) => {
|
|
|
115
|
+ emit('update:modelValue', value)
|
|
|
116
|
+ if (value) {
|
|
|
117
|
+ emit('opened')
|
|
|
118
|
+ } else {
|
|
|
119
|
+ emit('closed')
|
|
|
120
|
+ }
|
|
|
121
|
+ }
|
|
|
122
|
+})
|
|
|
123
|
+
|
|
|
124
|
+// 计算动画名称
|
|
|
125
|
+const transitionName = computed(() => {
|
|
|
126
|
+ return `hy-popup-${props.animationType}`
|
|
|
127
|
+})
|
|
|
128
|
+
|
|
|
129
|
+// 计算位置类名
|
|
|
130
|
+const positionClass = computed(() => {
|
|
|
131
|
+ return `hy-popup-position-${props.position}`
|
|
|
132
|
+})
|
|
|
133
|
+
|
|
|
134
|
+// 点击关闭按钮
|
|
|
135
|
+const handleClose = () => {
|
|
|
136
|
+ visible.value = false
|
|
|
137
|
+ emit('close')
|
|
|
138
|
+}
|
|
|
139
|
+
|
|
|
140
|
+// 点击遮罩层
|
|
|
141
|
+const handleOverlayClick = () => {
|
|
|
142
|
+ if (props.closeOnClickOverlay) {
|
|
|
143
|
+ handleClose()
|
|
|
144
|
+ }
|
|
|
145
|
+}
|
|
|
146
|
+</script>
|
|
|
147
|
+
|
|
|
148
|
+<style lang="scss" scoped>
|
|
|
149
|
+.hy-popup-wrapper {
|
|
|
150
|
+ position: fixed;
|
|
|
151
|
+ top: 0;
|
|
|
152
|
+ left: 0;
|
|
|
153
|
+ right: 0;
|
|
|
154
|
+ bottom: 0;
|
|
|
155
|
+ z-index: 999;
|
|
|
156
|
+ display: flex;
|
|
|
157
|
+ align-items: center;
|
|
|
158
|
+ justify-content: center;
|
|
|
159
|
+ box-sizing: border-box;
|
|
|
160
|
+}
|
|
|
161
|
+.close-wrap {
|
|
|
162
|
+ display: flex;
|
|
|
163
|
+ flex-direction: column;
|
|
|
164
|
+ align-items: center;
|
|
|
165
|
+ margin-top: 20rpx;
|
|
|
166
|
+ image {
|
|
|
167
|
+ width: 62rpx;
|
|
|
168
|
+ height: 62rpx;
|
|
|
169
|
+ margin: 46rpx 0 8rpx 0;
|
|
|
170
|
+ }
|
|
|
171
|
+ text {
|
|
|
172
|
+ font-size: 30rpx;
|
|
|
173
|
+ color: rgba(255, 255, 255, 0.76);
|
|
|
174
|
+ }
|
|
|
175
|
+}
|
|
|
176
|
+// 位置控制
|
|
|
177
|
+.hy-popup-position-center {
|
|
|
178
|
+ align-items: center;
|
|
|
179
|
+ justify-content: center;
|
|
|
180
|
+}
|
|
|
181
|
+
|
|
|
182
|
+.hy-popup-position-top {
|
|
|
183
|
+ align-items: flex-start;
|
|
|
184
|
+ justify-content: center;
|
|
|
185
|
+}
|
|
|
186
|
+
|
|
|
187
|
+.hy-popup-position-bottom {
|
|
|
188
|
+ align-items: flex-end;
|
|
|
189
|
+ justify-content: center;
|
|
|
190
|
+}
|
|
|
191
|
+
|
|
|
192
|
+.hy-popup-position-left {
|
|
|
193
|
+ align-items: center;
|
|
|
194
|
+ justify-content: flex-start;
|
|
|
195
|
+}
|
|
|
196
|
+
|
|
|
197
|
+.hy-popup-position-right {
|
|
|
198
|
+ align-items: center;
|
|
|
199
|
+ justify-content: flex-end;
|
|
|
200
|
+}
|
|
|
201
|
+
|
|
|
202
|
+.hy-popup-overlay {
|
|
|
203
|
+ position: absolute;
|
|
|
204
|
+ top: 0;
|
|
|
205
|
+ left: 0;
|
|
|
206
|
+ right: 0;
|
|
|
207
|
+ bottom: 0;
|
|
|
208
|
+}
|
|
|
209
|
+
|
|
|
210
|
+.hy-popup-content {
|
|
|
211
|
+ position: relative;
|
|
|
212
|
+ box-sizing: border-box;
|
|
|
213
|
+ overflow: hidden;
|
|
|
214
|
+ padding: 30rpx;
|
|
|
215
|
+}
|
|
|
216
|
+
|
|
|
217
|
+.hy-popup-no-padding {
|
|
|
218
|
+ padding: 0;
|
|
|
219
|
+}
|
|
|
220
|
+
|
|
|
221
|
+.hy-popup-close {
|
|
|
222
|
+ position: absolute;
|
|
|
223
|
+ top: 20rpx;
|
|
|
224
|
+ right: 20rpx;
|
|
|
225
|
+ width: 60rpx;
|
|
|
226
|
+ height: 60rpx;
|
|
|
227
|
+ display: flex;
|
|
|
228
|
+ align-items: center;
|
|
|
229
|
+ justify-content: center;
|
|
|
230
|
+ border-radius: 50%;
|
|
|
231
|
+ background-color: rgba(0, 0, 0, 0.1);
|
|
|
232
|
+ z-index: 10;
|
|
|
233
|
+}
|
|
|
234
|
+
|
|
|
235
|
+.hy-popup-close-icon {
|
|
|
236
|
+ font-size: 40rpx;
|
|
|
237
|
+ font-weight: bold;
|
|
|
238
|
+}
|
|
|
239
|
+
|
|
|
240
|
+// 通用过渡设置
|
|
|
241
|
+$transition-duration: 0.3s;
|
|
|
242
|
+$transition-timing: ease;
|
|
|
243
|
+
|
|
|
244
|
+// Scale 动画
|
|
|
245
|
+.hy-popup-scale-enter-active,
|
|
|
246
|
+.hy-popup-scale-leave-active {
|
|
|
247
|
+ transition: all $transition-duration $transition-timing;
|
|
|
248
|
+}
|
|
|
249
|
+
|
|
|
250
|
+.hy-popup-scale-enter-from .hy-popup-overlay,
|
|
|
251
|
+.hy-popup-scale-leave-to .hy-popup-overlay {
|
|
|
252
|
+ opacity: 0;
|
|
|
253
|
+}
|
|
|
254
|
+
|
|
|
255
|
+.hy-popup-scale-enter-from .hy-popup-content,
|
|
|
256
|
+.hy-popup-scale-leave-to .hy-popup-content {
|
|
|
257
|
+ transform: scale(0.8);
|
|
|
258
|
+ opacity: 0;
|
|
|
259
|
+}
|
|
|
260
|
+
|
|
|
261
|
+// Slide-up 动画
|
|
|
262
|
+.hy-popup-slide-up-enter-active,
|
|
|
263
|
+.hy-popup-slide-up-leave-active {
|
|
|
264
|
+ transition: all $transition-duration $transition-timing;
|
|
|
265
|
+}
|
|
|
266
|
+
|
|
|
267
|
+.hy-popup-slide-up-enter-from .hy-popup-overlay,
|
|
|
268
|
+.hy-popup-slide-up-leave-to .hy-popup-overlay {
|
|
|
269
|
+ opacity: 0;
|
|
|
270
|
+}
|
|
|
271
|
+
|
|
|
272
|
+.hy-popup-slide-up-enter-from .hy-popup-content {
|
|
|
273
|
+ transform: translateY(100%);
|
|
|
274
|
+ opacity: 0;
|
|
|
275
|
+}
|
|
|
276
|
+
|
|
|
277
|
+.hy-popup-slide-up-leave-to .hy-popup-content {
|
|
|
278
|
+ transform: translateY(100%);
|
|
|
279
|
+ opacity: 0;
|
|
|
280
|
+}
|
|
|
281
|
+
|
|
|
282
|
+// Slide-down 动画
|
|
|
283
|
+.hy-popup-slide-down-enter-active,
|
|
|
284
|
+.hy-popup-slide-down-leave-active {
|
|
|
285
|
+ transition: all $transition-duration $transition-timing;
|
|
|
286
|
+}
|
|
|
287
|
+
|
|
|
288
|
+.hy-popup-slide-down-enter-from .hy-popup-overlay,
|
|
|
289
|
+.hy-popup-slide-down-leave-to .hy-popup-overlay {
|
|
|
290
|
+ opacity: 0;
|
|
|
291
|
+}
|
|
|
292
|
+
|
|
|
293
|
+.hy-popup-slide-down-enter-from .hy-popup-content {
|
|
|
294
|
+ transform: translateY(-100%);
|
|
|
295
|
+ opacity: 0;
|
|
|
296
|
+}
|
|
|
297
|
+
|
|
|
298
|
+.hy-popup-slide-down-leave-to .hy-popup-content {
|
|
|
299
|
+ transform: translateY(-100%);
|
|
|
300
|
+ opacity: 0;
|
|
|
301
|
+}
|
|
|
302
|
+
|
|
|
303
|
+// Slide-left 动画
|
|
|
304
|
+.hy-popup-slide-left-enter-active,
|
|
|
305
|
+.hy-popup-slide-left-leave-active {
|
|
|
306
|
+ transition: all $transition-duration $transition-timing;
|
|
|
307
|
+}
|
|
|
308
|
+
|
|
|
309
|
+.hy-popup-slide-left-enter-from .hy-popup-overlay,
|
|
|
310
|
+.hy-popup-slide-left-leave-to .hy-popup-overlay {
|
|
|
311
|
+ opacity: 0;
|
|
|
312
|
+}
|
|
|
313
|
+
|
|
|
314
|
+.hy-popup-slide-left-enter-from .hy-popup-content {
|
|
|
315
|
+ transform: translateX(-100%);
|
|
|
316
|
+ opacity: 0;
|
|
|
317
|
+}
|
|
|
318
|
+
|
|
|
319
|
+.hy-popup-slide-left-leave-to .hy-popup-content {
|
|
|
320
|
+ transform: translateX(-100%);
|
|
|
321
|
+ opacity: 0;
|
|
|
322
|
+}
|
|
|
323
|
+
|
|
|
324
|
+// Slide-right 动画
|
|
|
325
|
+.hy-popup-slide-right-enter-active,
|
|
|
326
|
+.hy-popup-slide-right-leave-active {
|
|
|
327
|
+ transition: all $transition-duration $transition-timing;
|
|
|
328
|
+}
|
|
|
329
|
+
|
|
|
330
|
+.hy-popup-slide-right-enter-from .hy-popup-overlay,
|
|
|
331
|
+.hy-popup-slide-right-leave-to .hy-popup-overlay {
|
|
|
332
|
+ opacity: 0;
|
|
|
333
|
+}
|
|
|
334
|
+
|
|
|
335
|
+.hy-popup-slide-right-enter-from .hy-popup-content {
|
|
|
336
|
+ transform: translateX(100%);
|
|
|
337
|
+ opacity: 0;
|
|
|
338
|
+}
|
|
|
339
|
+
|
|
|
340
|
+.hy-popup-slide-right-leave-to .hy-popup-content {
|
|
|
341
|
+ transform: translateX(100%);
|
|
|
342
|
+ opacity: 0;
|
|
|
343
|
+}
|
|
|
344
|
+
|
|
|
345
|
+// Fade 动画
|
|
|
346
|
+.hy-popup-fade-enter-active,
|
|
|
347
|
+.hy-popup-fade-leave-active {
|
|
|
348
|
+ transition: all $transition-duration $transition-timing;
|
|
|
349
|
+}
|
|
|
350
|
+
|
|
|
351
|
+.hy-popup-fade-enter-from .hy-popup-overlay,
|
|
|
352
|
+.hy-popup-fade-leave-to .hy-popup-overlay {
|
|
|
353
|
+ opacity: 0;
|
|
|
354
|
+}
|
|
|
355
|
+
|
|
|
356
|
+.hy-popup-fade-enter-from .hy-popup-content,
|
|
|
357
|
+.hy-popup-fade-leave-to .hy-popup-content {
|
|
|
358
|
+ opacity: 0;
|
|
|
359
|
+}
|
|
|
360
|
+</style>
|