From 74c6544f6b89706c82e4eddd3b9f4f94b1451491 Mon Sep 17 00:00:00 2001 From: guoapeng Date: Mon, 21 Apr 2025 22:41:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=80=97=E6=9D=90=E6=BB=91=E5=8A=A8?= =?UTF-8?q?=E6=94=B9=E5=8F=98=E9=87=8D=E6=9E=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Index/Regular/Consumables.vue | 2 +- .../Index/components/Consumables/BallGrid2.vue | 12 +++++---- .../Index/components/Consumables/DragAreaEx.vue | 30 ++++++++++++++-------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/pages/Index/Regular/Consumables.vue b/src/pages/Index/Regular/Consumables.vue index 5e3c167..5833915 100644 --- a/src/pages/Index/Regular/Consumables.vue +++ b/src/pages/Index/Regular/Consumables.vue @@ -342,7 +342,7 @@ const updateTipNum = async ({ sync: boolean }) => { if (tipNum < 0) { - return + tipNum = 0 } if (deviceStore.deviceState.workState !== 'WORKING') { consumableStore.setDisableUpdateConsumableData(true) diff --git a/src/pages/Index/components/Consumables/BallGrid2.vue b/src/pages/Index/components/Consumables/BallGrid2.vue index d07e333..2bd9b8f 100644 --- a/src/pages/Index/components/Consumables/BallGrid2.vue +++ b/src/pages/Index/components/Consumables/BallGrid2.vue @@ -86,17 +86,19 @@ const ballStates = ref(Array.from({ length: props.total }, () => false)) // 小 // 发出自定义事件通知父组件 const emit = defineEmits(['update:TipNum']) -const updateSliderVal = async (hVal, vVal) => { - const empty = parseInt(vVal) * columns + parseInt(hVal) +const updateSliderVal = async (empty) => { + if (empty< 0){ + empty = 0 + } const activated = total - empty emit('update:TipNum', activated, props.order, false) } const updateSliderEndVal = async (hVal, vVal) => { - const empty = parseInt(vVal) * columns + parseInt(hVal) - const activated = total - empty - emit('update:TipNum', activated, props.order, true) + // const empty = parseInt(vVal) * columns + parseInt(hVal) + // const activated = total - empty + // emit('update:TipNum', activated, props.order, true) } // 计算网格样式 const gridStyle = computed(() => ({ diff --git a/src/pages/Index/components/Consumables/DragAreaEx.vue b/src/pages/Index/components/Consumables/DragAreaEx.vue index 98c6e6f..f5588e8 100644 --- a/src/pages/Index/components/Consumables/DragAreaEx.vue +++ b/src/pages/Index/components/Consumables/DragAreaEx.vue @@ -84,20 +84,30 @@ function handleDrag(event) { if (!isDragging.value) return const touchEvent = event.touches ? event.touches[0] : event - const deltaX = touchEvent.clientX - startX.value - const deltaY = touchEvent.clientY - startY.value const rect = sliderTrack.value.getBoundingClientRect() - let percentX = (deltaX + startXValue.value) / rect.width - let percentY = (deltaY + startYValue.value) / rect.height - - hValue.value = Math.min(1, Math.max(0, percentX)) * hTotalVal.value - vValue.value = Math.min(1, Math.max(0, percentY)) * vTotalVal.value - - emit('update:sliderValue', +hValue.value.toFixed(), +vValue.value.toFixed()) + const clientX = touchEvent.clientX + const clientY = touchEvent.clientY + const relativeX = clientX - rect.left + const relativeY = clientY - rect.top + + const row = Math.ceil(relativeY / (rect.height / vTotalVal.value) ) + const col = Math.ceil(relativeX / (rect.width /hTotalVal.value) ) + + const empty = (row - 1)* hTotalVal.value + col + emit('update:sliderValue', empty) + + // + // let percentX = (deltaX + startXValue.value) / rect.width + // let percentY = (deltaY + startYValue.value) / rect.height + // + // hValue.value = Math.min(1, Math.max(0, percentX)) * hTotalVal.value + // vValue.value = Math.min(1, Math.max(0, percentY)) * vTotalVal.value + // + // emit('update:sliderValue', +hValue.value.toFixed(), +vValue.value.toFixed()) } function handleEnd() { - emit('update:sliderEndValue', +hValue.value.toFixed(), +vValue.value.toFixed()) + // emit('update:sliderEndValue', +hValue.value.toFixed(), +vValue.value.toFixed()) isDragging.value = false document.removeEventListener('mousemove', handleDrag) document.removeEventListener('touchmove', handleDrag)