index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div class="workflow">
  3. <TeleportContainer />
  4. <div class="workflow-chart">
  5. <workflowChart :data="state.workflowData" ref="ref_workflow" />
  6. </div>
  7. <div class="operations">
  8. <div>
  9. <div
  10. class="__hover-bg"
  11. @click="WorkflowStore.$patch((s: any) => (s.envVars.show = true))"
  12. >
  13. <SvgIcon name="env" />
  14. </div>
  15. </div>
  16. <a-button type="primary" @click="getJsonData">保存配置</a-button>
  17. </div>
  18. <div class="panel">
  19. <workflowPanel />
  20. <envVarsPanel />
  21. </div>
  22. </div>
  23. </template>
  24. <script setup lang="ts">
  25. import { getCurrentInstance, onMounted, provide, reactive, ref } from 'vue'
  26. import workflowChart from './chart/index.vue'
  27. import workflowPanel from './chart/panel-index.vue'
  28. import envVarsPanel from './instance/component/vars/evn-index.vue'
  29. import { getTeleport } from '@antv/x6-vue-shape'
  30. import { data0, data1 } from './mockJson'
  31. import { useWorkflowStore } from '@/stores'
  32. import {
  33. workflowDraftDetail,
  34. workflowDraftSave,
  35. } from '@/api/modules/workflow/chart'
  36. const TeleportContainer = getTeleport()
  37. const WorkflowStore = useWorkflowStore()
  38. const emit = defineEmits([])
  39. const props = defineProps({
  40. ID: {},
  41. })
  42. const { proxy }: any = getCurrentInstance()
  43. const state: any = reactive({
  44. workflowData: null,
  45. })
  46. const ref_workflow = ref()
  47. const getJsonData = () => {
  48. const data = ref_workflow.value.toJSON()
  49. const offset = WorkflowStore.graph.translate()
  50. const res: any = {
  51. envVars: WorkflowStore.envVars.vars,
  52. graph: {
  53. nodes: [],
  54. edges: [],
  55. viewport: {
  56. zoom: WorkflowStore.graph.zoom(),
  57. x: offset.tx,
  58. y: offset.ty,
  59. },
  60. },
  61. }
  62. JSON.parse(JSON.stringify(data.cells)).forEach((cell: any) => {
  63. if (cell.shape === 'workflow-node') {
  64. const node: any = {
  65. id: cell.id,
  66. x: cell.position.x,
  67. y: cell.position.y,
  68. data: cell.data.workflowData,
  69. }
  70. delete node.data.edgeSource
  71. delete node.data.inVars
  72. res.graph.nodes.push(node)
  73. } else if (cell.shape === 'edge') {
  74. const edge: any = {
  75. target: cell.target.cell,
  76. source: cell.source.cell,
  77. }
  78. if (!cell.source.port.includes('end')) {
  79. edge.port = cell.source.port
  80. }
  81. res.graph.edges.push(edge)
  82. }
  83. })
  84. console.log(res)
  85. }
  86. const initData = () => {
  87. workflowDraftDetail(props.ID)
  88. const d = data0
  89. WorkflowStore.$patch((s: any) => (s.envVars.vars = d.envVars || []))
  90. state.workflowData = d.graph
  91. }
  92. onMounted(() => {
  93. initData()
  94. })
  95. </script>
  96. <style lang="scss" scoped>
  97. .workflow {
  98. width: 100%;
  99. height: 100%;
  100. display: flex;
  101. align-items: center;
  102. justify-content: center;
  103. position: relative;
  104. position: relative;
  105. .workflow-chart {
  106. width: 100%;
  107. height: 100%;
  108. z-index: 1;
  109. }
  110. .operations {
  111. position: absolute;
  112. top: 10px;
  113. right: 10px;
  114. z-index: 2;
  115. display: flex;
  116. align-items: center;
  117. gap: 10px;
  118. > div {
  119. display: flex;
  120. align-items: center;
  121. background-color: rgba(255, 255, 255, 0.95);
  122. box-shadow: 0 0px 8px rgba(0, 0, 0, 0.1);
  123. border-radius: 6px;
  124. padding: 4px;
  125. > div {
  126. min-width: 24px;
  127. height: 24px;
  128. display: flex;
  129. align-items: center;
  130. justify-content: center;
  131. }
  132. }
  133. }
  134. .panel {
  135. z-index: 2;
  136. position: absolute;
  137. right: 0;
  138. bottom: 0;
  139. display: flex;
  140. gap: 10px;
  141. height: calc(100% - 10px - 32px - 10px);
  142. }
  143. }
  144. </style>