点击拖拽创建的点可以继续拖拽

This commit is contained in:
kron
2025-12-29 10:10:21 +08:00
parent 08c4ef0625
commit 919b06bba0
3 changed files with 48 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
<script setup>
import { ref, onMounted } from "vue";
import { ref, onMounted, onBeforeUnmount } from "vue";
import { getElementRect, calcRing } from "@/util";
const props = defineProps({
@@ -19,10 +19,6 @@ const props = defineProps({
type: Function,
default: null,
},
scroll: {
type: Boolean,
default: true,
},
});
const rect = ref({});
@@ -44,6 +40,11 @@ const onClick = async (e) => {
return;
}
if (props.id === 7 || props.id === 9) {
if (
e.detail.x < rect.value.width * 0.2 ||
e.detail.x > rect.value.width * 0.8
)
return;
// 放大并通过滚动将点击位置置于视窗中心
scale.value = 1.4;
const viewportH = rect.value.width; // 容器高度等于宽度100vw
@@ -164,14 +165,44 @@ onMounted(async () => {
capsuleHeight.value = menuBtnInfo.top - 9;
const result = await getElementRect(".container");
rect.value = result;
uni.$on("set-edit-arrow", (data) => {
if (data === null) {
arrow.value = null;
scale.value = 1;
scrollTop.value = 0;
return;
}
if (props.id === 7 || props.id === 9) {
scale.value = 1.4;
const viewportH = rect.value.width; // 容器高度等于宽度100vw
const contentH = scale.value * rect.value.width; // 内容高度
const clickYInContainer = contentH * data.y - rect.value.top;
let target = clickYInContainer * scale.value - viewportH / 2;
target = Math.max(0, Math.min(contentH - viewportH, target));
setTimeout(() => {
scrollTop.value = target > 180 ? target + 10 : target;
}, 200);
}
arrow.value = {
...data,
x: data.x * scale.value,
y: data.y * scale.value,
};
});
});
onBeforeUnmount(() => {
uni.$off("set-edit-arrow");
});
</script>
<template>
<scroll-view
:scroll-y="scroll"
:scroll-y="scale > 1"
scroll-with-animation
:scroll-top="scrollTop"
:show-scrollbar="false"
:enhanced="true"
class="container"
@tap="onClick"
@touchmove="onDrag"