/
animatedAlertView.wpy
128 lines (126 loc) · 2.73 KB
/
animatedAlertView.wpy
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
<template>
<div>
<div @tap.stop="hideAlert" v-if="isShow" class="mask"></div>
<!-- :style="pannelBorderRadius"竟然没有Vue的绑定style语法 -->
<div class="pannel" :animation="animationData" :class="{radius: radius}">
<div class="title-wrapper">
<div class="title">{{ title }}</div>
<div class="closeBtn" @tap="hideAlert">
<!-- <img alt="" /> -->
</div>
</div>
<div class="slot-wrapper">
<slot></slot>
</div>
</div>
</div>
</template>
<script>
import wepy from "@wepy/core"
wepy.component({
props: {
isShow: {
type: Boolean,
default: false,
required: true
},
title: {
type: String,
default: '',
required: false
},
radius: {
type: Boolean,
default: false,
required: false
}
},
methods: {
hideAlert() {
console.log('点击背景')
this.$emit('closeAlertView', 1, 2, 3)
}
},
data: {
animationData: {}
},
created() {
console.log('创建了alertView组件')
let animation = wx.createAnimation({
duration: 300,
timingFunction: 'ease'
})
this.animation = animation
},
computed: {
pannelBorderRadius() {
return {
borderRadius: `${this.radius}rpx ${this.radius}rpx 0 0`
}
}
},
watch: {
isShow(newValue) {
console.log('isShow变化了,' + newValue)
if (!newValue) {
this.animation.bottom('-100%').step()
} else {
this.animation.bottom('0').step()
}
this.animationData = this.animation.export()
}
}
})
</script>
<style lang="less">
.mask {
width: 100vw;
height: 100vh;
position: fixed;
z-index: 100;
left: 0;
top: 0;
background: rgba(0, 0, 0, 0.6);
}
.pannel {
position: fixed;
bottom: -100%;
width: 100%;
min-height: 400rpx;
z-index: 101;
background-color: #fff;
&.radius {
border-radius: 30rpx 30rpx 0 0;
}
.title-wrapper {
width: 100%;
height: 100rpx;
display: flex;
justify-content: center;
align-items: center;
position: relative;
border-bottom: solid 2rpx rgba(0, 0, 0, 0.1);
.title {
font-size: 36rpx;
color: #000;
text-align: center;
}
.closeBtn {
position: absolute;
top: 38rpx;
right: 38rpx;
font-size: 0;
width: 45rpx;
height: 45rpx;
display: flex;
justify-content: center;
align-items: center;
background-color: red;
image {
width: 24rpx;
height: 24rpx;
}
}
}
}
</style>