Skip to content

Commit 3cc1805

Browse files
fix: 🐛 修复 FloadingPanel 设置 height 不生效的问题 (#725)
Closes: #703
1 parent cd20581 commit 3cc1805

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/uni_modules/wot-design-uni/components/wd-floating-panel/wd-floating-panel.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ const touch = useTouch()
4545
const props = defineProps(floatingPanelProps)
4646
const emit = defineEmits(['update:height', 'height-change'])
4747
48+
const heightValue = ref<number>(props.height)
49+
4850
const DAMP = 0.2 // 阻尼系数
4951
let startY: number // 起始位置
50-
const height = ref<number>(props.height) // 当前高度
5152
const windowHeight = ref<number>(0)
5253
const dragging = ref<boolean>(false) // 是否正在拖拽
5354
@@ -61,17 +62,22 @@ const anchors = computed(() => (props.anchors.length >= 2 ? props.anchors : [bou
6162
const rootStyle = computed(() => {
6263
const style: CSSProperties = {
6364
height: addUnit(boundary.value.max),
64-
transform: `translateY(calc(100% + ${addUnit(-height.value)}))`,
65+
transform: `translateY(calc(100% + ${addUnit(-heightValue.value)}))`,
6566
transition: !dragging.value ? `transform ${props.duration}ms cubic-bezier(0.18, 0.89, 0.32, 1.28)` : 'none'
6667
}
6768
6869
return `${objToStyle(style)};${props.customStyle}`
6970
})
7071
72+
const updateHeight = (value: number) => {
73+
heightValue.value = value
74+
emit('update:height', value)
75+
}
76+
7177
const handleTouchStart = (event: TouchEvent) => {
7278
touch.touchStart(event)
7379
dragging.value = true
74-
startY = -height.value
80+
startY = -heightValue.value
7581
}
7682
7783
const handleTouchMove = (event: TouchEvent) => {
@@ -81,15 +87,15 @@ const handleTouchMove = (event: TouchEvent) => {
8187
}
8288
touch.touchMove(event)
8389
const moveY = touch.deltaY.value + startY
84-
height.value = -ease(moveY)
90+
updateHeight(-ease(moveY))
8591
}
8692
8793
const handleTouchEnd = () => {
8894
dragging.value = false
89-
height.value = closest(anchors.value, height.value)
95+
updateHeight(closest(anchors.value, heightValue.value))
9096
91-
if (height.value !== -startY) {
92-
emit('height-change', { height: height.value })
97+
if (heightValue.value !== -startY) {
98+
emit('height-change', { height: heightValue.value })
9399
}
94100
}
95101
@@ -109,16 +115,16 @@ const ease = (y: number) => {
109115
}
110116
111117
watch(
112-
() => height.value,
118+
() => props.height,
113119
(value) => {
114-
emit('update:height', value)
120+
heightValue.value = value
115121
}
116122
)
117123
118124
watch(
119125
boundary,
120126
() => {
121-
height.value = closest(anchors.value, height.value)
127+
updateHeight(closest(anchors.value, heightValue.value))
122128
},
123129
{ immediate: true }
124130
)

src/uni_modules/wot-design-uni/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ declare module 'vue' {
9191
WdIndexAnchor: typeof import('./components/wd-index-anchor/wd-index-anchor.vue')['default']
9292
WdText: typeof import('./components/wd-text/wd-text.vue')['default']
9393
WdCountTo: typeof import('./components/wd-count-to/wd-count-to.vue')['default']
94+
WdFloatingPanel: typeof import('./components/wd-floating-panel/wd-floating-panel.vue')['default']
9495
}
9596
}
9697

0 commit comments

Comments
 (0)