simulateArrow.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <!-- 模拟剪头拖动效果 -->
  2. <template>
  3. <g>
  4. <path
  5. class="connector only-watch-el"
  6. :d="dragLinkPath()"
  7. ></path>
  8. <circle :cx="this.dragLink.fromX" :cy="this.dragLink.fromY" r="5"
  9. style="stroke:#006600;
  10. stroke-width: 2;
  11. fill:#CCCCCC"/>
  12. <polyline class="only-watch-el" :points="computedArrow()"
  13. style="stroke:#006600;"/>
  14. </g>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. dragLink: {
  20. type: Object
  21. }
  22. },
  23. methods: {
  24. dragLinkPath() {
  25. const { fromX, fromY, toX, toY } = this.dragLink;
  26. if (this.isVertical()) {
  27. return `M ${fromX} ${fromY} Q ${fromX} ${fromY + 50} ${(toX + fromX) /
  28. 2} ${(fromY + toY) / 2} T ${toX} ${toY}`;
  29. } else {
  30. return `M ${fromX} ${fromY} Q ${fromX + 30} ${fromY} ${(toX + fromX) /
  31. 2} ${(fromY + toY) / 2} T ${toX} ${toY}`;
  32. }
  33. },
  34. computedArrow() {
  35. // 计算箭头坐标
  36. const { toX, toY } = this.dragLink;
  37. if (this.isVertical()) {
  38. return `${toX} ${toY} ${toX - 3} ${toY - 6} ${toX + 3} ${toY - 6}`;
  39. } else {
  40. return `${toX - 3} ${toY + 3} ${toX} ${toY} ${toX - 3} ${toY - 3}`;
  41. }
  42. },
  43. isVertical() {
  44. let GlobalConfig = { isVertical: true }
  45. let _GlobalConfig = localStorage.getItem('GlobalConfig')
  46. if (_GlobalConfig && _GlobalConfig.length > 0) {
  47. GlobalConfig = Object.assign(GlobalConfig, JSON.parse(_GlobalConfig))
  48. }
  49. return GlobalConfig.isVertical
  50. }
  51. }
  52. };
  53. </script>
  54. <style scoped>
  55. .connector {
  56. stroke: hsla(0, 0%, 50%, 0.6);
  57. stroke-width: 2px;
  58. fill: none;
  59. }
  60. .only-watch-el {
  61. pointer-events: none;
  62. }
  63. .dragLinkArrows {
  64. border-top: 4px solid black;
  65. border-left: 4px solid transparent;
  66. border-right: 4px solid transparent;
  67. z-index: -10;
  68. }
  69. </style>