list.vue 1.4 KB

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