index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div class="workflow">
  3. <TeleportContainer/>
  4. <el-button style="position: absolute; top: 0;left: 0; z-index: 2" type="primary" @click="getJsonData">保存配置</el-button>
  5. <div class="workflow-chart">
  6. <workflowChart :data="state.workflowData" ref="ref_workflow" @init="graph => state.graph = graph"/>
  7. </div>
  8. <workflowPanel v-model:show="state.showPanel" :node="state.currentNode"/>
  9. </div>
  10. </template>
  11. <script setup lang="ts">
  12. import {getCurrentInstance, onMounted, provide, reactive, ref} from "vue";
  13. import workflowChart from './chart/index.vue'
  14. import workflowPanel from './chart/panel-index.vue'
  15. import { getTeleport } from '@antv/x6-vue-shape'
  16. import {data1, data2} from './mockJson'
  17. import {WorkflowFunc} from "@/views/workflow/types";
  18. const TeleportContainer = getTeleport()
  19. const emits = defineEmits([])
  20. const props = defineProps({})
  21. const {proxy}: any = getCurrentInstance()
  22. const state: any = reactive({
  23. workflowData: null,
  24. showPanel: false,
  25. currentNode: null,
  26. graph: null
  27. })
  28. const ref_workflow = ref()
  29. provide('workflowFunc', <WorkflowFunc>{
  30. nodeClick: (node) => {
  31. state.currentNode = node
  32. state.showPanel = true
  33. },
  34. layoutPort: (nodeId: string, portId: string) => {
  35. const dom = document.getElementById(portId)
  36. if (dom) {
  37. const node = state.graph.getCellById(nodeId)
  38. node.portProp(portId, ['args', 'dy'], dom.offsetTop + 17)
  39. }
  40. }
  41. })
  42. const getJsonData = () => {
  43. const data = ref_workflow.value.toJSON()
  44. console.log(data)
  45. const res: any = {
  46. nodes: [],
  47. edges: []
  48. }
  49. data.cells.forEach((cell: any) => {
  50. if (cell.shape === 'workflow-node') {
  51. const node: any = {
  52. id: cell.id,
  53. x: cell.position.x,
  54. y: cell.position.y,
  55. data: cell.data
  56. }
  57. res.nodes.push(node)
  58. } else if (cell.shape === 'edge') {
  59. const edge: any = {
  60. target: cell.target.cell,
  61. source: cell.source.cell,
  62. }
  63. if (!cell.source.port.includes('end')) {
  64. edge.port = cell.source.port
  65. }
  66. res.edges.push(edge)
  67. }
  68. })
  69. console.log(res)
  70. }
  71. const initData = () => {
  72. state.workflowData = data1
  73. }
  74. onMounted(() => {
  75. initData()
  76. })
  77. </script>
  78. <style lang="scss" scoped>
  79. .workflow {
  80. width: 100%;
  81. height: 100%;
  82. display: flex;
  83. align-items: center;
  84. justify-content: center;
  85. position: relative;
  86. .workflow-chart {
  87. width: 100%;
  88. height: 100%;
  89. z-index: 1;
  90. }
  91. }
  92. </style>