index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <script setup lang="ts">
  2. import demoData from "./dataTurbo.json";
  3. import "@logicflow/core/dist/style/index.css";
  4. import "@logicflow/extension/lib/style/index.css";
  5. import LogicFlow from "@logicflow/core";
  6. import { ref, unref, onMounted } from "vue";
  7. import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
  8. import { BpmnNode } from "/@/components/ReFlowChart/src/config";
  9. import { Snapshot, BpmnElement, Menu } from "@logicflow/extension";
  10. import { Control, NodePanel, DataDialog } from "/@/components/ReFlowChart";
  11. import { toLogicflowData } from "/@/components/ReFlowChart/src/adpterForTurbo";
  12. defineOptions({
  13. name: "FlowChart"
  14. });
  15. let lf = ref(null);
  16. let graphData = ref(null);
  17. let dataVisible = ref<boolean>(false);
  18. let config = ref({
  19. grid: true,
  20. background: {
  21. color: "#f7f9ff"
  22. },
  23. keyboard: {
  24. enabled: true
  25. }
  26. });
  27. let nodeList = BpmnNode;
  28. function initLf() {
  29. // 画布配置
  30. LogicFlow.use(Snapshot);
  31. // 使用bpmn插件,引入bpmn元素,这些元素可以在turbo中转换后使用
  32. LogicFlow.use(BpmnElement);
  33. // 启动右键菜单
  34. LogicFlow.use(Menu);
  35. const domLf = new LogicFlow({
  36. ...unref(config),
  37. container: document.querySelector("#LF-Turbo")
  38. });
  39. lf.value = domLf;
  40. // 设置边类型bpmn:sequenceFlow为默认类型
  41. unref(lf).setDefaultEdgeType("bpmn:sequenceFlow");
  42. onRender();
  43. }
  44. function onRender() {
  45. // Turbo数据转换为LogicFlow内部识别的数据结构
  46. const lFData = toLogicflowData(demoData);
  47. lf.value.render(lFData);
  48. }
  49. function catData() {
  50. graphData.value = unref(lf).getGraphData();
  51. dataVisible.value = true;
  52. }
  53. onMounted(() => {
  54. initLf();
  55. });
  56. </script>
  57. <template>
  58. <el-card>
  59. <template #header>
  60. <div class="card-header">
  61. <span class="font-medium">
  62. 流程图组件,采用开源的
  63. <el-link
  64. href="http://logic-flow.org/"
  65. target="_blank"
  66. :icon="useRenderIcon('set-up')"
  67. style="font-size: 16px; margin: 0 4px 5px"
  68. >
  69. LogicFlow
  70. </el-link>
  71. </span>
  72. </div>
  73. </template>
  74. <div class="logic-flow-view">
  75. <!-- 辅助工具栏 -->
  76. <Control
  77. class="demo-control"
  78. v-if="lf"
  79. :lf="lf"
  80. :catTurboData="false"
  81. @catData="catData"
  82. />
  83. <!-- 节点面板 -->
  84. <NodePanel :lf="lf" :nodeList="nodeList" />
  85. <!-- 画布 -->
  86. <div id="LF-Turbo" />
  87. <!-- 数据查看面板 -->
  88. <el-dialog
  89. customClass="flow-dialog"
  90. title="数据"
  91. v-model="dataVisible"
  92. width="50%"
  93. >
  94. <el-scrollbar>
  95. <DataDialog :graphData="graphData" />
  96. </el-scrollbar>
  97. </el-dialog>
  98. </div>
  99. </el-card>
  100. </template>
  101. <style scoped>
  102. #LF-Turbo {
  103. width: 100%;
  104. height: 70vh;
  105. }
  106. .logic-flow-view {
  107. margin: 10px;
  108. position: relative;
  109. }
  110. .demo-title {
  111. text-align: center;
  112. margin: 20px;
  113. }
  114. .demo-control {
  115. position: absolute;
  116. top: 10px;
  117. right: 20px;
  118. z-index: 2;
  119. }
  120. .time-plus {
  121. cursor: pointer;
  122. }
  123. .add-panel {
  124. position: absolute;
  125. z-index: 11;
  126. background-color: white;
  127. padding: 10px 5px;
  128. }
  129. .el-drawer__body {
  130. height: 80%;
  131. overflow: auto;
  132. margin-top: -30px;
  133. z-index: 3;
  134. }
  135. :deep(.flow-dialog) {
  136. transform: none;
  137. left: 0;
  138. top: 5vh;
  139. position: relative;
  140. margin: 0 auto;
  141. }
  142. :deep(.flow-dialog) .el-dialog__body {
  143. height: 85vh;
  144. overflow: auto;
  145. }
  146. </style>