index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. <DataDialog :graphData="graphData"></DataDialog>
  75. </el-dialog>
  76. </div>
  77. </template>
  78. <style scoped>
  79. #LF-Turbo {
  80. width: 100vw;
  81. height: 88.5vh;
  82. outline: none;
  83. }
  84. .logic-flow-view {
  85. margin: 10px;
  86. position: relative;
  87. }
  88. .demo-title {
  89. text-align: center;
  90. margin: 20px;
  91. }
  92. .demo-control {
  93. position: absolute;
  94. top: 10px;
  95. right: 20px;
  96. z-index: 2;
  97. }
  98. .time-plus {
  99. cursor: pointer;
  100. }
  101. .add-panel {
  102. position: absolute;
  103. z-index: 11;
  104. background-color: white;
  105. padding: 10px 5px;
  106. }
  107. .el-drawer__body {
  108. height: 80%;
  109. overflow: auto;
  110. margin-top: -30px;
  111. z-index: 3;
  112. }
  113. :deep(.flow-dialog) {
  114. transform: none;
  115. left: 0;
  116. position: relative;
  117. margin: 0 auto;
  118. }
  119. </style>