import{_ as i,o as a,c as e,a3 as t}from"./chunks/framework.BNdm2jZV.js";const c=JSON.parse('{"title":"RFlow 与 useFlow","description":"","frontmatter":{},"headers":[],"relativePath":"reference/components/flow.md","filePath":"reference/components/flow.md"}'),n={name:"reference/components/flow.md"};function l(d,s,h,p,k,o){return a(),e("div",null,[...s[0]||(s[0]=[t(`

RFlow 与 useFlow ​

RFlow 在自己的 DOM 容器中建立 LogicFlow。图数据用 FlowGraphData 表示,nodes 和 edges 为可选数组;NodeConfig、EdgeConfig 都要求稳定的 id,边的源和目标需指向存在的节点。

tsx
import { RFlow } from '@/components'
import type LogicFlow from '@logicflow/core'
import { defineComponent } from 'vue'

const graph = {
  nodes: [
    { id: 'start', type: 'rect', x: 100, y: 90, text: '发起' },
    { id: 'review', type: 'rect', x: 300, y: 90, text: '审核' },
  ],
  edges: [
    {
      id: 'start-review',
      type: 'polyline',
      sourceNodeId: 'start',
      targetNodeId: 'review',
    },
  ],
} satisfies Parameters<LogicFlow['render']>[0]

export default defineComponent({
  setup: () => () => (
    <RFlow
      height={240}
      readonly
      onRegister={(instance) => instance.render(graph)}
    />
  ),
})
属性默认说明
width / height'100%'容器尺寸,需要可计算的高度。
data无后续引用变化时重绘,嵌套原地修改不触发。当前挂载分支先渲染空图,首屏请在 onRegister 里主动渲染。
watchDatatrue是否监听传入数据。关闭后可从实例控制重绘。
readonlyfalse同步 LogicFlow 静默模式和节点、边文本编辑状态。
options网格开、partial: false、键盘开LogicFlow 初始化配置,包括尺寸、背景、键盘、边、交互、历史和插件等。container 由组件管理。
use无LogicFlow 全局插件列表,组件只在首次初始化时注册一次。需要实例级插件时检查 options.plugins。
onRegister(instance)无挂载后取得 LogicFlow,支持回调数组。

FlowOptions 支持的字段按用途分组:

FlowGraphData 用于包装组件的 Props。直接调用底层 instance.render 时,使用 Parameters<LogicFlow['render']>[0] 保留 LogicFlow 所要求的节点类型、坐标和连线字段。

useFlow() 返回 [register, { getFlowInstance }]。若首屏要填图,可在同一 onRegister 回调里先调用 register(instance) 再 instance.render(graph)。注册之前调用 getFlowInstance() 会抛错。程序化编辑、导入和事件监听走 LogicFlow 实例;组件目前没有公开销毁方法或卸载时的显式实例清理,频繁重挂载或绑定自定义监听时,请由接入方处理对应资源释放。

组件实现 · 图和选项类型 · 实例 Hook

`,9)])])}const E=i(n,[["render",l]]);export{c as __pageData,E as default};