list.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <!-- <template v-for="(path, index) in paths" :key="path.id">
  3. v-if="getPathIsShow(path)" -->
  4. <Sign
  5. v-for="(path, index) in paths"
  6. @delete="deletePath(path)"
  7. @updatePoints="(data) => updatePosition(index, data)"
  8. @updateLinePosition="(data) => updateLinePosition(index, data)"
  9. @updateLineHeight="(data) => (paths[index].lineAltitudeAboveGround = data)"
  10. :ref="(node: any) => nodeHandler(index, node)"
  11. :path="path"
  12. :key="path.id"
  13. />
  14. <!-- </template> -->
  15. </template>
  16. <script lang="ts" setup>
  17. import { reactive, watchEffect } from "vue";
  18. import Sign from "./sign.vue";
  19. import { getPathIsShow, Path } from "@/store";
  20. import { PathsNode } from "@/sdk/association/path";
  21. const props = defineProps<{ paths: Path[] }>();
  22. const nodes = reactive([]) as PathsNode;
  23. watchEffect(() => (nodes.length = props.paths.length));
  24. const deletePath = (path: Path) => {
  25. const index = props.paths.indexOf(path);
  26. props.paths.splice(index, 1);
  27. };
  28. const updatePosition = (ndx: number, data: Path["points"]) => {
  29. props.paths[ndx].points = data;
  30. };
  31. const updateLinePosition = (ndx: number, linePosition: Path["linePosition"]) => {
  32. if (props.paths[ndx].linePosition) {
  33. Object.assign(props.paths[ndx].linePosition, linePosition);
  34. } else {
  35. props.paths[ndx].linePosition = linePosition;
  36. }
  37. };
  38. const nodeHandler = (index: number, node: any) => {
  39. if (index < props.paths.length) {
  40. nodes[index] = { node, id: props.paths[index].id };
  41. }
  42. };
  43. defineExpose(nodes);
  44. </script>