index.vue 3.3 KB

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