forked from gzt/A8000
4 changed files with 388 additions and 0 deletions
-
13src/pages/Index/Regular/Consumables.vue
-
141src/pages/Index/components/Consumables/DragAreaEx.vue
-
113src/pages/Index/components/Consumables/SliderArea.vue
-
121src/pages/Index/components/Consumables/SliderAreaEx.vue
@ -0,0 +1,141 @@ |
|||
<template> |
|||
<div |
|||
class="slider-container" |
|||
@mousedown="handleStart" |
|||
@touchstart.prevent="handleStart" |
|||
> |
|||
<div class="slider-track" ref="sliderTrack"> |
|||
<div |
|||
class="slider-fill" |
|||
:style="{ width: `${(hValue / hTotal) * 100}%`, height: `${(vValue / vTotal) * 100}%` }" |
|||
></div> |
|||
<div |
|||
:style="{ visibility: `${isDragging ? 'visible' : 'hidden'}` }" |
|||
class="slider-thumb" |
|||
> |
|||
{{ `${hValue.toFixed()}, ${vValue.toFixed()}` }} |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script setup> |
|||
import { ref, onMounted, onUnmounted, watch, useTemplateRef } from 'vue' |
|||
|
|||
const props = defineProps({ |
|||
hVal: { |
|||
type: Number, |
|||
default: 25, |
|||
}, |
|||
hTotal: { |
|||
type: Number, |
|||
default: 50, |
|||
}, |
|||
vVal: { |
|||
type: Number, |
|||
default: 25, |
|||
}, |
|||
vTotal: { |
|||
type: Number, |
|||
default: 50, |
|||
}, |
|||
}) |
|||
|
|||
const emit = defineEmits(['update:hVal','update:vVal']) |
|||
|
|||
const hValue = ref(props.hVal) |
|||
const hTotalVal = ref(props.hTotal) |
|||
const vValue = ref(props.vVal) |
|||
const vTotalVal = ref(props.vTotal) |
|||
|
|||
const isDragging = ref(false) |
|||
const startX = ref(0) |
|||
const startY = ref(0) |
|||
const startXValue = ref(0) |
|||
const startYValue = ref(0) |
|||
const sliderTrack = useTemplateRef('sliderTrack') |
|||
|
|||
watch( |
|||
[() => props.hVal, () => props.vVal], |
|||
(newX, newY) => { |
|||
if (!isDragging.value) { |
|||
hValue.value = newX |
|||
vValue.value = newY |
|||
} |
|||
}, |
|||
) |
|||
|
|||
function handleStart(event) { |
|||
const touchEvent = event.touches ? event.touches[0] : event |
|||
startX.value = touchEvent.clientX |
|||
startY.value = touchEvent.clientY |
|||
const rect = sliderTrack.value.getBoundingClientRect() |
|||
startXValue.value = (hValue.value / hTotalVal.value) * rect.width |
|||
startYValue.value = (vValue.value / vTotalVal.value) * rect.height |
|||
|
|||
isDragging.value = true |
|||
document.addEventListener('mousemove', handleDrag) |
|||
document.addEventListener('touchmove', handleDrag, { passive: false }) |
|||
document.addEventListener('mouseup', handleEnd) |
|||
document.addEventListener('touchend', handleEnd) |
|||
} |
|||
|
|||
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 |
|||
// console.log(percent, sliderValue.value) |
|||
emit('update:hVal', hValue.value) |
|||
emit('update:vVal', vValue.value) |
|||
} |
|||
|
|||
function handleEnd() { |
|||
isDragging.value = false |
|||
document.removeEventListener('mousemove', handleDrag) |
|||
document.removeEventListener('touchmove', handleDrag) |
|||
document.removeEventListener('mouseup', handleEnd) |
|||
document.removeEventListener('touchend', handleEnd) |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.slider-container { |
|||
width: 300px; |
|||
height: 300px; |
|||
touch-action: none; /* Prevents the browser's default panning behavior */ |
|||
} |
|||
|
|||
.slider-track { |
|||
position: relative; |
|||
height: 100%; |
|||
background-color: #ddd; |
|||
cursor: pointer; |
|||
} |
|||
|
|||
.slider-fill { |
|||
position: absolute; |
|||
/* height: 100%; */ |
|||
background-color: #4caf50; |
|||
} |
|||
|
|||
.slider-thumb { |
|||
position: absolute; |
|||
top: 50%; |
|||
left: 50%; |
|||
transform: translateX(-50%) translateY(-50%); |
|||
font-size: 32px; |
|||
color: gray; |
|||
} |
|||
|
|||
.slider-thumb:active { |
|||
cursor: grabbing; |
|||
} |
|||
</style> |
@ -0,0 +1,113 @@ |
|||
<template> |
|||
<div |
|||
class="slider-container" |
|||
@mousedown="handleStart" |
|||
@touchstart.prevent="handleStart" |
|||
> |
|||
<div class="slider-track" ref="sliderTrack"> |
|||
<div class="slider-fill" :style="{ width: `${sliderValue}%` }"></div> |
|||
<div |
|||
:style="{ visibility: `${isDragging ? 'visible' : 'hidden'}` }" |
|||
class="slider-thumb" |
|||
> |
|||
{{ sliderValue.toFixed() }} |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script setup> |
|||
import { ref, onMounted, onUnmounted, watch, useTemplateRef } from 'vue' |
|||
|
|||
const props = defineProps({ |
|||
modelValue: { |
|||
type: Number, |
|||
default: 50, |
|||
}, |
|||
}) |
|||
|
|||
const emit = defineEmits(['update:modelValue']) |
|||
|
|||
const sliderValue = ref(props.modelValue) |
|||
const isDragging = ref(false) |
|||
const startX = ref(0) |
|||
const startValue = ref(0) |
|||
// const sliderThumb = ref(null); |
|||
const sliderTrack = useTemplateRef('sliderTrack') |
|||
|
|||
watch( |
|||
() => props.modelValue, |
|||
(newValue) => { |
|||
if (!isDragging.value) { |
|||
sliderValue.value = newValue |
|||
} |
|||
}, |
|||
) |
|||
|
|||
function handleStart(event) { |
|||
const touchEvent = event.touches ? event.touches[0] : event |
|||
startX.value = touchEvent.clientX |
|||
const rect = sliderTrack.value.getBoundingClientRect() |
|||
startValue.value = (sliderValue.value * rect.width) / 100 |
|||
|
|||
isDragging.value = true |
|||
document.addEventListener('mousemove', handleDrag) |
|||
document.addEventListener('touchmove', handleDrag, { passive: false }) |
|||
document.addEventListener('mouseup', handleEnd) |
|||
document.addEventListener('touchend', handleEnd) |
|||
} |
|||
|
|||
function handleDrag(event) { |
|||
if (!isDragging.value) return |
|||
|
|||
const touchEvent = event.touches ? event.touches[0] : event |
|||
const deltaX = touchEvent.clientX - startX.value |
|||
const rect = sliderTrack.value.getBoundingClientRect() |
|||
let percent = ((deltaX + startValue.value) / rect.width) * 100 |
|||
|
|||
// Limit the value between 0 and 100 |
|||
sliderValue.value = Math.min(100, Math.max(0, percent)) |
|||
emit('update:modelValue', sliderValue.value) |
|||
} |
|||
|
|||
function handleEnd() { |
|||
isDragging.value = false |
|||
document.removeEventListener('mousemove', handleDrag) |
|||
document.removeEventListener('touchmove', handleDrag) |
|||
document.removeEventListener('mouseup', handleEnd) |
|||
document.removeEventListener('touchend', handleEnd) |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.slider-container { |
|||
width: 300px; |
|||
touch-action: none; /* Prevents the browser's default panning behavior */ |
|||
} |
|||
|
|||
.slider-track { |
|||
position: relative; |
|||
height: 4rem; |
|||
background-color: #ddd; |
|||
cursor: pointer; |
|||
} |
|||
|
|||
.slider-fill { |
|||
position: absolute; |
|||
height: 100%; |
|||
background-color: #4caf50; |
|||
} |
|||
|
|||
.slider-thumb { |
|||
position: absolute; |
|||
top: 50%; |
|||
left: 50%; |
|||
transform: translateX(-50%) translateY(-50%); |
|||
font-size: 32px; |
|||
color: gray; |
|||
} |
|||
|
|||
.slider-thumb:active { |
|||
cursor: grabbing; |
|||
} |
|||
</style> |
@ -0,0 +1,121 @@ |
|||
<template> |
|||
<div |
|||
class="slider-container" |
|||
@mousedown="handleStart" |
|||
@touchstart.prevent="handleStart" |
|||
> |
|||
<div class="slider-track" ref="sliderTrack"> |
|||
<div |
|||
class="slider-fill" |
|||
:style="{ width: `${(sliderValue / totalVal) * 100}%` }" |
|||
></div> |
|||
<div |
|||
:style="{ visibility: `${isDragging ? 'visible' : 'hidden'}` }" |
|||
class="slider-thumb" |
|||
> |
|||
{{ sliderValue.toFixed() }} |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script setup> |
|||
import { ref, onMounted, onUnmounted, watch, useTemplateRef } from 'vue' |
|||
|
|||
const props = defineProps({ |
|||
modelValue: { |
|||
type: Number, |
|||
default: 25, |
|||
}, |
|||
totalValue: { |
|||
type: Number, |
|||
default: 50, |
|||
}, |
|||
}) |
|||
|
|||
const emit = defineEmits(['update:modelValue']) |
|||
|
|||
const sliderValue = ref(props.modelValue) |
|||
const totalVal = ref(props.totalValue) |
|||
const isDragging = ref(false) |
|||
const startX = ref(0) |
|||
const startValue = ref(0) |
|||
const sliderTrack = useTemplateRef('sliderTrack') |
|||
|
|||
watch( |
|||
() => props.modelValue, |
|||
(newValue) => { |
|||
if (!isDragging.value) { |
|||
sliderValue.value = newValue |
|||
} |
|||
}, |
|||
) |
|||
|
|||
function handleStart(event) { |
|||
const touchEvent = event.touches ? event.touches[0] : event |
|||
startX.value = touchEvent.clientX |
|||
const rect = sliderTrack.value.getBoundingClientRect() |
|||
startValue.value = (sliderValue.value / totalVal.value) * rect.width |
|||
// console.log(sliderValue.value, totalVal.value) |
|||
// console.log(startValue.value, rect.width) |
|||
isDragging.value = true |
|||
document.addEventListener('mousemove', handleDrag) |
|||
document.addEventListener('touchmove', handleDrag, { passive: false }) |
|||
document.addEventListener('mouseup', handleEnd) |
|||
document.addEventListener('touchend', handleEnd) |
|||
} |
|||
|
|||
function handleDrag(event) { |
|||
if (!isDragging.value) return |
|||
|
|||
const touchEvent = event.touches ? event.touches[0] : event |
|||
const deltaX = touchEvent.clientX - startX.value |
|||
const rect = sliderTrack.value.getBoundingClientRect() |
|||
let percent = (deltaX + startValue.value) / rect.width |
|||
|
|||
sliderValue.value = Math.min(1, Math.max(0, percent)) * totalVal.value |
|||
// console.log(percent, sliderValue.value) |
|||
emit('update:modelValue', sliderValue.value) |
|||
} |
|||
|
|||
function handleEnd() { |
|||
isDragging.value = false |
|||
document.removeEventListener('mousemove', handleDrag) |
|||
document.removeEventListener('touchmove', handleDrag) |
|||
document.removeEventListener('mouseup', handleEnd) |
|||
document.removeEventListener('touchend', handleEnd) |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.slider-container { |
|||
width: 300px; |
|||
touch-action: none; /* Prevents the browser's default panning behavior */ |
|||
} |
|||
|
|||
.slider-track { |
|||
position: relative; |
|||
height: 4rem; |
|||
background-color: #ddd; |
|||
cursor: pointer; |
|||
} |
|||
|
|||
.slider-fill { |
|||
position: absolute; |
|||
height: 100%; |
|||
background-color: #4caf50; |
|||
} |
|||
|
|||
.slider-thumb { |
|||
position: absolute; |
|||
top: 50%; |
|||
left: 50%; |
|||
transform: translateX(-50%) translateY(-50%); |
|||
font-size: 32px; |
|||
color: gray; |
|||
} |
|||
|
|||
.slider-thumb:active { |
|||
cursor: grabbing; |
|||
} |
|||
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue