前言
在OneCode低代码开发平台中,动作(Action)是连接用户交互与业务逻辑的核心桥梁。动作的执行方式由type
参数控制,而这个参数的值来自于ActionTypeEnum
枚举类的定义。本文将深入剖析这个枚举类,揭开OneCode动作执行机制的底层原理。
ActionTypeEnum
是OneCode中定义动作执行类型的核心枚举类,它位于net.ooder.esd.annotation.event
包下。从代码分析中,我们可以看到该枚举类定义了多种动作执行方式,每种方式都有特定的应用场景和执行机制。
"listItems": [
// 枚举值定义
{
"bindClass": [],
"caption": "模块间",
"id": "module",
"name": "模块间",
"pattern": "",
"tagVar": {
"name": "module",
"clazz": "net.ooder.esd.annotation.event.ActionTypeEnum"
}
},
{
"bindClass": [],
"caption": "外部页面调用",
"id": "otherModuleCall",
"name": "外部页面调用",
"pattern": "",
"tagVar": {
"name": "otherModuleCall",
"clazz": "net.ooder.esd.annotation.event.ActionTypeEnum"
}
},
// 更多枚举值...
],
"enumClass": "net.ooder.esd.annotation.event.ActionTypeEnum",
"id": "type",
"type": "listbox"
类型含义:用于在当前应用内的不同模块之间进行方法调用和数据传递。
应用场景:
执行机制:
代码示例:
{
"type": "module",
"target": "dsm.agg.common.utils.StringUtils",
"method": "format",
"args": ["Hello, {0}", "World"],
"redirection": "page::resultField"
}
类型含义:用于调用当前应用外部的页面或服务。
应用场景:
执行机制:
代码示例:
{
"type": "otherModuleCall",
"target": "http://external-system.com/api/function",
"method": "open",
"args": ["param1=value1¶m2=value2"],
"redirection": "other:callback:handleResult"
}
类型含义:用于调用当前上下文环境中的方法。
应用场景:
执行机制:
代码示例:
{
"type": "other",
"target": "page.formMain.submitBtn",
"method": "disable",
"args": [true]
}
类型含义:用于在系统内部发送消息,实现组件间的松耦合通信。
应用场景:
执行机制:
代码示例:
{
"type": "msg",
"target": "dataChangedEvent",
"method": "broadcast",
"args": [{"source": "formA", "data": "updated"}]
}
类型含义:用于在动作执行上下文中定义变量。
应用场景:
执行机制:
代码示例:
{
"type": "var",
"target": "userInfo",
"method": "define",
"args": [{
"id": "{page.userId.getValue()}",
"name": "{page.userName.getValue()}",
"roles": ["admin", "user"]
}]
}
类型含义:用于执行回调函数,处理异步操作结果。
应用场景:
执行机制:
代码示例:
{
"type": "callback",
"target": "dataProcessCallback",
"method": "call",
"args": ["{result.data}"],
"redirection": "other:callback:nextStep"
}
类型含义:表示不执行任何实际操作的空动作。
应用场景:
执行机制:
代码示例:
{
"type": "undefined",
"canReturn": false
}
在OneCode的可视化设计器中,ActionTypeEnum枚举值被转换为友好的中文选项,呈现在动作配置界面中:
"labelCaption": "执行方式",
"name": "type",
"readonly": false,
"type": "listbox",
"visibility": "visible"
这种设计使得开发者不需要记忆复杂的动作类型标识符,只需通过直观的界面选择即可完成配置。
在企业应用中,经常需要在不同模块间同步数据。使用module
类型动作可以轻松实现这一需求:
{
"type": "module",
"target": "dsm.agg.common.sync.DataSyncService",
"method": "syncUserData",
"args": ["{page.userId.getValue()}"],
"canReturn": true
}
对于需要异步执行的操作,可以结合other
和callback
类型实现完整的流程控制:
// 第一步:启动异步任务
{
"type": "other",
"target": "page.asyncTask",
"method": "start",
"args": ["{page.taskConfig.getValue()}"],
"redirection": "other:callback:handleTaskResult",
"canReturn": false
}
// 第二步:处理任务结果(回调)
{
"type": "callback",
"target": "handleTaskResult",
"method": "call",
"args": ["{result}"],
"canReturn": true
}
canReturn
参数控制动作执行流程通过深入理解ActionTypeEnum
枚举类,开发者可以更加灵活地配置和使用OneCode的动作系统,构建出功能强大、易于维护的低代码应用。在下一篇文章中,我们将继续探讨OneCode动作系统中的其他核心参数类型和它们的应用场景。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。