index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <g>
  3. <!-- 圆形markStart -->
  4. <circle
  5. :cx="props.sourceX"
  6. :cy="props.sourceY - 4"
  7. r="4"
  8. :fill="status ? 'gray' : 'black'"
  9. />
  10. <!-- path -->
  11. <path
  12. :d="path"
  13. fill="none"
  14. :stroke="status ? 'gray' : 'black'"
  15. stroke-width="2"
  16. />
  17. <!-- 箭头markEnd -->
  18. <path
  19. :d="`M ${targetX} ${targetY + 2} L ${targetX - 5} ${targetY - 10} L ${targetX + 5} ${targetY - 10} Z`"
  20. :fill="status ? 'gray' : 'black'"
  21. stroke="none"
  22. />
  23. </g>
  24. </template>
  25. <script lang="ts" setup>
  26. import { getSmoothStepPath, SmoothStepEdgeProps } from "@vue-flow/core";
  27. import { computed, inject } from "vue";
  28. const selectLine = inject("selectLine");
  29. const status = ref(true);
  30. const props = defineProps<SmoothStepEdgeProps>();
  31. const path = computed(() => getSmoothStepPath(props)[0]);
  32. const setSeletedStatus = () => {
  33. if (selectLine.value != null) {
  34. if (props.id == selectLine.value.id) {
  35. status.value = false;
  36. } else {
  37. status.value = true;
  38. }
  39. } else {
  40. status.value = true;
  41. }
  42. };
  43. watch(
  44. () => selectLine.value,
  45. () => {
  46. setSeletedStatus();
  47. },
  48. { deep: true }
  49. );
  50. function getArrowTransform(props: SmoothStepEdgeProps) {
  51. const { targetPosition } = props;
  52. if (targetPosition === "top") {
  53. return `rotate(0 ${props.targetX} ${props.targetY})`;
  54. }
  55. if (targetPosition === "bottom") {
  56. return `rotate(180 ${props.targetX} ${props.targetY})`;
  57. }
  58. if (targetPosition === "left") {
  59. return `rotate(-90 ${props.targetX} ${props.targetY})`;
  60. }
  61. if (targetPosition === "right") {
  62. return `rotate(90 ${props.targetX} ${props.targetY})`;
  63. }
  64. }
  65. </script>
  66. <script lang="ts">
  67. export default {
  68. name: "Custom",
  69. };
  70. </script>