点击拖拽创建的点可以继续拖拽
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from "vue";
|
import { ref, onMounted, onBeforeUnmount } from "vue";
|
||||||
import { getElementRect, calcRing } from "@/util";
|
import { getElementRect, calcRing } from "@/util";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -19,10 +19,6 @@ const props = defineProps({
|
|||||||
type: Function,
|
type: Function,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
scroll: {
|
|
||||||
type: Boolean,
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const rect = ref({});
|
const rect = ref({});
|
||||||
@@ -44,6 +40,11 @@ const onClick = async (e) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (props.id === 7 || props.id === 9) {
|
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;
|
scale.value = 1.4;
|
||||||
const viewportH = rect.value.width; // 容器高度等于宽度(100vw)
|
const viewportH = rect.value.width; // 容器高度等于宽度(100vw)
|
||||||
@@ -164,14 +165,44 @@ onMounted(async () => {
|
|||||||
capsuleHeight.value = menuBtnInfo.top - 9;
|
capsuleHeight.value = menuBtnInfo.top - 9;
|
||||||
const result = await getElementRect(".container");
|
const result = await getElementRect(".container");
|
||||||
rect.value = result;
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<scroll-view
|
<scroll-view
|
||||||
:scroll-y="scroll"
|
:scroll-y="scale > 1"
|
||||||
scroll-with-animation
|
scroll-with-animation
|
||||||
:scroll-top="scrollTop"
|
:scroll-top="scrollTop"
|
||||||
|
:show-scrollbar="false"
|
||||||
|
:enhanced="true"
|
||||||
class="container"
|
class="container"
|
||||||
@tap="onClick"
|
@tap="onClick"
|
||||||
@touchmove="onDrag"
|
@touchmove="onDrag"
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ onShareTimeline(async () => {
|
|||||||
:id="targetId"
|
:id="targetId"
|
||||||
:src="targetSrc"
|
:src="targetSrc"
|
||||||
:arrows="arrows.filter((item) => item.x && item.y)"
|
:arrows="arrows.filter((item) => item.x && item.y)"
|
||||||
:scroll="false"
|
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
<view :style="{ transform: hasPoint ? 'translateY(-100rpx)' : 'none' }">
|
<view :style="{ transform: hasPoint ? 'translateY(-100rpx)' : 'none' }">
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ const deleteArrow = () => {
|
|||||||
} else {
|
} else {
|
||||||
arrowGroups.value[currentGroup.value][currentArrow.value] = {};
|
arrowGroups.value[currentGroup.value][currentArrow.value] = {};
|
||||||
}
|
}
|
||||||
|
uni.$emit("set-edit-arrow", null);
|
||||||
uni.setStorageSync("last-point-record", arrowGroups.value);
|
uni.setStorageSync("last-point-record", arrowGroups.value);
|
||||||
};
|
};
|
||||||
const onEditDone = (arrow) => {
|
const onEditDone = (arrow) => {
|
||||||
@@ -83,6 +84,15 @@ const onEditDone = (arrow) => {
|
|||||||
if (currentArrow.value < amount.value - 1) currentArrow.value++;
|
if (currentArrow.value < amount.value - 1) currentArrow.value++;
|
||||||
uni.setStorageSync("last-point-record", arrowGroups.value);
|
uni.setStorageSync("last-point-record", arrowGroups.value);
|
||||||
};
|
};
|
||||||
|
const onSelectArrow = (index) => {
|
||||||
|
currentArrow.value = index;
|
||||||
|
const arrow = arrowGroups.value[currentGroup.value][currentArrow.value];
|
||||||
|
if (arrow && arrow.x && arrow.y) {
|
||||||
|
uni.$emit("set-edit-arrow", arrow);
|
||||||
|
} else {
|
||||||
|
uni.$emit("set-edit-arrow", null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
onLoad((options) => {
|
onLoad((options) => {
|
||||||
const pointBook = uni.getStorageSync("last-point-book");
|
const pointBook = uni.getStorageSync("last-point-book");
|
||||||
@@ -145,7 +155,7 @@ onLoad((options) => {
|
|||||||
v-if="arrowGroups[currentGroup]"
|
v-if="arrowGroups[currentGroup]"
|
||||||
v-for="(arrow, index) in arrowGroups[currentGroup]"
|
v-for="(arrow, index) in arrowGroups[currentGroup]"
|
||||||
:key="index"
|
:key="index"
|
||||||
@click="currentArrow = index"
|
@click="onSelectArrow(index)"
|
||||||
:style="{
|
:style="{
|
||||||
borderColor: currentArrow === index ? '#FED847' : '#eeeeee',
|
borderColor: currentArrow === index ? '#FED847' : '#eeeeee',
|
||||||
borderWidth: currentArrow === index ? '2px' : '1px',
|
borderWidth: currentArrow === index ? '2px' : '1px',
|
||||||
|
|||||||
Reference in New Issue
Block a user