Skip to content

节点规范

本文档详细描述 MdrFrontEngine 节点图系统中所有节点类型的完整规范。

节点通用结构

每个节点都具有以下基础结构:

json
{
  "id": "node-unique-id",
  "type": "NodeType",
  "name": "节点名称",
  "position": { "x": 100, "y": 100 },
  "inputs": { ... },
  "outputs": { ... },
  "config": { ... }
}
字段类型描述
idstring节点唯一标识符
typestring节点类型
namestring节点显示名称
position节点在画布上的位置
inputsobject输入端口配置
outputsobject输出端口配置
configobject节点特定配置

端口类型

执行端口

控制执行流程的端口。

类型颜色描述
exec⬜ 白色执行流入口/出口

数据端口

传递数据的端口。

类型颜色描述
string🟢 绿色字符串
number🔵 蓝色数字
boolean🟡 黄色布尔值
object🟣 紫色对象
array🔴 红色数组
any⚪ 白色任意类型
function🟠 橙色函数

触发器节点

Event/onClick

组件点击事件触发器。

json
{
  "type": "trigger/onClick",
  "config": {
    "target": "component-id"
  },
  "outputs": {
    "exec": { "type": "exec" },
    "event": { "type": "object" },
    "target": { "type": "object" }
  }
}

配置项:

属性类型描述
targetstring目标组件 ID

输出:

端口类型描述
execexec执行流
eventobject原生事件对象
targetobject目标元素

Event/onChange

值变化事件触发器。

json
{
  "type": "trigger/onChange",
  "config": {
    "target": "input-id"
  },
  "outputs": {
    "exec": { "type": "exec" },
    "value": { "type": "any" },
    "event": { "type": "object" }
  }
}

输出:

端口类型描述
execexec执行流
valueany新值
eventobject原生事件对象

Event/onLoad

页面/组件加载事件。

