index.vue 2.8 KB

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