modal.js
3.91 KB
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
Component({
/**
* 组件的属性列表(共有数据)
*/
properties: {
//modal出现动画类型
fadeStyle: {
type: String,
value: '',
observer(newVal, oldVal, changedPath) {
// 属性被改变时执行的函数(可选),通常 newVal 就是新设置的数据, oldVal 是旧数
if (newVal == "slideUp") { //从下向上滑出
this.setData({
bottom: '-' + this.properties.height,
})
} else if (newVal == "slideDown") { //从上向下滑出
this.setData({
top: '-' + this.properties.height,
})
} else if (newVal == "slideRight") { //从左向右滑出
this.setData({
left: '-' + this.properties.width
})
} else if (newVal == "slideLeft") { //从右向左滑出
this.setData({
right: '-' + this.properties.width
})
} else if (newVal == "center") { //中间
this.setData({
right: '10%',
left: '10%',
top: '20%',
})
}
}
},
width: {
type: String,
value: '100%',
},
height: {
type: String,
value: '',
},
top: {
type: String,
value: ''
},
bottom: {
type: String,
value: ''
},
left: {
type: String,
value: ''
},
right: {
type: String,
value: ''
},
opacity: {
type: String,
value: '0'
},
},
/**
* 组件的初始数据(私有数据)
*/
data: {
//控制模态框打开关闭参数
showModalStatus: false
},
options: {
addGlobalClass: true, //使其可以使用全局样式
multipleSlots: true //使其可以使用多个slot,用name区分
},
/**
* 组件的方法列表
*/
methods: {
//打开模态框
showModal: function (event) {
this.setData({
showModalStatus: true
})
//需要等模态框出现再执行动画,否则无动画效果
setTimeout(function () {
if (this.properties.fadeStyle == "slideUp") {
this.setData({
bottom: 0,
opacity: 1
})
} else if (this.properties.fadeStyle == "slideDown") {
this.setData({
top: 0,
opacity: 1
})
} else if (this.properties.fadeStyle == "slideRight") {
this.setData({
left: 0,
opacity: 1
})
} else if (this.properties.fadeStyle == "slideLeft") {
this.setData({
right: 0,
opacity: 1
})
} else if (this.properties.fadeStyle == "center") {
this.setData({
right: '10%',
left: '10%',
top: '20%',
opacity: 1
})
}
}.bind(this), 100)
},
//关闭模态框
closeModal: function () {
//判断动画样式
if (this.properties.fadeStyle == "slideUp") {
this.setData({
bottom: '-' + this.properties.height,
opacity: 0
})
} else if (this.properties.fadeStyle == "slideDown") {
this.setData({
top: '-' + this.properties.height,
opacity: 0
})
} else if (this.properties.fadeStyle == "slideRight") {
this.setData({
left: '-' + this.properties.width,
opacity: 0
})
} else if (this.properties.fadeStyle == "slideLeft") {
this.setData({
right: '-' + this.properties.width,
opacity: 0
})
} else if (this.properties.fadeStyle == "center") {
this.setData({
right: '10%',
left: '10%',
top: '20%',
opacity: 0
})
}
//等关闭动画完毕后再移除模态框和遮罩
setTimeout(function () {
this.setData({
showModalStatus: false
})
}.bind(this), 400)
}
}
})