From 4bf0601fbc7997ea82c1593dc1e0554ab019e4a8 Mon Sep 17 00:00:00 2001 From: Belen Date: Thu, 31 Oct 2024 15:11:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DSlider=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=8B=96=E6=8B=BD=E6=97=B6=EF=BC=8C=E5=9C=A8=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E7=AB=AF=E6=97=A0=E6=95=88=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/slider/slider-button.vue | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/web-vue/components/slider/slider-button.vue b/packages/web-vue/components/slider/slider-button.vue index f14805d57..e5c094efc 100644 --- a/packages/web-vue/components/slider/slider-button.vue +++ b/packages/web-vue/components/slider/slider-button.vue @@ -15,6 +15,8 @@ :aria-valuetext="tooltipContent" :class="cls" @mousedown="handleMouseDown" + @touchstart="handleMouseDown" + @contextmenu.prevent @click.stop /> @@ -67,28 +69,39 @@ export default defineComponent({ const prefixCls = getPrefixCls('slider-btn'); const isDragging = ref(false); - const handleMouseDown = (e: MouseEvent) => { + const handleMouseDown = (e: MouseEvent | TouchEvent) => { if (props.disabled) { return; } - e.preventDefault(); isDragging.value = true; on(window, 'mousemove', handleMouseMove); + on(window, 'touchmove', handleMouseMove); on(window, 'mouseup', handleMouseUp); on(window, 'contextmenu', handleMouseUp); + on(window, 'touchend', handleMouseUp); emit('movestart'); }; - const handleMouseMove = (e: MouseEvent) => { - emit('moving', e.clientX, e.clientY); + const handleMouseMove = (e: MouseEvent | TouchEvent) => { + let clientX: number; + let clientY: number; + if (e.type.startsWith('touch')) { + clientY = (e as TouchEvent).touches[0].clientY; + clientX = (e as TouchEvent).touches[0].clientX; + } else { + clientY = (e as MouseEvent).clientY; + clientX = (e as MouseEvent).clientX; + } + emit('moving', clientX, clientY); }; const handleMouseUp = () => { isDragging.value = false; off(window, 'mousemove', handleMouseMove); off(window, 'mouseup', handleMouseUp); + off(window, 'touchend', handleMouseUp); emit('moveend'); };