Skip to content

Commit

Permalink
fix: 修复Slider组件拖拽时,在移动端无效。 (#3343)
Browse files Browse the repository at this point in the history
Co-authored-by: Belen <[email protected]>
  • Loading branch information
BelenLuo-tech and Belen authored Nov 23, 2024
1 parent 9589fcb commit 5df412f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/web-vue/components/slider/slider-button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
:aria-valuetext="tooltipContent"
:class="cls"
@mousedown="handleMouseDown"
@touchstart="handleMouseDown"
@contextmenu.prevent
@click.stop
/>
</tooltip>
Expand Down Expand Up @@ -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');
};
Expand Down

0 comments on commit 5df412f

Please sign in to comment.