输入类型 - 用户界面元素
- Updated: 2022/05/19
用户界面 (UI) 元素是在构建机器人时用于接收操作中输入的输入控件。
以下示例显示了受支持的输入类型。 使用 UI 元素创建用户界面设计来构建 Control Room 界面。 例如,如果您需要文本输入,则使用 TEXT
,如果您需要单选按钮,则选择 RADIO
,依此类推。 本主题基于以下位置的 Package SDK 中提供的 SampleUI 示例:<PackageSDK>\src\main\java\com\automationanywhere\botcommand\samples\commands\ui\SampleUI.java.
- 确保已导入以下软件包,以保证所有功能都能按照示例中的描述运行。
import com.automationanywhere.commandsdk.annotations.Idx; import com.automationanywhere.commandsdk.annotations.Pkg; import com.automationanywhere.commandsdk.annotations.rules.CodeType; import com.automationanywhere.commandsdk.annotations.rules.VariableType;
- 添加
@BotCommand
注释,使类成为 Control Room 中的操作。 有关注释的更多信息,请参阅 注释。@BotCommand
- 添加
@CommandPkg
注解以定义所有与 UI 相关的组件 - 标签、描述和名称。@CommandPkg(label = "UI Demo", description = "Demonstrates the provided UI elements", name = "uiDemo")
- 创建一个类,并按照下面的描述定义字段。
- 使用
@Execute
对该方法进行注释,以便于在编译期间执行该方法。 - 在此示例中,
@Idx
和@Pkg
被用作类的成员,因此您应该使用set
和get
方法来定义它们。-
@Idx
- 定义操作的索引。 -
@Pkg
- 定义将在界面中显示的所有参数和成员变量。 必须与@Idx
一起使用,否则此注释将被忽略。 -
@Inject
- 使用成员类从 UI 接收值时,字段级别需要@Inject
。@BotCommand @CommandPkg(label = "UI Demo", description = "Demonstrates the provided UI elements", name = "uiDemo") public class SampleUI { @Idx(index = "1", type = TEXT) @Pkg(label = "Text type") @Inject String text; @Execute public String getText() { return text; } public void setText(String text) { this.text = text; } }
-
- 使用
- 将该操作拖入画布,您就可以在文本字段中输入一个字符串。 您将看到一个与此图片类似的输入框。
UI 元素 - 数字字段
使用数字类型来创建一个接受数字的 UI 元素。 使用以下示例,您将能够创建一个只接受数字的字段。
@BotCommand @CommandPkg(label = "UI Demo", description = "Demonstrates the provided UI elements", name = "uiDemo") public class SampleUI { @Idx(index = "2", type = NUMBER) @Pkg(label = "Number type") @Inject String num; @Execute public String getNum() { return num; } public void setNum(String num) { this.num = num; } }
可以创建其他 UI 组件,例如: 布尔值、单选按钮、数字、变量、代码、字典、列表、日期/时间 等等。 要获取受支持 UI 元素的完整列表,请参阅 <PackageSDK>\src\main\java\com\automationanywhere\botcommand\samples\commands\ui\SampleUI.java.
支持的 UI 验证还支持以下 UI 验证:
- @NotEmpty 表示在机器人设计时,UI 字段需要输入。
- @ LocalFile 指的是用户计算机上的本地文件。
- @NumberIntegers 指的是您可以提供的数值,例如浮点数或双精度输入类型。