RuleGo RuleGo
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文
🏠首页
  • 快速入门
  • 规则链
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 可视化
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • 触发器
  • 高级主题
  • 性能
  • 标准组件
  • 扩展组件
  • 自定义组件
  • 组件市场
  • 概述
  • 快速入门
  • 路由
  • DSL
  • API
  • Options
  • 组件
🔥编辑器 (opens new window)
  • 可视化编辑器 (opens new window)
  • RuleGo-Server (opens new window)
  • ❓问答

    • FAQ
💖支持
👥加入社区
  • Github (opens new window)
  • Gitee (opens new window)
  • GitCode (opens new window)
  • 更新日志 (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • 快速入门

  • 规则链

  • 标准组件

  • 扩展组件

  • 自定义组件

  • 组件市场

  • 可视化

    • 可视化概述
    • RuleGo-Editor
    • 获取组件配置表单
      • 组件配置表单API
        • types.ComponentForm
        • types.ComponentFormField
      • 组件配置表单约定
      • 自定义组件表单配置信息
    • 获取规则链配置
    • 获取规则链节点配置
    • 批量初始化规则链
    • 删除规则链实例
    • 保存规则链坐标信息
    • 组件配置表单约定
  • AOP

  • 触发器

  • 高级主题

  • RuleGo-Server

  • 问题

目录

获取组件配置表单

该API会扫描所有注册到注册器的组件,根据约定方式 得到组件定义及其表单配置信息。用于规则链可视化配置,组件物料加载。

# 组件配置表单API

返回所有注册的组件定义及其表单配置信息列表。

rulego.Registry.GetComponentForms().Values()
1

返回类型:[]types.ComponentForm

参考示例:examples/ui_api/ (opens new window)

示例返回结果:testdata/components.json (opens new window)

# types.ComponentForm

字段 类型 说明 默认值
type string 组件类型 组件实现的Type()函数值,全局唯一
category string 组件分类
fields []ComponentFormField 组件配置字段列表 默认获取组件的Config字段
label string 组件展示名称 空
desc string 组件说明 空
icon string 图标 空
relationTypes []string 和下一个节点能产生的连接名称列表 过滤器节点类型默认是:True/False/Failure;其他节点类型默认是Success/Failure,如果是空,表示用户可以自定义连接关系
disabled bool 是否禁用,如果禁用在rulego-editor不显示 false

# types.ComponentFormField

字段 类型 说明 默认值
name string 字段名称
type string 字段类型 如:string、int、bool、等
defaultValue any 默认值 组件实现的方法node.New(), Config对应的字段,提供了默认值会填充到该值
label string 字段展示名称 空,可以通过tag:Label指定
desc string 字段说明 空,可以通过tag:Desc指定
rules []Object 前端界面校验规则,示例{required: true, message: "该字段是必须的"} 空
fields []ComponentFormField 嵌套字段, Type=struct,嵌套字段 空
component Object 表单组件配置,示例{"type": "codeEditor"} 空

type:字段类型,目前提供以下类型,rulego-editor前端会根据类型自动选择表单组件

  • string
  • bool
  • int
  • int8
  • int16
  • int32
  • int64
  • uint
  • uint8
  • uint16
  • uint32
  • uint64
  • float32
  • float64
  • array:Slice类型也会转换成:array
  • map
  • struct:嵌套字段

也可以通过component字段显性指定表单组件类型:

  • codeEditor:代码编辑器
  • textarea: 文本框
  • select:下拉框,示例:
{
  "type": "select",
  "filterable": true,
  "allowCreate": false,
  "multiple": false,
  "options": [
    {
      "label": "TCP",
      "value": "tcp"
    },
    {
      "label": "UDP",
      "value": "udp"
    }
  ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 组件配置表单约定

组件配置表单约定

# 自定义组件表单配置信息

自定义组件也可以通过实现以下可选接口,覆盖组件配置表单约定 的定义信息:

type ComponentDefGetter interface {
  Def() ComponentForm
}
1
2
3

示例:

//配置项,支持以下类型
type DefaultValueConfig struct {
	Num    int
	Url    string `label:"服务器地址" desc:"broker服务器地址" validate:"required" `
	IsSsl  bool
	Params []string
	A      int32
	B      int64
	C      float64
	D      map[string]string
	E      TestE
	F      uint16
}
type TestE struct {
	A string
}
//自定义组件
type DefaultValueNode struct {
	BaseNode
	//根据该字段的定义返回表单配置项定义信息
	Config DefaultValueConfig
}

func (n *DefaultValueNode) Type() string {
	return "test/defaultConfig"
}

//默认值
func (n *DefaultValueNode) New() types.Node {
	return &DefaultValueNode{
		Config: DefaultValueConfig{
			Url: "http://localhost:8080",
			Num: 5,
			E: TestE{
				A: "测试",
			},
		},
	}
}
//实现ComponentDefGetter接口修改组件名和描述
func (n *DefaultValueNode) Def() types.ComponentForm {
	relationTypes := &[]string{"aa", "bb"}
	return types.ComponentForm{
		Label:         "默认测试组件",
		Desc:          "用法xxxxx",
		RelationTypes: relationTypes,
	}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

也可以修改后,返回前端。 示例:

	items := Registry.GetComponentForms()
	componentForm, ok := items.GetComponent("test/configHasPtr")
	assert.Equal(t, true, ok)
	componentForm.Label = "中文Label"
	items[componentForm.Type] = componentForm
1
2
3
4
5
在 GitHub 上编辑此页 (opens new window)
上次更新: 2025/04/02, 01:29:50
RuleGo-Editor
获取规则链配置

← RuleGo-Editor 获取规则链配置→

Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式