vueFlow2.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <style lang="scss" scoped>
  2. .container{
  3. height: 100%;
  4. }
  5. .my-flow {
  6. margin: 10px;
  7. height: 700px;
  8. // :deep(.node-light) {
  9. // background: none;
  10. // }
  11. // :deep(.node-dark) {
  12. // background: #eeeeee;
  13. // }
  14. }
  15. </style>
  16. <template>
  17. <div class="container">
  18. <el-row class="mb-4">
  19. <el-button type="primary" @click="resetTransform">重置</el-button>
  20. </el-row>
  21. <VueFlow
  22. fit-view-on-init
  23. class="my-flow"
  24. v-model="elements"
  25. >
  26. <Background />
  27. <Panel :position="PanelPosition.TopRight">
  28. <button type="button" @click="addRandomNode('办理')">办理</button>
  29. <button type="button" style="margin-left:10px" @click="addRandomNode('分支')">分支</button>
  30. <button type="button" style="margin-left:10px" @click="addRandomNode('结束')">结束</button>
  31. </Panel>
  32. <!-- <Controls /> -->
  33. </VueFlow>
  34. </div>
  35. </template>
  36. <script lang="ts" setup name="DemoBpmn">
  37. import '@vue-flow/core/dist/style.css'
  38. /* import the default theme (optional) */
  39. import '@vue-flow/core/dist/theme-default.css'
  40. import {
  41. Background,
  42. Panel,
  43. PanelPosition,
  44. Controls,
  45. } from '@vue-flow/additional-components'
  46. import { VueFlow, useVueFlow } from '@vue-flow/core'
  47. import { ref, watch } from 'vue'
  48. import { ElMessage } from 'element-plus'
  49. const data = [
  50. { id: '1', type: 'input', label: '开始', position: { x: 250, y: 5 } },
  51. ]
  52. let elements = ref(data)
  53. const isHidden = ref(false)
  54. let {
  55. onPaneReady,
  56. onNodeDragStop,
  57. onConnect,
  58. addEdges,
  59. setTransform,
  60. toObject,
  61. nodes,
  62. edges,
  63. applyNodeChanges,
  64. dimensions,
  65. addNodes
  66. } = useVueFlow()
  67. function addRandomNode(_name) {
  68. const nodeId = (nodes.value.length + 1).toString()
  69. const newNode = {
  70. id: nodeId,
  71. label: _name,
  72. position: { x: 250, y: 100 }
  73. }
  74. addNodes([newNode])
  75. }
  76. watch(isHidden, () => {
  77. nodes.value.forEach((n) => (n.hidden = isHidden.value))
  78. edges.value.forEach((e) => (e.hidden = isHidden.value))
  79. })
  80. onPaneReady(({ fitView }) => {
  81. fitView()
  82. })
  83. onNodeDragStop((e) => {
  84. })
  85. onConnect((params) => addEdges([params]))
  86. const resetTransform = () => {
  87. elements.value = data
  88. setTransform({ x: 0, y: 0, zoom: 1 })
  89. }
  90. </script>