Skip to content

Commit f3ccf3d

Browse files
fix: 🐛 修复 Overlay 组件锁定背景滚动属性 lock-scroll 无法取消的问题 (#1149)
1 parent ed923ec commit f3ccf3d

7 files changed

Lines changed: 103 additions & 29 deletions

File tree

‎docs/component/overlay.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
| ----------- | ------------------ | ----------------- | ------ | ------ | -------- |
4646
| show | 是否展示遮罩层 | `boolean` | true | false | - |
4747
| duration | 动画时长,单位毫秒 | `string / number` | - | 300 | - |
48-
| lockScroll | 是否锁定滚动 | `boolean` | false | true | - |
48+
| lockScroll | 是否锁定背景滚动,锁定时蒙层里的内容也将无法滚动 | `boolean` | false | true | - |
4949
| zIndex | 层级 | `number` | - | 10 | - |
5050
| customStyle | 自定义样式 | `string` | - | - | - |

‎docs/component/transition.md‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,30 @@
7474

7575
## Attributes
7676

77-
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
78-
| ------------ | ------------ | ---------------- | ---------------------------------------------------------------------------------------------------------------- | ------- | -------- |
79-
| show | 是否展示组件 | boolean | - | - | - |
80-
| name | 动画类型 | string | fade / fade-up / fade-down / fade-left / fade-right / slide-up / slide-down / slide-left / slide-right / zoom-in | - | - |
81-
| duration | 动画执行时间 | number / boolean | - | 300(ms) | - |
82-
| custom-style | 自定义样式 | string | - | - | - |
77+
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
78+
|--------------|--------------|------------------|----------------|---------|----------|
79+
| show | 是否展示组件 | boolean | - | - | - |
80+
| name | 动画类型 | string | `TransitionName` | - | - |
81+
| duration | 动画执行时间 | number / boolean | - | 300(ms) | - |
82+
| custom-style | 自定义样式 | string | - | - | - |
83+
| disable-touch-move | 是否阻止触摸滚动 | boolean | - | false | $LOWEST_VERSION$ |
84+
85+
### TransitionName 动画类型
86+
87+
| 名称 | 说明 | 最低版本 |
88+
|-------------|--------------|----------|
89+
| fade | 淡入淡出 | - |
90+
| fade-down | 向下淡入淡出 | - |
91+
| fade-left | 向左淡入淡出 | - |
92+
| fade-right | 向右淡入淡出 | - |
93+
| fade-up | 向上淡入淡出 | - |
94+
| slide-down | 向下滑动 | - |
95+
| slide-left | 向左滑动 | - |
96+
| slide-right | 向右滑动 | - |
97+
| slide-up | 向上滑动 | - |
98+
| zoom-in | 缩放进入 | - |
99+
| zoom-out | 缩放离开 | - |
100+
83101

84102
## Events
85103

‎docs/en-US/component/transition.md‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,31 @@ When the animation leaves, the tag will be set with `leave-class` and `leave-act
7272
}
7373
```
7474

75-
## Attributes
76-
77-
| Parameter | Description | Type | Options | Default | Version |
78-
|-----------|-------------|------|----------|---------|----------|
79-
| show | Whether to display component | boolean | - | - | - |
80-
| name | Animation type | string | fade / fade-up / fade-down / fade-left / fade-right / slide-up / slide-down / slide-left / slide-right / zoom-in | - | - |
81-
| duration | Animation execution time | number / boolean | - | 300(ms) | - |
82-
| custom-style | Custom style | string | - | - | - |
75+
## Attributes
76+
77+
| Parameter | Description | Type | Optional Values | Default Value | Minimum Version |
78+
|--------------------|------------------------------------|------------------|------------------|---------------|------------------|
79+
| show | Whether to display the component | boolean | - | - | - |
80+
| name | Animation type | string | `TransitionName` | - | - |
81+
| duration | Animation duration | number / boolean | - | 300(ms) | - |
82+
| custom-style | Custom styles | string | - | - | - |
83+
| disable-touch-move | Whether to prevent touch scrolling | boolean | - | false | $LOWEST_VERSION$ |
84+
85+
### TransitionName Animation Types
86+
87+
| Name | Description | Minimum Version |
88+
|-------------|-----------------|-----------------|
89+
| fade | Fade in and out | - |
90+
| fade-down | Fade down | - |
91+
| fade-left | Fade left | - |
92+
| fade-right | Fade right | - |
93+
| fade-up | Fade up | - |
94+
| slide-down | Slide down | - |
95+
| slide-left | Slide left | - |
96+
| slide-right | Slide right | - |
97+
| slide-up | Slide up | - |
98+
| zoom-in | Zoom in | - |
99+
| zoom-out | Zoom out | - |
83100

84101
## Events
85102

‎src/subPages/overlay/Index.vue‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212
</page-wraper>
1313
<wd-overlay :show="show" @click="show = false" />
1414

15-
<wd-overlay :show="show1" @click="show1 = false">
15+
<wd-overlay :show="show1" @click="show1 = false" :lock-scroll="lockScroll">
1616
<view class="wrapper">
17-
<view class="block" @click.stop="" />
17+
<view class="content" @click.stop="">
18+
<demo-block title="是否锁定背景滚动,锁定时蒙层里的内容也将无法滚动" transparent>
19+
<wd-switch v-model="lockScroll" size="22px" />
20+
</demo-block>
21+
<view class="scroll">
22+
<view class="block" v-for="i in 10" :key="i" @click.stop="">{{ i }}</view>
23+
</view>
24+
</view>
1825
</view>
1926
</wd-overlay>
2027
</view>
@@ -24,21 +31,33 @@ import { ref } from 'vue'
2431
2532
const show = ref<boolean>(false)
2633
const show1 = ref<boolean>(false)
34+
const lockScroll = ref<boolean>(true)
2735
</script>
2836
<style lang="scss" scoped>
29-
.wot-theme-dark {
30-
}
31-
3237
.wrapper {
3338
display: flex;
39+
flex-direction: column;
3440
align-items: center;
3541
justify-content: center;
3642
height: 100%;
3743
}
3844
45+
.content {
46+
background-color: #fff;
47+
border-radius: 12px;
48+
}
49+
50+
.scroll {
51+
height: 50vh;
52+
overflow-y: auto;
53+
width: 300px;
54+
}
55+
3956
.block {
40-
width: 120px;
57+
width: 100%;
4158
height: 120px;
42-
background-color: #fff;
59+
display: flex;
60+
align-items: center;
61+
justify-content: center;
4362
}
4463
</style>

‎src/uni_modules/wot-design-uni/components/wd-overlay/wd-overlay.vue‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
custom-class="wd-overlay"
66
:duration="duration"
77
:custom-style="`z-index: ${zIndex}; ${customStyle}`"
8+
:disable-touch-move="lockScroll"
89
@click="handleClick"
9-
@touchmove.stop.prevent="lockScroll ? noop : ''"
1010
>
1111
<slot></slot>
1212
</wd-transition>
@@ -37,8 +37,6 @@ function handleClick() {
3737
emit('click')
3838
}
3939
40-
function noop() {}
41-
4240
// #ifdef H5
4341
useLockScroll(() => props.show && props.lockScroll)
4442
// #endif

‎src/uni_modules/wot-design-uni/components/wd-transition/types.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
* @Author: weisheng
33
* @Date: 2024-09-01 15:42:04
4-
* @LastEditTime: 2024-11-06 23:50:08
4+
* @LastEditTime: 2025-07-04 18:33:43
55
* @LastEditors: weisheng
66
* @Description:
7-
* @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-transition\types.ts
7+
* @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/wd-transition/types.ts
88
* 记得注释
99
*/
1010
import type { ExtractPropTypes, PropType } from 'vue'
@@ -95,7 +95,13 @@ export const transitionProps = {
9595
* 离开过渡的结束状态
9696
* 类型:string
9797
*/
98-
leaveToClass: makeStringProp('')
98+
leaveToClass: makeStringProp(''),
99+
/**
100+
* 是否阻止触摸滚动
101+
* 类型:boolean
102+
* 默认值:false
103+
*/
104+
disableTouchMove: makeBooleanProp(false)
99105
}
100106

101107
export type TransitionProps = ExtractPropTypes<typeof transitionProps>

‎src/uni_modules/wot-design-uni/components/wd-transition/wd-transition.vue‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<template>
2-
<view v-if="!lazyRender || inited" :class="rootClass" :style="style" @transitionend="onTransitionEnd" @click="handleClick">
2+
<view
3+
:class="rootClass"
4+
:style="style"
5+
@transitionend="onTransitionEnd"
6+
@click="handleClick"
7+
@touchmove.stop.prevent="noop"
8+
v-if="isShow && disableTouchMove"
9+
>
10+
<slot />
11+
</view>
12+
<view :class="rootClass" :style="style" @transitionend="onTransitionEnd" @click="handleClick" v-else-if="isShow && !disableTouchMove">
313
<slot />
414
</view>
515
</template>
@@ -82,6 +92,10 @@ const rootClass = computed(() => {
8292
return `wd-transition ${props.customClass} ${classes.value}`
8393
})
8494
95+
const isShow = computed(() => {
96+
return !props.lazyRender || inited.value
97+
})
98+
8599
onBeforeMount(() => {
86100
if (props.show) {
87101
enter()
@@ -210,6 +224,8 @@ function onTransitionEnd() {
210224
display.value = false
211225
}
212226
}
227+
228+
function noop() {}
213229
</script>
214230
<style lang="scss" scoped>
215231
@import './index.scss';

0 commit comments

Comments
 (0)