|
@@ -12,16 +12,18 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
-import { computed, ref, watch, watchEffect } from "vue";
|
|
|
|
|
|
+import { computed, onUnmounted, ref, watch, watchEffect } from "vue";
|
|
import { sdk } from "@/sdk";
|
|
import { sdk } from "@/sdk";
|
|
|
|
|
|
import type { Path } from "@/store";
|
|
import type { Path } from "@/store";
|
|
|
|
+import { inRevise } from "bill/utils";
|
|
|
|
|
|
export type SignProps = { path: Path };
|
|
export type SignProps = { path: Path };
|
|
|
|
|
|
const props = defineProps<SignProps>();
|
|
const props = defineProps<SignProps>();
|
|
const emit = defineEmits<{
|
|
const emit = defineEmits<{
|
|
(e: "delete"): void;
|
|
(e: "delete"): void;
|
|
|
|
+ (e: "updateLinePosition", val: Path["linePosition"]): void;
|
|
(e: "updatePoints", val: Path["points"]): void;
|
|
(e: "updatePoints", val: Path["points"]): void;
|
|
}>();
|
|
}>();
|
|
|
|
|
|
@@ -29,9 +31,9 @@ const getLineProps = () => ({
|
|
width: props.path.lineWidth,
|
|
width: props.path.lineWidth,
|
|
color: props.path.lineColor,
|
|
color: props.path.lineColor,
|
|
altitudeAboveGround: props.path.lineAltitudeAboveGround,
|
|
altitudeAboveGround: props.path.lineAltitudeAboveGround,
|
|
- position: props.path.linePosition?.loc || props.path.points[0].position.loc,
|
|
|
|
|
|
+ position: props.path.linePosition?.position || props.path.points[0].position,
|
|
normal: props.path.linePosition?.normal || { x: 0, y: 0, z: 1 },
|
|
normal: props.path.linePosition?.normal || { x: 0, y: 0, z: 1 },
|
|
- modelId: props.path.linePosition?.modelId || props.path.points[0].position.modelId,
|
|
|
|
|
|
+ modelId: props.path.linePosition?.modelId || props.path.points[0].modelId,
|
|
});
|
|
});
|
|
|
|
|
|
const path = sdk.createPath({
|
|
const path = sdk.createPath({
|
|
@@ -41,20 +43,10 @@ const path = sdk.createPath({
|
|
showDirection: props.path.showDirection,
|
|
showDirection: props.path.showDirection,
|
|
reverseDirection: props.path.reverseDirection,
|
|
reverseDirection: props.path.reverseDirection,
|
|
line: getLineProps(),
|
|
line: getLineProps(),
|
|
- points: props.path.points.map((item) => ({
|
|
|
|
- name: item.name,
|
|
|
|
- position: item.position.loc,
|
|
|
|
- modelId: item.position.modelId,
|
|
|
|
- })),
|
|
|
|
|
|
+ points: props.path.points,
|
|
});
|
|
});
|
|
|
|
+path.changeCanEdit(false);
|
|
|
|
|
|
-watch(
|
|
|
|
- getLineProps,
|
|
|
|
- (val) => {
|
|
|
|
- path.changeLine(val);
|
|
|
|
- },
|
|
|
|
- { deep: true }
|
|
|
|
-);
|
|
|
|
watchEffect(() => path.visibilityName(props.path.showName));
|
|
watchEffect(() => path.visibilityName(props.path.showName));
|
|
|
|
|
|
const toCameraDistance = ref(path.toCameraDistance);
|
|
const toCameraDistance = ref(path.toCameraDistance);
|
|
@@ -66,23 +58,57 @@ const show = computed(
|
|
);
|
|
);
|
|
watchEffect(() => path.visibility(show.value));
|
|
watchEffect(() => path.visibility(show.value));
|
|
|
|
|
|
|
|
+let currentPoints = props.path.points;
|
|
|
|
+let changPointsTimeout: any;
|
|
path.bus.on("changePoints", (points) => {
|
|
path.bus.on("changePoints", (points) => {
|
|
- pathPoints.value = points.map((p) => ({
|
|
|
|
- localPos: p.position,
|
|
|
|
|
|
+ clearTimeout(changPointsTimeout);
|
|
|
|
+ currentPoints = points.map((p, ndx) => ({
|
|
|
|
+ name: `标记点${ndx + 1}`,
|
|
|
|
+ position: { ...p.position },
|
|
modelId: p.modelId,
|
|
modelId: p.modelId,
|
|
}));
|
|
}));
|
|
|
|
+ emit("updatePoints", currentPoints);
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+watch(
|
|
|
|
+ () => props.path.points,
|
|
|
|
+ (p) => {
|
|
|
|
+ changPointsTimeout = setTimeout(() => {
|
|
|
|
+ if (inRevise(p, currentPoints)) {
|
|
|
|
+ path.changePathPoints(p);
|
|
|
|
+ currentPoints = p;
|
|
|
|
+ }
|
|
|
|
+ }, 16);
|
|
|
|
+ },
|
|
|
|
+ { deep: true, flush: "post" }
|
|
|
|
+);
|
|
|
|
|
|
- emit(
|
|
|
|
- "updatePoints",
|
|
|
|
- points.map((p, i) => ({
|
|
|
|
- ...props.path.points[i],
|
|
|
|
- position: {
|
|
|
|
- loc: p.position,
|
|
|
|
- modelId: p.modelId,
|
|
|
|
- },
|
|
|
|
- }))
|
|
|
|
- );
|
|
|
|
|
|
+let currentLine = getLineProps();
|
|
|
|
+let changLineTimeout: any;
|
|
|
|
+watch(
|
|
|
|
+ getLineProps,
|
|
|
|
+ (val) => {
|
|
|
|
+ changLineTimeout = setTimeout(() => {
|
|
|
|
+ if (inRevise(val, currentLine)) {
|
|
|
|
+ path.changeLine(val);
|
|
|
|
+ currentLine = val;
|
|
|
|
+ }
|
|
|
|
+ }, 16);
|
|
|
|
+ },
|
|
|
|
+ { deep: true }
|
|
|
|
+);
|
|
|
|
+path.bus.on("linePositionChange", (position) => {
|
|
|
|
+ const p = {
|
|
|
|
+ position: { ...position.pos },
|
|
|
|
+ normal: { ...position.normal },
|
|
|
|
+ modelId: position.modelId,
|
|
|
|
+ };
|
|
|
|
+ currentLine = { ...getLineProps(), ...p };
|
|
|
|
+ emit("updateLinePosition", p);
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+onUnmounted(() => path.destory());
|
|
|
|
+defineExpose(path);
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped></style>
|
|
<style lang="scss" scoped></style>
|