mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-27 06:53:36 +08:00
29 lines
12 KiB
JavaScript
29 lines
12 KiB
JavaScript
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(`<h1 id="rflow-与-useflow" tabindex="-1">RFlow 与 useFlow <a class="header-anchor" href="#rflow-与-useflow" aria-label="Permalink to "RFlow 与 useFlow""></a></h1><p><code>RFlow</code> 在自己的 DOM 容器中建立 LogicFlow。图数据用 <code>FlowGraphData</code> 表示,<code>nodes</code> 和 <code>edges</code> 为可选数组;<code>NodeConfig</code>、<code>EdgeConfig</code> 都要求稳定的 <code>id</code>,边的源和目标需指向存在的节点。</p><div class="language-tsx vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">tsx</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { RFlow } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> '@/components'</span></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> type</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> LogicFlow </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> '@logicflow/core'</span></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { defineComponent } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> 'vue'</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> graph</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> nodes: [</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { id: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'start'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, type: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'rect'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, x: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">100</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">90</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, text: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'发起'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { id: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'review'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, type: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'rect'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, x: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">300</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, y: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">90</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, text: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'审核'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ],</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> edges: [</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> id: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'start-review'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> type: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'polyline'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sourceNodeId: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'start'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> targetNodeId: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'review'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> },</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ],</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">} </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">satisfies</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> Parameters</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"><</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">LogicFlow</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">'render'</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]>[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> default</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> defineComponent</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">({</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setup</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: () </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> () </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> <</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">RFlow</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> height</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">240</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> readonly</span></span>
|
||
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> onRegister</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">instance</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=></span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> instance.</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">render</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(graph)}</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> /></span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ),</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span></span></code></pre></div><table tabindex="0"><thead><tr><th>属性</th><th>默认</th><th>说明</th></tr></thead><tbody><tr><td><code>width</code> / <code>height</code></td><td><code>'100%'</code></td><td>容器尺寸,需要可计算的高度。</td></tr><tr><td><code>data</code></td><td>无</td><td>后续引用变化时重绘,嵌套原地修改不触发。当前挂载分支先渲染空图,首屏请在 <code>onRegister</code> 里主动渲染。</td></tr><tr><td><code>watchData</code></td><td><code>true</code></td><td>是否监听传入数据。关闭后可从实例控制重绘。</td></tr><tr><td><code>readonly</code></td><td><code>false</code></td><td>同步 LogicFlow 静默模式和节点、边文本编辑状态。</td></tr><tr><td><code>options</code></td><td>网格开、<code>partial: false</code>、键盘开</td><td>LogicFlow 初始化配置,包括尺寸、背景、键盘、边、交互、历史和插件等。<code>container</code> 由组件管理。</td></tr><tr><td><code>use</code></td><td>无</td><td>LogicFlow 全局插件列表,组件只在首次初始化时注册一次。需要实例级插件时检查 <code>options.plugins</code>。</td></tr><tr><td><code>onRegister(instance)</code></td><td>无</td><td>挂载后取得 LogicFlow,支持回调数组。</td></tr></tbody></table><p><code>FlowOptions</code> 支持的字段按用途分组:</p><ul><li>画布与布局:<code>width</code>、<code>height</code>、<code>background</code>、<code>grid</code>、<code>partial</code>、<code>style</code>、<code>overlapMode</code>。</li><li>交互:<code>keyboard</code>、<code>adjustEdge</code>、<code>allowRotate</code>、<code>allowResize</code>、<code>isSilentMode</code>、<code>stopScrollGraph</code>、<code>stopZoomGraph</code>、<code>stopMoveGraph</code>、<code>textEdit</code>、<code>textMode</code>、<code>edgeTextMode</code>、<code>nodeTextMode</code>、<code>guards</code>。</li><li>边和渲染:<code>edgeType</code>、<code>customTrajectory</code>、<code>animation</code>、<code>history</code>、<code>outline</code>、<code>snapline</code>。</li><li>扩展:<code>plugins</code>、<code>pluginsOptions</code>、<code>disabledPlugins</code>、<code>disabledTools</code>、<code>idGenerator</code>、<code>edgeGenerator</code>。</li></ul><p><code>FlowGraphData</code> 用于包装组件的 Props。直接调用底层 <code>instance.render</code> 时,使用 <code>Parameters<LogicFlow['render']>[0]</code> 保留 LogicFlow 所要求的节点类型、坐标和连线字段。</p><p><code>useFlow()</code> 返回 <code>[register, { getFlowInstance }]</code>。若首屏要填图,可在同一 <code>onRegister</code> 回调里先调用 <code>register(instance)</code> 再 <code>instance.render(graph)</code>。注册之前调用 <code>getFlowInstance()</code> 会抛错。程序化编辑、导入和事件监听走 LogicFlow 实例;组件目前没有公开销毁方法或卸载时的显式实例清理,频繁重挂载或绑定自定义监听时,请由接入方处理对应资源释放。</p><p><a href="https://github.com/XiaoDaiGua-Ray/ray-template/blob/403fdd589abbe37b38e1240d34f8daf2a60d3690/packages/ui/src/RFlow/src/Flow.tsx" target="_blank" rel="noreferrer">组件实现</a> · <a href="https://github.com/XiaoDaiGua-Ray/ray-template/blob/403fdd589abbe37b38e1240d34f8daf2a60d3690/packages/ui/src/RFlow/src/types.ts" target="_blank" rel="noreferrer">图和选项类型</a> · <a href="https://github.com/XiaoDaiGua-Ray/ray-template/blob/403fdd589abbe37b38e1240d34f8daf2a60d3690/packages/ui/src/RFlow/src/hooks/useFlow.ts" target="_blank" rel="noreferrer">实例 Hook</a></p>`,9)])])}const E=i(n,[["render",l]]);export{c as __pageData,E as default};
|