Graph.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="container">
  3. <div :class="['graph', {active: isDragging}]"
  4. @drop="addNode"
  5. @dragover.prevent
  6. >
  7. <svg width="100%" height="418">
  8. <defs>
  9. <marker id="end-arrow" viewBox="0 -5 10 10" refX="42" markerWidth="5" markerHeight="5" orient="auto">
  10. <path d="M0,-5 L10,0 L0,5"></path>
  11. </marker>
  12. <marker id="mark-end-arrow" viewBox="0 -5 10 10" refX="7" markerWidth="5" markerHeight="5" orient="auto">
  13. <path d="M0,-5 L10,0 L0,5"></path>
  14. </marker>
  15. <marker id="arrow" markerWidth="12" markerHeight="12" viewBox="0 0 14 14" refX="30" refY="6" orient="auto">
  16. <path d="M2,2 L10,6 L2,10 L6,6 L2,2"/>
  17. </marker>
  18. </defs>
  19. <g class="graph">
  20. <g>
  21. <path class="link" d="M143,85L363,124" marker-end="url(#arrow)"></path>
  22. </g>
  23. <g>
  24. <g class="conceptG" transform="translate(143,85)">
  25. <circle r="33"></circle>
  26. <text text-anchor="middle">
  27. <tspan>普通活动</tspan>
  28. </text>
  29. </g>
  30. <g class="conceptG" transform="translate(363,124)">
  31. <circle r="34"></circle>
  32. <text text-anchor="middle">
  33. <tspan>普通活动</tspan>
  34. </text>
  35. </g>
  36. <g v-for="node in nodes"
  37. :key="node.id"
  38. class="conceptG"
  39. :transform="'translate('+node.x+','+node.y+')'"
  40. >
  41. <circle r="34"></circle>
  42. <text text-anchor="middle">
  43. <tspan>{{node.name}}</tspan>
  44. </text>
  45. </g>
  46. </g>
  47. </g>
  48. </svg>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. var nodeId = 3
  54. export default {
  55. data () {
  56. return {
  57. nodes: [
  58. {id: 1, name: '普通活动', x: 200, y: 200},
  59. {id: 2, name: '普通活动', x: 300, y: 300}
  60. ]
  61. }
  62. },
  63. props: {
  64. isDragging: {
  65. type: Boolean,
  66. require: true
  67. }
  68. },
  69. methods: {
  70. addNode: function (e) {
  71. var jsonStr = e.dataTransfer.getData('item')
  72. var jsonObj = JSON.parse(jsonStr)
  73. this.nodes.push({
  74. id: nodeId++,
  75. name: jsonObj.name,
  76. x: e.x - 165,
  77. y: e.y - 53
  78. })
  79. }
  80. }
  81. }
  82. </script>
  83. <style scoped>
  84. .container {
  85. height: 80%;
  86. padding: 4px;
  87. }
  88. .graph {
  89. height: 100%;
  90. border: 1px solid transparent;
  91. background: url('../assets/wf_edit_bg.gif');
  92. }
  93. .graph.active {
  94. border: 1px dashed #5cdc5c;
  95. }
  96. svg {
  97. height: 100%;
  98. }
  99. marker {
  100. fill: #3c39f2;
  101. }
  102. g.conceptG circle {
  103. fill: #F6FBFF;
  104. stroke: #6164c1;
  105. stroke-width: 1px;
  106. }
  107. g.conceptG:hover circle {
  108. fill: rgb(200, 238, 241);
  109. }
  110. g.selected circle {
  111. fill: #e8d0ef;
  112. stroke: #9b78d3;
  113. stroke-width: 1.5px;
  114. }
  115. g.selected:hover circle {
  116. fill: #e8d0ef;
  117. }
  118. g.conceptG text {
  119. font-size: 12px;
  120. fill: #151996;
  121. }
  122. path.link {
  123. fill: none;
  124. stroke: #a6a6f2;
  125. stroke-width: 2px;
  126. cursor: default;
  127. }
  128. path.link:hover {
  129. stroke: rgb(94, 196, 204) !important;
  130. }
  131. </style>