index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. <el-link
  72. class="mt-2"
  73. href="https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/flow-chart"
  74. target="_blank"
  75. >
  76. 代码位置 src/views/flow-chart
  77. </el-link>
  78. </template>
  79. <div class="logic-flow-view">
  80. <!-- 辅助工具栏 -->
  81. <Control
  82. v-if="lf"
  83. class="demo-control"
  84. :lf="lf"
  85. :catTurboData="false"
  86. @catData="catData"
  87. />
  88. <!-- 节点面板 -->
  89. <NodePanel v-if="lf" :lf="lf" :nodeList="nodeList" />
  90. <!-- 画布 -->
  91. <div id="turbo" />
  92. <!-- 数据查看面板 -->
  93. <el-dialog
  94. v-model="dataVisible"
  95. class="flow-dialog"
  96. title="数据"
  97. width="50%"
  98. >
  99. <el-scrollbar>
  100. <DataDialog :graphData="graphData" />
  101. </el-scrollbar>
  102. </el-dialog>
  103. </div>
  104. </el-card>
  105. </template>
  106. <style scoped>
  107. #turbo {
  108. width: 100%;
  109. height: 65vh;
  110. }
  111. .logic-flow-view {
  112. position: relative;
  113. margin: 10px;
  114. }
  115. .demo-title {
  116. margin: 20px;
  117. text-align: center;
  118. }
  119. .demo-control {
  120. position: absolute;
  121. top: 10px;
  122. right: 20px;
  123. z-index: 2;
  124. }
  125. .time-plus {
  126. cursor: pointer;
  127. }
  128. .add-panel {
  129. position: absolute;
  130. z-index: 11;
  131. padding: 10px 5px;
  132. background-color: white;
  133. }
  134. .el-drawer__body {
  135. z-index: 3;
  136. height: 80%;
  137. margin-top: -30px;
  138. overflow: auto;
  139. }
  140. :deep(.flow-dialog) {
  141. position: relative;
  142. top: 5vh;
  143. left: 0;
  144. margin: 0 auto;
  145. transform: none;
  146. }
  147. :deep(.flow-dialog) .el-dialog__body {
  148. height: 85vh;
  149. overflow: auto;
  150. }
  151. </style>