|
@@ -1,16 +1,15 @@
|
|
|
<template>
|
|
|
- <!-- 使用 更复杂的线段拖拽 -->
|
|
|
<!-- @dragstart="emit('dragLineStart', props.line)"
|
|
|
@update:line="(ps) => emit('dragLine', props.line, ps)"
|
|
|
@dragend="emit('dragLineEnd', props.line)" -->
|
|
|
<EditLine
|
|
|
:ref="(d: any) => shape = d?.shape"
|
|
|
- :data="{ ...line, ...style, lineJoin: 'miter' }"
|
|
|
+ :data="data"
|
|
|
:opacity="0"
|
|
|
:points="points"
|
|
|
:closed="false"
|
|
|
:id="line.id"
|
|
|
- :disablePoint="!showEditPoint || isDrawIng"
|
|
|
+ :disablePoint="true"
|
|
|
:ndx="0"
|
|
|
@dragstart="dragstartHandler(points.map((item) => item.id))"
|
|
|
@update:line="
|
|
@@ -40,32 +39,12 @@
|
|
|
v-for="polygon in diffPolygons"
|
|
|
:config="{
|
|
|
points: flatPositions(polygon),
|
|
|
- fill: line.stroke,
|
|
|
+ fill: isDrawIng ? themeColor : style.stroke,
|
|
|
closed: true,
|
|
|
listening: false,
|
|
|
}"
|
|
|
v-if="diffPolygons"
|
|
|
/>
|
|
|
- <template v-if="showEditPoint">
|
|
|
- <EditPoint
|
|
|
- v-for="(point, ndx) in points"
|
|
|
- :key="point.id"
|
|
|
- :size="line.strokeWidth"
|
|
|
- :points="points"
|
|
|
- :opacity="1"
|
|
|
- :drawIng="ndx === 0 && isDrawIng"
|
|
|
- :ndx="ndx"
|
|
|
- :closed="false"
|
|
|
- :id="line.id"
|
|
|
- :disable="addMode"
|
|
|
- :color="isDrawIng ? themeColor : style.stroke"
|
|
|
- @dragstart="dragstartHandler([point.id])"
|
|
|
- @update:position="(p) => emit('updatePoint', { ...point, ...p })"
|
|
|
- @dragend="dragendHandler"
|
|
|
- @delete="delPoint(point)"
|
|
|
- />
|
|
|
- </template>
|
|
|
-
|
|
|
<PropertyUpdate
|
|
|
:describes="describes"
|
|
|
:data="line"
|
|
@@ -73,10 +52,9 @@
|
|
|
:name="shapeName"
|
|
|
@change="
|
|
|
() => {
|
|
|
- isStartChange || emit('updateBefore', []);
|
|
|
+ describes.length.isChange || emit('updateBefore', []);
|
|
|
emit('updateLine', { ...line });
|
|
|
emit('update');
|
|
|
- isStartChange = false;
|
|
|
}
|
|
|
"
|
|
|
@delete="delHandler"
|
|
@@ -86,30 +64,22 @@
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
import { computed, ref, watchEffect } from "vue";
|
|
|
-import { getMouseStyle, getSnapInfos, LineData, shapeName } from "./index.ts";
|
|
|
+import { getMouseStyle, LineData, shapeName } from "./index.ts";
|
|
|
import { flatPositions, onlyId } from "@/utils/shared.ts";
|
|
|
import EditLine from "../share/edit-line.vue";
|
|
|
-import { getVectorLine, lineCenter, lineLen, lineVector, Pos } from "@/utils/math.ts";
|
|
|
+import { Pos } from "@/utils/math.ts";
|
|
|
import { Line } from "konva/lib/shapes/Line";
|
|
|
import { DC } from "@/deconstruction.js";
|
|
|
-import { useMode } from "@/core/hook/use-status.ts";
|
|
|
-import { Mode } from "@/constant/mode.ts";
|
|
|
import SizeLine from "../share/size-line.vue";
|
|
|
import { useConfig } from "@/core/hook/use-config.ts";
|
|
|
-import { ComponentSnapInfo } from "../index.ts";
|
|
|
-import { useCustomSnapInfos } from "@/core/hook/use-snap.ts";
|
|
|
-import { mergeDescribes } from "@/core/html-mount/propertys/index.ts";
|
|
|
import { PropertyUpdate, Operate } from "../../html-mount/propertys/index.ts";
|
|
|
import {
|
|
|
useAnimationMouseStyle,
|
|
|
useMouseShapeStatus,
|
|
|
} from "@/core/hook/use-mouse-status.ts";
|
|
|
import { themeColor } from "@/constant";
|
|
|
-import { Vector2 } from "three";
|
|
|
-import { useGetDiffPolygons, useGetExtendPolygon } from "./attach-view.ts";
|
|
|
-import EditPoint from "../share/edit-point.vue";
|
|
|
-
|
|
|
-const mode = useMode();
|
|
|
+import { useGetDiffLineIconPolygons, useGetExtendPolygon } from "./attach-view.ts";
|
|
|
+import { useLineDataSnapInfos, useLineDescribes } from "./attach-server.ts";
|
|
|
|
|
|
const props = defineProps<{
|
|
|
line: LineData["lines"][number];
|
|
@@ -119,31 +89,9 @@ const props = defineProps<{
|
|
|
dragPointIds?: string[];
|
|
|
}>();
|
|
|
|
|
|
-const getExtendPolygon = useGetExtendPolygon();
|
|
|
-const showEditPoint = computed(() => {
|
|
|
- return (
|
|
|
- (!mode.include(Mode.readonly) && !mode.include(Mode.draw) && props.canEdit) ||
|
|
|
- isDrawIng.value
|
|
|
- );
|
|
|
-});
|
|
|
-const polygon = computed(() =>
|
|
|
- getExtendPolygon(props.data, props.line, !showEditPoint.value)
|
|
|
-);
|
|
|
-const dragIng = computed(
|
|
|
- () =>
|
|
|
- props.dragPointIds?.length &&
|
|
|
- (props.dragPointIds.includes(props.line.a) ||
|
|
|
- props.dragPointIds.includes(props.line.b))
|
|
|
-);
|
|
|
-const getDiffPolygons = useGetDiffPolygons();
|
|
|
-const diffPolygons = computed(() =>
|
|
|
- !dragIng.value ? getDiffPolygons(polygon.value) : [polygon.value]
|
|
|
-);
|
|
|
-
|
|
|
const emit = defineEmits<{
|
|
|
(e: "updatePoint", value: LineData["points"][number]): void;
|
|
|
(e: "addPoint", value: LineData["points"][number]): void;
|
|
|
- (e: "delPoint", value: LineData["points"][number]): void;
|
|
|
(e: "delLine"): void;
|
|
|
(e: "updateLine", value: LineData["lines"][number]): void;
|
|
|
(e: "updateBefore", value: string[]): void;
|
|
@@ -154,125 +102,58 @@ const emit = defineEmits<{
|
|
|
(e: "dragLineEnd", value: LineData["lines"][number]): void;
|
|
|
}>();
|
|
|
|
|
|
+const getExtendPolygon = useGetExtendPolygon();
|
|
|
+const polygon = computed(() => getExtendPolygon(props.data, props.line, true));
|
|
|
+const getDiffPolygons = useGetDiffLineIconPolygons(props.line);
|
|
|
+const diffPolygons = computed(() => getDiffPolygons(polygon.value));
|
|
|
+
|
|
|
const shape = ref<DC<Line>>();
|
|
|
const points = computed(() => [
|
|
|
props.data.points.find((p) => p.id === props.line.a)!,
|
|
|
props.data.points.find((p) => p.id === props.line.b)!,
|
|
|
]);
|
|
|
const lineData = computed(() => props.line);
|
|
|
-const describes = mergeDescribes(lineData, {}, ["stroke", "strokeWidth"]);
|
|
|
-const d = describes as any;
|
|
|
-d.strokeWidth.props = {
|
|
|
- ...d.strokeWidth.props,
|
|
|
- proportion: true,
|
|
|
-};
|
|
|
-d.strokeWidth.label = "粗细";
|
|
|
-d.stroke.label = "颜色";
|
|
|
-
|
|
|
-let isStartChange = false;
|
|
|
-let setLineVector: Vector2;
|
|
|
-describes.length = {
|
|
|
- type: "inputNum",
|
|
|
- label: "线段长度",
|
|
|
- "layout-type": "row",
|
|
|
- get value() {
|
|
|
- return lineLen(points.value[0], points.value[1]);
|
|
|
- },
|
|
|
- set value(val) {
|
|
|
- if (!isStartChange) {
|
|
|
- emit("updateBefore", [props.line.a, props.line.b]);
|
|
|
- setLineVector = lineVector(points.value);
|
|
|
- }
|
|
|
- isStartChange = true;
|
|
|
- const aCount = props.data.lines.filter(
|
|
|
- (line) => line.a === points.value[0].id || line.b === points.value[0].id
|
|
|
- ).length;
|
|
|
- const bCount = props.data.lines.filter(
|
|
|
- (line) => line.a === points.value[1].id || line.b === points.value[1].id
|
|
|
- ).length;
|
|
|
-
|
|
|
- if (aCount === bCount || (aCount > 1 && bCount > 1)) {
|
|
|
- // 两端伸展
|
|
|
- const center = lineCenter(points.value);
|
|
|
- const l1 = getVectorLine(setLineVector.clone().multiplyScalar(-1), center, val / 2);
|
|
|
- const l2 = getVectorLine(setLineVector, center, val / 2);
|
|
|
- emit("updatePoint", { ...points.value[0], ...l1[1] });
|
|
|
- emit("updatePoint", { ...points.value[1], ...l2[1] });
|
|
|
- } else {
|
|
|
- // 单端伸展
|
|
|
- const changeNdx = aCount > 1 ? 1 : 0;
|
|
|
- const start = points.value[aCount > 1 ? 0 : 1];
|
|
|
- const lineVec =
|
|
|
- aCount > 1 ? setLineVector : setLineVector.clone().multiplyScalar(-1);
|
|
|
- const line = getVectorLine(lineVec, start, val);
|
|
|
- emit("updatePoint", { ...points.value[changeNdx], ...line[1] });
|
|
|
- }
|
|
|
- },
|
|
|
- props: { proportion: true },
|
|
|
-};
|
|
|
+const describes = useLineDescribes(lineData);
|
|
|
|
|
|
const delHandler = () => {
|
|
|
emit("updateBefore", [props.line.a, props.line.b]);
|
|
|
emit("delLine");
|
|
|
emit("update");
|
|
|
};
|
|
|
-const menus = [
|
|
|
- {
|
|
|
- label: "删除",
|
|
|
- handler: delHandler,
|
|
|
- },
|
|
|
-];
|
|
|
+const menus = [{ label: "删除", handler: delHandler }];
|
|
|
|
|
|
const status = useMouseShapeStatus(shape);
|
|
|
-const [mstyle] = useAnimationMouseStyle({
|
|
|
+const [style] = useAnimationMouseStyle({
|
|
|
shape,
|
|
|
getMouseStyle,
|
|
|
data: lineData as any,
|
|
|
});
|
|
|
+
|
|
|
const isDrawIng = computed(
|
|
|
() =>
|
|
|
props.addMode && props.data.lines.indexOf(props.line) === props.data.lines.length - 1
|
|
|
);
|
|
|
|
|
|
-const style = computed(() =>
|
|
|
- isDrawIng.value ? { ...mstyle.value, stroke: themeColor } : mstyle.value
|
|
|
-);
|
|
|
-
|
|
|
const addPoint = (pos: Pos) => {
|
|
|
emit("updateBefore", []);
|
|
|
emit("addPoint", { ...points.value[0], ...pos, id: onlyId() });
|
|
|
emit("update");
|
|
|
};
|
|
|
|
|
|
+const lDataSnap = useLineDataSnapInfos();
|
|
|
const config = useConfig();
|
|
|
-const delPoint = (point: LineData["points"][number]) => {
|
|
|
- emit("updateBefore", []);
|
|
|
- emit("delPoint", point);
|
|
|
- emit("update");
|
|
|
-};
|
|
|
-
|
|
|
-const infos = useCustomSnapInfos();
|
|
|
-let snapInfos: ComponentSnapInfo[];
|
|
|
const dragstartHandler = (eIds: string[]) => {
|
|
|
emit("updateBefore", eIds);
|
|
|
-
|
|
|
- snapInfos = getSnapInfos({
|
|
|
- ...props.data,
|
|
|
- lines: props.data.lines.filter(
|
|
|
- (item) => !(eIds.includes(item.a) || eIds.includes(item.b))
|
|
|
- ),
|
|
|
- points: props.data.points.filter((item) => !eIds.includes(item.id)),
|
|
|
- });
|
|
|
- snapInfos.forEach((item) => {
|
|
|
- infos.add(item);
|
|
|
- });
|
|
|
+ lDataSnap.update(eIds);
|
|
|
};
|
|
|
const dragendHandler = () => {
|
|
|
emit("update");
|
|
|
- snapInfos.forEach((item) => infos.remove(item));
|
|
|
+ lDataSnap.clear();
|
|
|
};
|
|
|
|
|
|
-// const padstart = computed(() => {
|
|
|
-// props.line.
|
|
|
-// })
|
|
|
+defineExpose({
|
|
|
+ get shape() {
|
|
|
+ return shape.value;
|
|
|
+ },
|
|
|
+});
|
|
|
</script>
|