Skip to content

Commit df0346d

Browse files
committed
重构 popup 组件,添加动画效果
1 parent dfb05d4 commit df0346d

5 files changed

Lines changed: 251 additions & 240 deletions

File tree

‎components/uni-popup/uni-popup.vue‎

Lines changed: 112 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<template>
2-
<view>
3-
<view v-show="show" :style="{ top: offsetTop + 'px' }" class="uni-mask" @click="hide" @touchmove.stop.prevent="moveHandle" />
4-
<view v-show="show" :class="'uni-popup-' + position + ' ' + 'uni-popup-' + mode" class="uni-popup">
5-
{{ msg }}
6-
<slot />
7-
<view v-if="position === 'middle' && mode === 'insert'" :class="{
8-
'uni-close-bottom': buttonMode === 'bottom',
9-
'uni-close-right': buttonMode === 'right'
10-
}" class="uni-icon uni-icon-close" @click="closeMask" />
2+
<view v-if="show" class="uni-popup">
3+
<view :class="[ani, animation ? 'ani' : '', !custom ? 'uni-custom' : '']" class="uni-popup__mask" @click="close(true)" />
4+
<view :class="[type, ani, animation ? 'ani' : '', !custom ? 'uni-custom' : '']" class="uni-popup__wrapper" @click="close(true)">
5+
<view class="uni-popup__wrapper-box" @click.stop="clear">
6+
<slot />
7+
</view>
118
</view>
129
</view>
1310
</template>
@@ -16,181 +13,156 @@
1613
export default {
1714
name: 'UniPopup',
1815
props: {
19-
/**
20-
* 页面显示
21-
*/
22-
show: {
16+
// 开启动画
17+
animation: {
2318
type: Boolean,
24-
default: false
25-
},
26-
/**
27-
* 对齐方式
28-
*/
29-
position: {
30-
type: String,
31-
// top - 顶部, middle - 居中, bottom - 底部
32-
default: 'middle'
33-
},
34-
/**
35-
* 显示模式
36-
*/
37-
mode: {
38-
type: String,
39-
default: 'insert'
19+
default: true
4020
},
41-
/**
42-
* 额外信息
43-
*/
44-
msg: {
21+
// 弹出层类型,可选值,top: 顶部弹出层;bottom:底部弹出层;center:全屏弹出层
22+
type: {
4523
type: String,
46-
default: ''
24+
default: 'center'
4725
},
48-
/**
49-
* h5遮罩是否到顶
50-
*/
51-
h5Top: {
26+
// 是否开启自定义
27+
custom: {
5228
type: Boolean,
5329
default: false
5430
},
55-
buttonMode: {
56-
type: String,
57-
default: 'bottom'
31+
// maskClick
32+
maskClick: {
33+
type: Boolean,
34+
default: true
5835
}
5936
},
6037
data() {
6138
return {
62-
offsetTop: 0
39+
ani: '',
40+
show: false
6341
}
6442
},
65-
watch: {
66-
h5Top(newVal) {
67-
if (newVal) {
68-
this.offsetTop = 44
69-
} else {
70-
this.offsetTop = 0
71-
}
72-
}
73-
},
74-
created() {
75-
let offsetTop = 0
76-
// #ifdef H5
77-
if (!this.h5Top) {
78-
offsetTop = 44
79-
} else {
80-
offsetTop = 0
81-
}
82-
// #endif
83-
this.offsetTop = offsetTop
84-
},
43+
created() {},
8544
methods: {
86-
hide() {
87-
if (this.mode === 'insert' && this.position === 'middle') return
88-
this.$emit('hidePopup')
89-
},
90-
closeMask() {
91-
if (this.mode === 'insert') {
92-
this.$emit('hidePopup')
93-
}
45+
clear() {},
46+
open() {
47+
this.show = true
48+
this.$nextTick(() => {
49+
setTimeout(() => {
50+
this.ani = 'uni-' + this.type
51+
}, 30)
52+
})
9453
},
95-
moveHandle() {}
54+
close(type) {
55+
if (!this.maskClick && type) return
56+
this.ani = ''
57+
this.$nextTick(() => {
58+
setTimeout(() => {
59+
this.show = false
60+
}, 300)
61+
})
62+
}
9663
}
9764
}
9865
</script>
9966
<style>
100-
.uni-mask {
67+
@charset "UTF-8";
68+
69+
.uni-popup {
10170
position: fixed;
102-
z-index: 998;
71+
top: 50px;
10372
top: 0;
73+
bottom: 0;
74+
left: 0;
10475
right: 0;
76+
z-index: 999;
77+
overflow: hidden
78+
}
79+
80+
.uni-popup__mask {
81+
position: absolute;
82+
top: 0;
10583
bottom: 0;
10684
left: 0;
107-
background-color: rgba(0, 0, 0, 0.3);
85+
right: 0;
86+
z-index: 998;
87+
background: rgba(0, 0, 0, .4);
88+
opacity: 0
10889
}
10990
110-
.uni-popup {
91+
.uni-popup__mask.ani {
92+
transition: all .3s
93+
}
94+
95+
.uni-popup__mask.uni-bottom,
96+
.uni-popup__mask.uni-center,
97+
.uni-popup__mask.uni-top {
98+
opacity: 1
99+
}
100+
101+
.uni-popup__wrapper {
111102
position: absolute;
112103
z-index: 999;
113-
background-color: #ffffff;
104+
box-sizing: border-box
114105
}
115106
116-
.uni-popup-middle {
117-
display: flex;
118-
flex-direction: column;
119-
align-items: center;
120-
justify-content: center;
121-
top: 50%;
122-
left: 50%;
123-
transform: translate(-50%, -50%);
107+
.uni-popup__wrapper.ani {
108+
transition: all .3s
124109
}
125110
126-
.uni-popup-middle.uni-popup-insert {
127-
min-width: 380upx;
128-
min-height: 380upx;
129-
max-width: 100%;
130-
max-height: 80%;
131-
transform: translate(-50%, -65%);
132-
background: none;
133-
box-shadow: none;
111+
.uni-popup__wrapper.top {
112+
top: 0;
113+
left: 0;
114+
width: 100%;
115+
transform: translateY(-100%)
134116
}
135117
136-
.uni-popup-middle.uni-popup-fixed {
137-
border-radius: 10upx;
138-
padding: 30upx;
118+
.uni-popup__wrapper.bottom {
119+
bottom: 0;
120+
left: 0;
121+
width: 100%;
122+
transform: translateY(100%)
139123
}
140124
141-
.uni-close-bottom,
142-
.uni-close-right {
143-
position: absolute;
144-
bottom: -180upx;
145-
text-align: center;
146-
border-radius: 50%;
147-
color: #f5f5f5;
148-
font-size: 60upx;
149-
font-weight: bold;
150-
opacity: 0.8;
151-
z-index: -1;
152-
}
153-
154-
.uni-close-bottom {
155-
margin: auto;
156-
left: 0;
157-
right: 0;
158-
width: 28px;
159-
height: 28px;
125+
.uni-popup__wrapper.center {
126+
width: 100%;
127+
height: 100%;
128+
display: flex;
129+
justify-content: center;
130+
align-items: center;
131+
transform: scale(1.2);
132+
opacity: 0
160133
}
161134
162-
.uni-close-right {
163-
right: -60upx;
164-
top: -80upx;
135+
.uni-popup__wrapper-box {
136+
position: relative;
137+
box-sizing: border-box
165138
}
166139
167-
.uni-close-bottom:after {
168-
content: '';
169-
position: absolute;
170-
width: 0px;
171-
border: 1px #f5f5f5 solid;
172-
top: -200upx;
173-
bottom: 56upx;
174-
left: 50%;
175-
transform: translate(-50%, -0%);
176-
opacity: 0.8;
140+
.uni-popup__wrapper.uni-custom .uni-popup__wrapper-box {
141+
padding: 30upx;
142+
background: #fff
177143
}
178144
179-
.uni-popup-top {
180-
top: 0;
181-
left: 0;
182-
width: 100%;
183-
height: 100upx;
184-
line-height: 100upx;
185-
text-align: center;
145+
.uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
146+
position: relative;
147+
max-width: 80%;
148+
max-height: 80%;
149+
overflow-y: scroll
186150
}
187151
188-
.uni-popup-bottom {
189-
left: 0;
190-
bottom: 0;
152+
.uni-popup__wrapper.uni-custom.bottom .uni-popup__wrapper-box,
153+
.uni-popup__wrapper.uni-custom.top .uni-popup__wrapper-box {
191154
width: 100%;
192-
min-height: 100upx;
193-
line-height: 100upx;
194-
text-align: center;
155+
max-height: 500px;
156+
overflow-y: scroll
157+
}
158+
159+
.uni-popup__wrapper.uni-bottom,
160+
.uni-popup__wrapper.uni-top {
161+
transform: translateY(0)
162+
}
163+
164+
.uni-popup__wrapper.uni-center {
165+
transform: scale(1);
166+
opacity: 1
195167
}
196168
</style>

‎pages.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
"bounce": "none",
351351
"pullToRefresh": {
352352
"style": "circle",
353-
"offset": "50px"
353+
"offset": "70px"
354354
}
355355
}
356356
}

‎pages/extUI/nav-bar/nav-bar.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<view>
3-
<uni-nav-bar left-icon="arrowleft" left-text="返回" title="标题" @click-left="back" :statusBar="true" />
3+
<uni-nav-bar :status-bar="true" left-icon="arrowleft" left-text="返回" title="标题" @click-left="back" />
44
<view class="example-info">
55
本导航栏为自定义组件,并非原生导航栏。除非原生导航栏无法满足需求,否则不推荐使用自定义导航栏组件。具体参考https://ask.dcloud.net.cn/article/34921
66
</view>

0 commit comments

Comments
 (0)