操作栏 (测试版)
定义和用法
操作栏组件属于小组件,用于显示一系列可供用户使用的操作。这些操作一部分显示为一行按钮,其余操作则显示在随附的列表框中。组件配置和用户界面的大小决定了显示为按钮的操作的数量。所有不显示为按钮的操作均显示在列表框中,该列表框在单击省略号操作后即会显示。
下面的示例图示为操作栏组件:
可通过以下方式配置操作栏组件:
定义操作栏中包括的操作
设置显示为按钮的操作的最大数量
根据操作的可用性设置操作的可见性选项
定义操作的顺序
定义操作是否需要输入
为操作栏选择所需的样式
配置操作栏中的菜单按钮
操作主要用于激活服务或弹窗。必须在 ThingWorx 中单独配置服务或弹出式混搭。必须在 ThingWorx 中的相应服务或混搭中配置其他所有功能,如 toast 消息。还可以配置从操作栏打开 URL。例如,配置“在 Windchill 中查看”按钮。
操作栏组件包括在项列表和项标识组件内。该组件也可包含在“查看部件列表”、“查看部件结构”和“查看文档结构”任务的预览窗格中。预览窗格会替换给定任务右上角的选定文档/部件窗格。
操作栏、部件操作栏和文档操作栏是可用于操作栏组件的配置类型。下表列出适用于每种配置的操作。该表还列出各个操作的 ID,其中将 ID 作为配置中 id 特性的值。
配置类型
默认操作
操作 ID
操作栏
批准
Approve
否决
Reject
分析
Analyze
重新分配
Reassign
部件操作栏
报告问题
PTC.Nav.ReportAProblem
在 Windchill 中查看
PTC.Nav.ViewInWindchill
文档操作栏
打开文档
PTC.Nav.OpenDocument
报告问题
PTC.Nav.ReportAProblem
在 Windchill 中查看
PTC.Nav.ViewInWindchill
绑定特性 
输入
特性名称
说明
特性类型
Disabled
禁用混搭中的小组件。
布尔型
Input
用于标识要从后端系统中获取的数据。
CCO 格式的 JSON
ServiceActionId
单击操作时,将使用服务操作的操作 ID 来更新此字符串。
字符串
SubComponentConfiguration
如果配置在运行时发生更改,会将其绑定到此特性。
JSON
输出
特性名称
说明
特性类型
EventTriggered
如果将操作的 fireEventOnFinish 配置特性配置为 true,在服务结束运行或弹窗显示时所触发的事件。
事件
ServiceActionIdChanged
ServiceActionId 中的值发生更改 (即由操作栏调用的服务结束运行) 时所触发的事件。
事件
PopupClosed
当打开的弹窗关闭时所触发的事件。
事件
配置特性 
下表显示了用于配置此组件的 JSON 特性。
有关详情,请参阅组件配置结构
有关子特性的详情,请参阅子特性和容器键
特性名称
说明
特性类型
默认值
必需或可选
maxItemsToShow
显示的最大操作按钮数。如果操作按钮数大于指定值,会在列表框中填充其他操作。
2
必需
modelThingName
事物的名称,该事物包含具有以下声明的服务:
public JSONObject GetActions(@ThingworxServiceParameter(name = "ccoJson", baseType = "JSON") JSONObject ccoJson)
此服务接受 CCO 格式的输入,其中包含单一项。然后返回一个包含数组的 JSONObject,该数组将可用操作的 ID 映射到从后端系统接收到的相应操作标签。请参阅下面的 JSON 配置示例。
PTC.ActionBar Model.Thing
必需
actions
需要从后端系统中获取其数据的操作列表。容器键为 actionConfiguration。请参阅下面的子特性:
不适用
必需
overrideLabel
此处设置的值将显示为操作按钮的标签,覆盖来自后端系统的值。要进行本地化,可在值两边加上双括号。
不适用
可选
actionButtonVisibility
用于确定在何种条件及何种状态下显示操作按钮。选项:AlwaysShownDisableUnavailableHideUnavailableAlwaysShown - 按钮始终可见且已启用。DisableUnavailable - 按钮始终可见,但当操作不可用于所选对象时,按钮将被禁用。HideUnavailable - 仅当操作可用于所选对象时,按钮才可见。
注意:其他配置也可能影响按钮是已启用还是已禁用。
不适用
必需
buttonStyle
确定按钮的视觉样式。选项:primarysecondarytertiarydangertransparent
不适用
必需
overrideSetDisabled
如果设置了此字段,其值是决定启用还是禁用按钮的唯一因素。选项:truefalse。如果为 true,确保禁用该按钮;如果为 false,确保启用该按钮。
不适用
可选
fireEventOnFinish
如果将此字段设置为 true,当服务结束运行时,将触发 EventTriggered 事件,而当弹窗关闭时,将触发 PopupClosed 事件。
不适用
可选
inputConstraints
确定操作的输入约束。选项:InputRequiredSingleInputOnlyNoInputRequired
InputRequired:此操作必须接收输入才能运行。如果输入为空且不包含任何项,此操作的按钮将处于禁用状态。
SingleInputOnly - 此操作必须接收单个输入才能运行。如果输入为空或包含多个项,此操作的按钮将处于禁用状态。
NoInputRequired - 此操作可在没有任何输入的情况下运行,也可通过输入进行操作。
不适用
可选
iconWhenEnabled
如果指定了此字段,在启用操作按钮时,操作按钮的标签左侧将有一个图标。
entityName
用作图标的媒体实体的名称。
iconWhenDisabled
如果指定了此字段,在禁用操作按钮时,操作按钮的标签左侧将有一个图标。
entityName
用作图标的媒体实体的名称。
activityType
用于确定此操作是运行服务还是显示弹出式混搭。选项:openUrl (在 Windchill Navigate 9.3.4 及更高版本中提供)、popupserviceparent (在 Windchill Navigate 9.4.0 及更高版本中提供)。有关 popup、service 和 parent 的必需子特性,请参阅下表。
不适用
必需
mashupName
以弹窗形式显示的混搭的名称。
仅当 activityType 设置为 popup 时,才会使用此特性。
不适用
必需
redirectAfterPopupSuccess
成功操作后,在关闭弹窗时,会重定向到另一混搭。
要通知操作栏是否已成功完成由弹窗执行的操作,请设置名为 PTC.ActionBar.popupCloseParameters 的会话参数,以指示操作是成功还是失败。例如,在弹出式混搭中,有一个表达式将在弹出项所执行的操作完成后执行,会话参数将在该表达式中设置。在以下示例中,由于操作成功,JSON 属性 operationSuccessful 设置为 true:
sessionStorage.setItem("PTC.ActionBar.popupCloseParameters", JSON.stringify( { operationSuccessful: true } ));
仅当 activityType 设置为 popup 时,才会使用此特性。
不适用
可选
popupWidth
指定所显示的弹窗的宽度。
仅当 activityType 设置为 popup 时,才会使用此特性。
1024
可选
popupHeight
指定所显示的弹窗的宽度。
仅当 activityType 设置为 popup 时,才会使用此特性。
640
可选
thingWithService
包含要运行的服务的事物的名称。
仅当 activityType 设置为 service 时,才会使用此特性。
不适用
必需
serviceName
要运行的服务的名称。
仅当 activityType 设置为 service 时,才会使用此特性。
不适用
必需
parameters
此可选字段可用于将硬编码参数传递给服务或弹出混搭。参数在 JSONObject 中定义,必须用转义引号将其格式转换为 JSON 对象的字符串。参数应以 "{\"myParamName\": \"hardcodedValue\"}" 格式输入到配置文件中。请参阅下面的附加信息。
仅当 activityType 设置为 servicepopup 时,才会使用此特性。
不适用
可选
openUrl
允许在操作按钮上设置 URL。设置为有效值时:选择操作按钮后,带有已设置 URL 的新窗口或新选项卡随即打开。
仅当 activityType 设置为 openUrl 时,才会使用此特性。
不适用
可选
parentId
此可选字段可用于设置父操作的 ID。如果设置为有效值,表示存在具有该 ID 的父操作,并将该操作设置为父菜单按钮下的一个选项。如果不存在具有 parentId 中所设置 ID 的操作,忽略且不显示操作。
仅当 activityType 设置为 parentId 时,才会使用此特性。
父项的 ID
可选
使用 parameters 配置服务操作:
下面是名为 MyService 的示例服务的签名:
@ThingworxServiceDefinition(name = "MyService", category = "MyCategory")
public void MyService(
@ThingworxServiceParameter(name = "exampleInt", baseType = "INTEGER") Integer exampleInt,
@ThingworxServiceParameter(name = "ExampleString", baseType = "STRING") String exampleString,
@ThingworxServiceParameter(name = "ExampleBoolean", baseType = "BOOLEAN") Boolean exampleBoolean)
MyService 的参数值如下所示:
{
\"exampleInt\": 123,
\"exampleString\": \"Hello\",
\"exampleBoolean\": true
}
* 
您的服务将自动获取两个参数 (如果您定义服务特征接收这两个参数):serviceParam_InputCcoserviceParam_ActionId。参数 serviceParam_InputCco 是 JSONObject,并且是提供给操作栏的输入。参数 serviceParam_ActionId 是所单击操作的 ID 的字符串。如果您的服务未在其声明中包括这些参数,不能使用它们。如果要使用它们,请使用以下方法定义您的服务声明,以使用其中一个或两个:
@ThingworxServiceDefinition(name = "MyService", category = "MyCategory")
public void MyService(
@ThingworxServiceParameter(name = "serviceParam_InputCco", baseType = "JSON")
JSONObject serviceParam_InputCco,
@ThingworxServiceParameter(name = "serviceParam_ActionId", baseType = "STRING")
String serviceParam_ActionId)
示例配置 
使用标准按钮的示例配置
{
"maxItemsToShow": {
"value": 3
},
"modelThingName": {
"entityName": "PTC.ActionBarModel.Thing"
},
"actions": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"id": "Approve",
"additionalData": {
"actionConfiguration": {
"actionButtonVisibility": {
"selectedKey": "HideUnavailable"
},
"buttonStyle": {
"selectedKey": "primary"
},
"activityType": {
"selectedKey": "popup"
},
"mashupName": {
"mashupName": "PTC.AccessApp.WindchillServices.RoutingOptionMashup"
},
"fireEventOnFinish": {
"value": false
},
"inputConstraints": {
"selectedKey": "SingleInputOnly"
}
}
},
"ordinal": 10
}, {
"id": "Reassign",
"additionalData": {
"actionConfiguration": {
"overrideLabel": {
"value": "Reassign"
},
"actionButtonVisibility": {
"selectedKey": "AlwaysShown"
},
"buttonStyle": {
"selectedKey": "primary"
},
"activityType": {
"selectedKey": "popup"
},
"mashupName": {
"mashupName": "PTC.AccessApp.WindchillServices.ReassignActionMashup"
},
"fireEventOnFinish": {
"value": false
},
"inputConstraints": {
"selectedKey": "InputRequired"
}
}
},
"ordinal": 20
}, {
"id": "PTC.Nav.OpenDocument",
"additionalData": {
"actionConfiguration": {
"openUrl": {
"value": "https://www.ptc.com"
},
"overrideLabel": {
"selectedKey": "[[PTC.AccessApp.OpenDocument]]"
},
"buttonStyle": {
"selectedKey": "primary"
},
"activityType": {
"selectedKey": "openUrl"
},
"actionButtonVisibility": {
"selectedKey": "AlwaysShown"
}
},
"ordinal": 30
}
}, {
"id": "ProblemReport",
"additionalData": {
"actionConfiguration": {
"overrideLabel": {
"value": "[[PTC.Nav.CreateProblemReport.AppTitle]]"
},
"popupHeight": {
"value": 640
},
"popupWidth": {
"value": 800
},
"actionButtonVisibility": {
"selectedKey": "AlwaysShown"
},
"buttonStyle": {
"selectedKey": "primary"
},
"mashupName": {
"mashupName": "PTC.Nav.CreateProblemReportAppMashup"
},
"activityType": {
"selectedKey": "popup"
},
"parameters": {
"value": "{\"affectedItemsCCO\":{\"timeStamp\":\"2021-11-24 22:45:54.528\",\"data\":[{\"itemListsData\":[{\"items\":[{\"id\":{\"value\":\"OR:wt.part.WTPart:100447\"}}],\"objectType\":\"PTC.ProdMgmt.Part\"}],\"adapter\":{\"instanceName\":\"windchill\",\"thingName\":\"PTC.WCAdapter\"}}],\"version\":\"1.0.0\",\"statusMessage\":\"OK\",\"status\":\"200\"},\"isPopup\":true}"
}
}
},
"ordinal": 40
}
],
"objectType": "WT.WorkItem.Actions"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
}
}
}
使用菜单按钮的示例配置
{
"maxItemsToShow": {
"value": 3
},
"modelThingName": {
"entityName": "PTC.ActionBarModel.Thing"
},
"actions": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"id": "Approve",
"additionalData": {
"actionConfiguration": {
"actionButtonVisibility": {
"selectedKey": "HideUnavailable"
},
"buttonStyle": {
"selectedKey": "primary"
},
"activityType": {
"selectedKey": "popup"
},
"mashupName": {
"mashupName": "PTC.AccessApp.WindchillServices.RoutingOptionMashup"
},
"fireEventOnFinish": {
"value": false
},
"inputConstraints": {
"selectedKey": "SingleInputOnly"
}
}
},
"ordinal": 10
}, {
"id": "Reassign",
"additionalData": {
"actionConfiguration": {
"overrideLabel": {
"value": "Reassign"
},
"actionButtonVisibility": {
"selectedKey": "AlwaysShown"
},
"buttonStyle": {
"selectedKey": "primary"
},
"activityType": {
"selectedKey": "popup"
},
"mashupName": {
"mashupName": "PTC.AccessApp.WindchillServices.ReassignActionMashup"
},
"fireEventOnFinish": {
"value": false
},
"inputConstraints": {
"selectedKey": "InputRequired"
}
}
},
"ordinal": 20
}, {
"id": "PTC.Nav.OpenDocument",
"additionalData": {
"actionConfiguration": {
"openUrl": {
"value": "https://www.ptc.com"
},
"overrideLabel": {
"selectedKey": "[[PTC.AccessApp.OpenDocument]]"
},
"buttonStyle": {
"selectedKey": "primary"
},
"activityType": {
"selectedKey": "openUrl"
},
"actionButtonVisibility": {
"selectedKey": "AlwaysShown"
}
},
"ordinal": 30
}
}, {
"id": "ProblemReport",
"additionalData": {
"actionConfiguration": {
"overrideLabel": {
"value": "[[PTC.Nav.CreateProblemReport.AppTitle]]"
},
"popupHeight": {
"value": 640
},
"popupWidth": {
"value": 800
},
"actionButtonVisibility": {
"selectedKey": "AlwaysShown"
},
"buttonStyle": {
"selectedKey": "primary"
},
"mashupName": {
"mashupName": "PTC.Nav.CreateProblemReportAppMashup"
},
"activityType": {
"selectedKey": "popup"
},
"parameters": {
"value": "{\"affectedItemsCCO\":{\"timeStamp\":\"2021-11-24 22:45:54.528\",\"data\":[{\"itemListsData\":[{\"items\":[{\"id\":{\"value\":\"OR:wt.part.WTPart:100447\"}}],\"objectType\":\"PTC.ProdMgmt.Part\"}],\"adapter\":{\"instanceName\":\"windchill\",\"thingName\":\"PTC.WCAdapter\"}}],\"version\":\"1.0.0\",\"statusMessage\":\"OK\",\"status\":\"200\"},\"isPopup\":true}"
}
}
},
"ordinal": 40
}
],
"objectType": "WT.WorkItem.Actions"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
}
}
}
这对您有帮助吗?