Browse Source

优化长按处理

fixbug/user-0121
zhangjiming 6 months ago
parent
commit
0ce2fc2729
  1. 4
      src/pages/Index/components/Consumables/DragAreaEx.vue
  2. 11
      src/pages/Index/components/Consumables/SliderAreaEx.vue

4
src/pages/Index/components/Consumables/DragAreaEx.vue

@ -93,11 +93,11 @@ function handleDrag(event) {
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())
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)

11
src/pages/Index/components/Consumables/SliderAreaEx.vue

@ -75,7 +75,8 @@ function handleStart(event) {
isDragging.value = true
longPressTimer = setTimeout(() => {
if (Math.round(sliderValue.value) === props.currValue) {
longPressTimer = null
if (+sliderValue.value.toFixed() === props.currValue) {
emit('longPress', props.order)
}
}, 1200)
@ -87,7 +88,6 @@ function handleStart(event) {
}
function handleDrag(event) {
if (longPressTimer) {
clearTimeout(longPressTimer)
longPressTimer = null
@ -102,7 +102,7 @@ function handleDrag(event) {
sliderValue.value =
totalVal.value - Math.min(1, Math.max(0, percent)) * totalVal.value
// console.log(percent, sliderValue.value)
emit('update:sliderValue', sliderValue.value.toFixed(), props.order)
emit('update:sliderValue', +sliderValue.value.toFixed(), props.order)
}
function handleEnd() {
@ -110,9 +110,10 @@ function handleEnd() {
if (longPressTimer) {
clearTimeout(longPressTimer)
longPressTimer = null
} else {
emit('update:sliderEndValue', sliderValue.value.toFixed(), props.order)
}
emit('update:sliderEndValue', +sliderValue.value.toFixed(), props.order)
document.removeEventListener('mousemove', handleDrag)
document.removeEventListener('touchmove', handleDrag)
document.removeEventListener('mouseup', handleEnd)

Loading…
Cancel
Save