From 2f8eb36a52b12b131bcbfd509acd29b5d603345c Mon Sep 17 00:00:00 2001 From: xingyy <64720302+Concur-max@users.noreply.github.com> Date: Fri, 14 Feb 2025 17:00:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(components):=20=E5=AE=9E=E7=8E=B0=E4=BE=A7?= =?UTF-8?q?=E8=BE=B9=E6=A0=8F=E6=8B=96=E5=8A=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 SideButton 组件中添加拖动功能,支持鼠标和触摸操作 -优化 artDetail 页面中的拖动逻辑,限制拖动范围 -修复 liveRoom 组件中的拖动相关问题 --- app/pages/artDetail/index.vue | 14 +- .../liveRoom/components/SideButton/index.vue | 145 +++++++++++++++--- 2 files changed, 130 insertions(+), 29 deletions(-) diff --git a/app/pages/artDetail/index.vue b/app/pages/artDetail/index.vue index 8838e5c..8576f79 100644 --- a/app/pages/artDetail/index.vue +++ b/app/pages/artDetail/index.vue @@ -14,7 +14,7 @@ const initData = async () => { detail.value = res.data } } -const position = ref({x: window?.innerWidth - 120 || 0, y: 240}) // 设置初始位置在右侧 +const position = ref({x: window?.innerWidth - 120 || 0, y: 240}) const startPosition = ref({x: 0, y: 0}) const isDragging = ref(false) @@ -33,38 +33,30 @@ const onDrag = (e) => { const clientX = e.touches ? e.touches[0].clientX : e.clientX const clientY = e.touches ? e.touches[0].clientY : e.clientY - // 获取窗口尺寸 - const maxX = window.innerWidth - 108 // 减去元素宽度 - const maxY = window.innerHeight - 137 // 减去元素高度 + const maxX = window.innerWidth - 108 + const maxY = window.innerHeight - 137 - // 限制范围 const x = Math.min(Math.max(0, clientX - startPosition.value.x), maxX) const y = Math.min(Math.max(0, clientY - startPosition.value.y), maxY) - position.value = {x, y} } } - const stopDrag = () => { isDragging.value = false } onMounted(() => { - // 鼠标事件 document.addEventListener('mousemove', onDrag) document.addEventListener('mouseup', stopDrag) - // 触摸事件 document.addEventListener('touchmove', onDrag) document.addEventListener('touchend', stopDrag) }) - onUnmounted(() => { document.removeEventListener('mousemove', onDrag) document.removeEventListener('mouseup', stopDrag) document.removeEventListener('touchmove', onDrag) document.removeEventListener('touchend', stopDrag) }) - initData() diff --git a/app/pages/liveRoom/components/SideButton/index.vue b/app/pages/liveRoom/components/SideButton/index.vue index 77fbbba..142dc27 100644 --- a/app/pages/liveRoom/components/SideButton/index.vue +++ b/app/pages/liveRoom/components/SideButton/index.vue @@ -1,17 +1,93 @@ + + \ No newline at end of file