使用 SCW
注意
在阅读本文档之前,我们假定你已经知道如何利用 SCW 打包 CoCo 控件,如果你还不了解,详见 打包 CoCo 控件。
一、控件类型定义
const types: Types = {
type: "MY_WIDGET",
info: {
title: "我的控件",
icon: "icon-widget-radio",
category: "我的控件"
},
options: {
visible: false,
global: true
},
properties: [/* 控件属性 */],
methods: [/* 控件方法 */],
events: [/* 控件事件 */]
}
属性 | 说明 |
---|---|
type | 控件类型,全局唯一,命名规范:大写字母加下划线组成 |
info | 控件信息,包括名称、图标、分类等,详见 API |
info.title | 控件名称 |
info.icon | 控件图标 |
info.category | 控件分类 |
options | 控件选项,包括是否可见、是否全局等,详见 API |
options.visible | 是否可见,默认 false |
options.global | 是否全局,默认 false |
properties | 控件属性,包括控件的属性、类型、默认值等 |
methods | 控件方法,包括控件的行为、参数等 |
events | 控件事件,包括控件的触发事件、参数等 |
1.控件属性
const types: Types = {
//...
properties: [
{
key: "property",
label: "属性",
type: new StringType("默认值"),
blockOptions: {
get: {
key: "getProperty"
},
set: false
}
}
]
}
属性 | 说明 |
---|---|
key | 控件的属性,命名规范:英文 + 数字组成,不能以数字开头,可以使用 CoCo 内置属性 |
label | 属性的显示名称 |
type | 属性的类型,详见 类型 API |
blockOptions | 属性的积木块选项,详见 属性积木块选项 API |
blockOptions.get | 属性的获取方法积木选项,false 表示不可获取 |
blockOptions.get.key | 获取方法名 |
blockOptions.set | 属性的设置方法积木选项,false 表示不可设置 |
blockOptions.set.key | 设置方法名 |
控件属性组
const types: Types = {
//...
properties: [
{
blockOptions: {
set: false
},
contents: [
{
key: "property1",
label: "属性1",
type: new StringType("默认值")
}, {
key: "property2",
label: "属性2",
type: new StringType("默认值")
}
]
}
]
}
属性 | 说明 |
---|---|
blockOptions | 属性组的积木块选项,属性组内的每个属性都继承了此选项 |
contents | 属性组的内容 |
提示
属性组是可以嵌套的。例如:
const types: Types = {
//...
properties: [
{
blockOptions: {/* 属性组的积木块选项 */},
contents: [
{ // 子属性组
blockOptions: {/* 子属性组的积木块选项,继承自父属性组的积木块选项 */},
contents: [
{
key: "property",
label: "属性",
type: new StringType("默认值")
}
]
}
]
}
]
}
2.控件方法
const types: Types = {
//...
methods: [
{
key: "method",
label: "方法",
block: [
"调用", MethodBlockParam.THIS, MethodBlockParam.METHOD, "参数1", {
key: "param1",
label: "参数1",
type: new StringType("默认值")
}, "参数2", {
key: "param2",
label: "参数2",
type: new NumberType(0)
}
],
returns: new StringType(),
blockOptions: {
icon: "icon-widget-radio",
color: Color.BLUE,
}
}
]
}
生成的积木块:(调用 [我的控件] 方法 [方法] 参数1 (“默认值”) 参数2 (0))
属性 |
---|