操作栏组件属于小组件,用于显示一系列可供用户使用的操作。这些操作一部分显示为一行按钮,其余操作则显示在随附的列表框中。组件配置和用户界面的大小决定了显示为按钮的操作的数量。所有不显示为按钮的操作均显示在列表框中,该列表框在单击省略号操作后即会显示。
操作栏组件包括在项列表和项标识组件内。该组件也可包含在“查看部件列表”、“查看部件结构”和“查看文档结构”任务的预览窗格中。预览窗格会替换给定任务右上角的选定文档/部件窗格。
下表显示了用于配置此组件的 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 | 用于确定在何种条件及何种状态下显示操作按钮。选项:AlwaysShown、DisableUnavailable 和 HideUnavailable。AlwaysShown - 按钮始终可见且已启用。DisableUnavailable - 按钮始终可见,但当操作不可用于所选对象时,按钮将被禁用。HideUnavailable - 仅当操作可用于所选对象时,按钮才可见。 注意:其他配置也可能影响按钮是已启用还是已禁用。 | | 不适用 | 必需 |
buttonStyle | 确定按钮的视觉样式。选项:primary、secondary、tertiary、danger 和 transparent。 | | 不适用 | 必需 |
overrideSetDisabled | 如果设置了此字段,其值是决定启用还是禁用按钮的唯一因素。选项:true 和 false。如果为 true,确保禁用该按钮;如果为 false,确保启用该按钮。 | | 不适用 | 可选 |
fireEventOnFinish | 如果将此字段设置为 true,当服务结束运行时,将触发 EventTriggered 事件,而当弹窗关闭时,将触发 PopupClosed 事件。 | | 不适用 | 可选 |
inputConstraints | 确定操作的输入约束。选项:InputRequired、SingleInputOnly 和 NoInputRequired。 InputRequired:此操作必须接收输入才能运行。如果输入为空且不包含任何项,此操作的按钮将处于禁用状态。 SingleInputOnly - 此操作必须接收单个输入才能运行。如果输入为空或包含多个项,此操作的按钮将处于禁用状态。 NoInputRequired - 此操作可在没有任何输入的情况下运行,也可通过输入进行操作。 | | 不适用 | 可选 |
iconWhenEnabled | 如果指定了此字段,在启用操作按钮时,操作按钮的标签左侧将有一个图标。 | | | |
entityName | 用作图标的媒体实体的名称。 | | | |
iconWhenDisabled | 如果指定了此字段,在禁用操作按钮时,操作按钮的标签左侧将有一个图标。 | | | |
entityName | 用作图标的媒体实体的名称。 | | | |
activityType | 用于确定此操作是运行服务还是显示弹出式混搭。选项:openUrl (在 Windchill Navigate 9.3.4 及更高版本中提供)、popup、service 和 parent (在 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 设置为 service 或 popup 时,才会使用此特性。 | | 不适用 | 可选 |
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_InputCco 和 serviceParam_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"
}
}
]
}
}
}