Skip to content

Commit 0dd34d0

Browse files
feat: ✨ 使用Transition重构Popup为center类型的Popup添加zoom-in动画 (#699)
* feat: ✨ 使用Transition重构Popup为center类型的Popup添加zoom-in动画 ✅ Closes: #687 * fix: 🐛 修复 Transition 动画类名重复的问题
1 parent 5e55da4 commit 0dd34d0

File tree

11 files changed

+267
-270
lines changed

11 files changed

+267
-270
lines changed

docs/component/popup.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@
88
`v-model` 为绑定值,表示是否展示弹出层。
99

1010
```html
11-
<wd-popup v-model="show" custom-style="padding: 30px 40px;" @close="handleClose">内容</wd-popup>
11+
<wd-popup v-model="show" custom-style="border-radius:32rpx;" @close="handleClose">
12+
<text class="custom-txt">弹弹弹</text>
13+
</wd-popup>
14+
```
15+
```css
16+
.custom-txt {
17+
color: black;
18+
width: 400rpx;
19+
height: 400rpx;
20+
display: flex;
21+
justify-content: center;
22+
align-items: center;
23+
font-size: 40rpx;
24+
border-radius: 32rpx;
25+
}
1226
```
1327

1428
## 弹出位置
@@ -89,6 +103,7 @@ h5 滚动穿透不需要处理,组件已默认开启 `lock-scroll`。
89103
| hide-when-close | 是否当关闭时将弹出层隐藏(display: none) | boolean | - | true | - |
90104
| lazy-render | 弹层内容懒渲染,触发展示时才渲染内容 | boolean | - | true | - |
91105
| safe-area-inset-bottom | 弹出面板是否设置底部安全距离(iphone X 类型的机型) | boolean | - | false | - |
106+
| transition | 动画类型,参见 wd-transition 组件的name | string | fade / fade-up / fade-down / fade-left / fade-right / slide-up / slide-down / slide-left / slide-right / zoom-in | - | - |
92107
| lockScroll | 是否锁定背景滚动 | boolean | - | true | 0.1.30 |
93108

94109
## Events

src/App.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<!--
2+
* @Author: weisheng
3+
* @Date: 2024-10-12 13:07:08
4+
* @LastEditTime: 2024-11-08 13:14:48
5+
* @LastEditors: weisheng
6+
* @Description:
7+
* @FilePath: \wot-design-uni\src\App.vue
8+
* 记得注释
9+
-->
110
<script setup lang="ts">
211
import { onLaunch, onShow, onHide, onThemeChange } from '@dcloudio/uni-app'
312
import { useDark } from './store'
@@ -7,7 +16,7 @@ onThemeChange((option) => {
716
darkMode.setDark(option.theme === 'dark')
817
})
918
10-
onLaunch((ctx) => {
19+
onLaunch(() => {
1120
const systemInfo = uni.getSystemInfoSync()
1221
darkMode.setDark(systemInfo.theme === 'dark')
1322
@@ -18,8 +27,6 @@ onLaunch((ctx) => {
1827
// 处理收到的消息
1928
if (typeof event.data === 'boolean') {
2029
darkMode.setDark(event.data)
21-
} else {
22-
darkMode.setDark(false)
2330
}
2431
})
2532
// #endif

src/pages/popup/Index.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
</wd-cell-group>
4646
</demo-block>
4747

48-
<wd-popup v-model="show1" custom-style="padding: 30px 40px;" @close="handleClose1"><text class="custom-txt">内容</text></wd-popup>
48+
<wd-popup v-model="show1" @close="handleClose1" custom-style="border-radius:32rpx;">
49+
<text class="custom-txt">弹弹弹</text>
50+
</wd-popup>
4951
<wd-popup v-model="show2" position="top" custom-style="height: 200px;" @close="handleClose2"></wd-popup>
5052
<wd-popup v-model="show3" position="right" custom-style="width: 200px;" @close="handleClose3"></wd-popup>
5153
<wd-popup v-model="show4" position="bottom" custom-style="height: 200px;" @close="handleClose4"></wd-popup>
@@ -168,5 +170,12 @@ function handleClose10() {
168170
169171
.custom-txt {
170172
color: black;
173+
width: 400rpx;
174+
height: 400rpx;
175+
display: flex;
176+
justify-content: center;
177+
align-items: center;
178+
font-size: 40rpx;
179+
border-radius: 32rpx;
171180
}
172181
</style>

src/pages/transition/Index.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</demo-block>
1717
<demo-block title="Zoom 动画">
1818
<wd-button @click="zoomIn">zoom-in</wd-button>
19+
<wd-button @click="zoomOut">zoom-out</wd-button>
1920
</demo-block>
2021
<demo-block title="自定义动画">
2122
<wd-button @click="custom">custom</wd-button>
@@ -25,7 +26,6 @@
2526

2627
<wd-transition
2728
:show="customShow"
28-
name=""
2929
:duration="{ enter: 700, leave: 1000 }"
3030
enter-class="custom-enter"
3131
enter-active-class="custom-enter-active"
@@ -39,10 +39,11 @@
3939
</view>
4040
</template>
4141
<script lang="ts" setup>
42+
import type { TransitionName } from '@/uni_modules/wot-design-uni/components/wd-transition/types'
4243
import { ref } from 'vue'
4344
4445
const show = ref<boolean>(false)
45-
const name = ref<any>('')
46+
const name = ref<TransitionName>()
4647
const customShow = ref<boolean>(false)
4748
function fade() {
4849
transition('fade')
@@ -74,13 +75,16 @@ function slideRight() {
7475
function zoomIn() {
7576
transition('zoom-in')
7677
}
78+
function zoomOut() {
79+
transition('zoom-out')
80+
}
7781
function custom() {
7882
customShow.value = true
7983
setTimeout(() => {
8084
customShow.value = false
8185
}, 1200)
8286
}
83-
function transition(transition: string) {
87+
function transition(transition: TransitionName) {
8488
name.value = transition
8589
show.value = true
8690
setTimeout(() => {

src/uni_modules/wot-design-uni/components/common/abstracts/_mixin.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@
103103
}
104104
}
105105

106+
/* 定义状态(m) */
107+
@mixin mdeep($modifier...) {
108+
$selectors: "";
109+
110+
@each $item in $modifier {
111+
$selectors: #{$selectors + & + $modifierSeparator + $item + ","};
112+
}
113+
114+
@at-root {
115+
:deep() {
116+
#{$selectors} {
117+
@content;
118+
}
119+
}
120+
}
121+
}
122+
106123
/* 对于需要需要嵌套在 m 底下的 e,调用这个混合宏,一般在切换整个组件的状态,如切换颜色的时候 */
107124
@mixin me($element...) {
108125
$selector: &;
Lines changed: 40 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
@import './../common/abstracts/_mixin.scss';
22
@import './../common/abstracts/variable.scss';
3-
@import '../wd-overlay/index.scss';
43

54
.wot-theme-dark {
6-
@include b(popup) {
7-
background: $-dark-background2;
5+
@include b(popup-wrapper) {
6+
:deep() {
7+
.wd-popup {
8+
background: $-dark-background2;
9+
}
10+
11+
.wd-popup__close {
12+
color: $-dark-color;
13+
}
14+
}
15+
}
16+
}
817

9-
@include e(close) {
10-
color: $-dark-color;
18+
@include b(popup-wrapper) {
19+
:deep() {
20+
.wd-popup {
21+
position: fixed;
22+
max-height: 100%;
23+
overflow-y: auto;
24+
background: #fff;
1125
}
1226
}
1327
}
1428

15-
@include b(popup) {
16-
position: fixed;
17-
max-height: 100%;
18-
overflow-y: auto;
19-
background: #fff;
2029

30+
@include b(popup) {
2131
@include edeep(close) {
2232
position: absolute;
2333
top: 10px;
@@ -27,86 +37,48 @@
2737
transform: rotate(-45deg);
2838
}
2939

30-
@include m(center) {
40+
@include mdeep(center) {
3141
left: 50%;
3242
top: 50%;
3343
transform: translate3d(-50%, -50%, 0);
44+
transform-origin: 0% 0%;
45+
46+
&.wd-zoom-in-enter,
47+
&.wd-zoom-in-leave-to {
48+
transform: scale(0.8) translate3d(-50%, -50%, 0) !important;
49+
}
50+
51+
@include when(deep) {
52+
53+
&.wd-zoom-in-enter,
54+
&.wd-zoom-in-leave-to {
55+
transform: scale(0.1) translate3d(-50%, -50%, 0) !important;
56+
}
57+
}
58+
3459
}
3560

36-
@include m(left) {
61+
@include mdeep(left) {
3762
top: 0;
3863
bottom: 0;
3964
left: 0;
4065
}
4166

42-
@include m(right) {
67+
@include mdeep(right) {
4368
top: 0;
4469
right: 0;
4570
bottom: 0;
4671
}
4772

48-
@include m(top) {
73+
@include mdeep(top) {
4974
top: 0;
5075
left: 0;
5176
right: 0;
5277
}
5378

54-
@include m(bottom) {
79+
@include mdeep(bottom) {
5580
right: 0;
5681
bottom: 0;
5782
left: 0;
5883
}
59-
}
60-
61-
.wd-center-enter-active,
62-
.wd-center-leave-active {
63-
transition-property: opacity;
64-
}
65-
66-
.wd-center-enter,
67-
.wd-center-leave-to {
68-
opacity: 0;
69-
}
70-
71-
.wd-top-enter-active,
72-
.wd-top-leave-active,
73-
.wd-bottom-enter-active,
74-
.wd-bottom-leave-active,
75-
.wd-left-enter-active,
76-
.wd-left-leave-active,
77-
.wd-right-enter-active,
78-
.wd-right-enter-active {
79-
transition-property: transform;
80-
}
81-
82-
.wd-top-enter,
83-
.wd-top-leave-to {
84-
transform: translate3d(0, -100%, 0);
85-
}
86-
87-
.wd-bottom-enter,
88-
.wd-bottom-leave-to {
89-
transform: translate3d(0, 100%, 0);
90-
}
91-
92-
.wd-left-enter,
93-
.wd-left-leave-to {
94-
transform: translate3d(-100%, 0, 0);
95-
}
96-
97-
.wd-right-enter,
98-
.wd-right-leave-to {
99-
transform: translate3d(100%, 0, 0);
100-
}
101-
102-
.wd-zoom-in-enter-active,
103-
.wd-zoom-in-leave-active {
104-
transition-property: opacity, transform;
105-
transform-origin: center center;
106-
}
107-
108-
.wd-zoom-in-enter,
109-
.wd-zoom-in-leave-to {
110-
opacity: 0;
111-
transform: translate3d(-50%, -50%, 0) scale(0.7);
11284
}

0 commit comments

Comments
 (0)