json
{
  "type": "trigger/onLoad",
  "config": {
    "target": "page" | "component-id"
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

Event/onSubmit

表单提交事件。

json
{
  "type": "trigger/onSubmit",
  "config": {
    "target": "form-id"
  },
  "outputs": {
    "exec": { "type": "exec" },
    "formData": { "type": "object" },
    "event": { "type": "object" }
  }
}

Event/onKeyPress

键盘事件触发器。

json
{
  "type": "trigger/onKeyPress",
  "config": {
    "key": "Enter",
    "modifiers": ["ctrl", "shift"]
  },
  "outputs": {
    "exec": { "type": "exec" },
    "key": { "type": "string" },
    "event": { "type": "object" }
  }
}

配置项:

属性类型描述
keystring触发按键
modifiersarray修饰键 ["ctrl", "shift", "alt", "meta"]

Event/onTimer

定时器触发器。

json
{
  "type": "trigger/onTimer",
  "config": {
    "interval": 1000,
    "repeat": true,
    "immediate": false
  },
  "outputs": {
    "exec": { "type": "exec" },
    "count": { "type": "number" },
    "timestamp": { "type": "number" }
  }
}

配置项:

属性类型默认值描述
intervalnumber1000间隔时间(ms)
repeatbooleanfalse是否重复
immediatebooleanfalse是否立即触发

操作节点

Action/SetState

状态更新节点。

json
{
  "type": "action/setState",
  "config": {
    "target": "stateName",
    "mode": "replace"
  },
  "inputs": {
    "exec": { "type": "exec" },
    "value": { "type": "any" }
  },
  "outputs": {
    "exec": { "type": "exec" },
    "newValue": { "type": "any" }
  }
}

配置项:

属性类型描述
targetstring目标状态名
mode"replace" | "merge" | "push" | "remove"更新模式

更新模式:

模式描述适用类型
replace完全替换所有类型
merge浅合并object
push追加元素array
remove移除元素array

Action/Navigate

页面跳转节点。

json
{
  "type": "action/navigate",
  "config": {
    "path": "/detail/${id}",
    "mode": "push"
  },
  "inputs": {
    "exec": { "type": "exec" },
    "params": { "type": "object" }
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

配置项:

属性类型默认值描述
pathstring-目标路径
mode"push" | "replace""push"导航模式
queryobject-URL 查询参数

Action/HTTP

HTTP 请求节点。

json
{
  "type": "action/http",
  "config": {
    "method": "GET",
    "url": "/api/users",
    "headers": {},
    "timeout": 30000
  },
  "inputs": {
    "exec": { "type": "exec" },
    "url": { "type": "string" },
    "body": { "type": "any" },
    "params": { "type": "object" }
  },
  "outputs": {
    "success": { "type": "exec" },
    "error": { "type": "exec" },
    "response": { "type": "object" },
    "data": { "type": "any" },
    "status": { "type": "number" },
    "errorMessage": { "type": "string" }
  }
}

配置项:

属性类型默认值描述
method"GET" | "POST" | "PUT" | "DELETE" | "PATCH""GET"请求方法
urlstring-请求 URL
headersobject{}请求头
timeoutnumber30000超时时间(ms)
contentTypestring"application/json"Content-Type

Action/ShowToast

显示消息提示节点。

json
{
  "type": "action/showToast",
  "config": {
    "type": "success",
    "duration": 3000,
    "position": "top"
  },
  "inputs": {
    "exec": { "type": "exec" },
    "message": { "type": "string" }
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

配置项:

属性类型默认值描述
type"info" | "success" | "warning" | "error""info"提示类型
durationnumber3000显示时长(ms)
position"top" | "bottom""top"显示位置

Action/ShowModal

显示模态框节点。

json
{
  "type": "action/showModal",
  "config": {
    "ref": "modal-id"
  },
  "inputs": {
    "exec": { "type": "exec" }
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

Action/HideModal

隐藏模态框节点。

json
{
  "type": "action/hideModal",
  "config": {
    "ref": "modal-id"
  },
  "inputs": {
    "exec": { "type": "exec" }
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

Action/Console

控制台输出节点(调试用)。

json
{
  "type": "action/console",
  "config": {
    "level": "log"
  },
  "inputs": {
    "exec": { "type": "exec" },
    "message": { "type": "any" }
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

逻辑节点

Logic/Condition

条件分支节点。

json
{
  "type": "logic/condition",
  "config": {
    "expression": "value > 0"
  },
  "inputs": {
    "exec": { "type": "exec" },
    "input": { "type": "any" }
  },
  "outputs": {
    "true": { "type": "exec" },
    "false": { "type": "exec" }
  }
}

配置项:

属性类型描述
expressionstring条件表达式

Logic/Switch

多条件分支节点。

json
{
  "type": "logic/switch",
  "config": {
    "cases": [
      { "value": "a", "label": "Case A" },
      { "value": "b", "label": "Case B" }
    ]
  },
  "inputs": {
    "exec": { "type": "exec" },
    "value": { "type": "any" }
  },
  "outputs": {
    "case_a": { "type": "exec" },
    "case_b": { "type": "exec" },
    "default": { "type": "exec" }
  }
}

Logic/ForEach

循环节点。

json
{
  "type": "logic/forEach",
  "inputs": {
    "exec": { "type": "exec" },
    "array": { "type": "array" }
  },
  "outputs": {
    "loop": { "type": "exec" },
    "item": { "type": "any" },
    "index": { "type": "number" },
    "done": { "type": "exec" }
  }
}

Logic/Delay

延迟执行节点。

json
{
  "type": "logic/delay",
  "config": {
    "duration": 1000
  },
  "inputs": {
    "exec": { "type": "exec" },
    "duration": { "type": "number" }
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

Logic/Debounce

防抖节点。

json
{
  "type": "logic/debounce",
  "config": {
    "wait": 300
  },
  "inputs": {
    "exec": { "type": "exec" }
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

Logic/Throttle

节流节点。

json
{
  "type": "logic/throttle",
  "config": {
    "limit": 1000
  },
  "inputs": {
    "exec": { "type": "exec" }
  },
  "outputs": {
    "exec": { "type": "exec" }
  }
}

数据节点

Data/Variable

变量引用节点。

json
{
  "type": "data/variable",
  "config": {
    "name": "stateName"
  },
  "outputs": {
    "value": { "type": "any" }
  }
}

Data/Constant

常量节点。

json
{
  "type": "data/constant",
  "config": {
    "type": "string",
    "value": "Hello"
  },
  "outputs": {
    "value": { "type": "string" }
  }
}

配置项:

属性类型描述
type"string" | "number" | "boolean" | "object" | "array"值类型
valueany常量值

Data/Transform

数据转换节点。

json
{
  "type": "data/transform",
  "config": {
    "expression": "data.map(item => item.name)"
  },
  "inputs": {
    "data": { "type": "any" }
  },
  "outputs": {
    "result": { "type": "any" }
  }
}

Data/Merge

对象合并节点。

json
{
  "type": "data/merge",
  "inputs": {
    "obj1": { "type": "object" },
    "obj2": { "type": "object" }
  },
  "outputs": {
    "result": { "type": "object" }
  }
}

Data/Pick

对象取值节点。

json
{
  "type": "data/pick",
  "config": {
    "path": "user.profile.name"
  },
  "inputs": {
    "object": { "type": "object" }
  },
  "outputs": {
    "value": { "type": "any" }
  }
}

Data/ArrayOperation

数组操作节点。

json
{
  "type": "data/arrayOperation",
  "config": {
    "operation": "filter",
    "expression": "item.active === true"
  },
  "inputs": {
    "array": { "type": "array" }
  },
  "outputs": {
    "result": { "type": "array" }
  }
}

操作类型:

操作描述配置
map映射expression
filter过滤expression
find查找expression
sort排序key, order
slice切片start, end
reverse反转-
flat展平depth

自定义代码节点

Code/JavaScript

JavaScript 代码节点。

json
{
  "type": "code/javascript",
  "config": {
    "code": "const result = inputs.a + inputs.b;\nreturn { result };",
    "async": false
  },
  "inputs": {
    "exec": { "type": "exec" },
    "a": { "type": "number" },
    "b": { "type": "number" }
  },
  "outputs": {
    "exec": { "type": "exec" },
    "result": { "type": "number" }
  }
}

配置项:

属性类型默认值描述
codestring-JavaScript 代码
asyncbooleanfalse是否异步

代码上下文:

javascript
// 可用变量
inputs; // 输入数据
state; // 当前状态
props; // 组件属性
refs; // 组件引用

// 可用函数
setState(key, value); // 更新状态
navigate(path); // 页面跳转
fetch(url, options); // HTTP 请求
console.log(); // 日志输出

子图节点

Subgraph/Call

调用子图节点。

json
{
  "type": "subgraph/call",
  "config": {
    "graphId": "fetch-and-cache"
  },
  "inputs": {
    "exec": { "type": "exec" },
    "url": { "type": "string" }
  },
  "outputs": {
    "exec": { "type": "exec" },
    "data": { "type": "any" }
  }
}

注释节点

Comment

注释节点(不参与执行)。

json
{
  "type": "comment",
  "config": {
    "text": "这里处理用户登录逻辑",
    "color": "#FFE066"
  }
}

下一步

基于 MIT 许可证发布