Vue-flow中动态流程图的实现

一、实现

在Vue-flow官网中,关于动态流程图的部分长这样

他可以让你的流程变得可动,更加容易理解

Examples中提供了各个文件的代码以及importMap,但是当我复制文件过来之后发现无法渲染,控制台报警告

我们只需要在index.vue中引入

复制代码
import '@vue-flow/core/dist/style.css'

二、修改为自定义样式

在官方例子中,根节点长这样,如果我们想要将根节点中的图标修改为字符串,我们只需要在ProcessNode.vue中将processLabel计算属性修改,如下

javascript 复制代码
const processLabel = computed(() => {
  if (isStartNode.value) {
    return 'node'
  }

  switch (status.value) {
    case ProcessStatus.ERROR:
      return 'faild'
    case ProcessStatus.SKIPPED:
      return '🚧'
    case ProcessStatus.CANCELLED:
      return '🚫'
    case ProcessStatus.FINISHED:
      return '😎'
    default:
      return '🏠'
  }
})

下面switch中的几个case分别对应各个节点根据状态不同显示的图案(字符串)

而bgColor则代表各个节点更具不同状态显示的背景颜色

javascript 复制代码
const bgColor = computed(() => {
  if (isStartNode.value) {
    return '#2563eb'
  }

  switch (status.value) {
    case ProcessStatus.ERROR:
      return '#f87171'
    case ProcessStatus.FINISHED:
      return '#42B983'
    case ProcessStatus.CANCELLED:
      return '#fbbf24'
    default:
      return '#4b5563'
  }
})

如果想要去除右上角控制器,只需要在index.vue中删除<Panel>标签中的内容

html 复制代码
      <Panel class="process-panel" position="top-right">
        <div class="layout-panel">
          <button v-if="isRunning" class="stop-btn" title="stop" @click="stop">
            <Icon name="stop" />
            <span class="spinner" />
          </button>
          <button v-else title="start" @click="run(nodes)">
            <Icon name="play" />
          </button>

          <button title="set horizontal layout" @click="layoutGraph('LR')">
            <Icon name="horizontal" />
          </button>

          <button title="set vertical layout" @click="layoutGraph('TB')">
            <Icon name="vertical" />
          </button>
        </div>

        <div class="checkbox-panel">
          <label>Cancel on error</label>
          <input v-model="cancelOnError" type="checkbox" />
        </div>
      </Panel>

整个流程的开启函数则是在useRunProcess.js中修改,在index.vue中通过run(nodes)调用

相关推荐
烛阴1 天前
为什么游戏开发者都爱 Lua?零基础快速上手指南
前端·lua
大猫会长1 天前
tailwindcss出现could not determine executable to run
前端·tailwindcss
Moonbit1 天前
MoonBit Pearls Vol.10:prettyprinter:使用函数组合解决结构化数据打印问题
前端·后端·程序员
533_1 天前
[css] border 渐变
前端·css
云中雾丽1 天前
flutter的dart语言和JavaScript的消息循环机制的异同
前端
地方地方1 天前
Vue依赖注入:provide/inject 问题解析与最佳实践
前端·javascript·面试
云中雾丽1 天前
dart的继承和消息循环机制
前端
世界哪有真情1 天前
Trae 蓝屏问题
前端·后端·trae
Moment1 天前
NestJS 在 2025 年:对于后端开发者仍然值得吗 😕😕😕
前端·后端·github
热心市民小岳1 天前
Konva.js 实现 腾讯文档 多维表格
前端·javascript