AWC开发创建对象,包括创建页面调用SOA服务

通过awc开发一个创建对象的功能需要三个文件,html文件通过awc提供的ui控件去画一个创建对象的页面(awcui控件在文档中心有详细描述),json文件可以查看源码查询如何使用,js文件中执行调用创建对象的soa服务(api可以通过genSoaApi命令获取)

  • 通过ui控件画一个简单的html界面用来输入数据,效果如下:

 AWC开发创建对象,包括创建页面调用SOA服务_第1张图片

  • 创建页面的代码如下:

      
         
          
          
          
          
          
            创建
          
         
      

  • 通过json文件定义客户端用户界面及其行为,json数据如下:
{
    "schemaVersion": "1.0.0",
    "imports": [
        "js/aw-panel.directive",
        "js/aw-panel-body.directive",
        "js/aw-textbox.directive",
        "js/aw-form.directive",
        "js/aw-button.directive",
        "js/enable-when.directive",
        "js/aw-i18n.directive",
        "js/aw-break.directive"
    ],
    "data": {
        "itemid": {
            "displayName": "零件id",
            "type": "STRING",
            "isRequired": "true",
            "isEditable": "true",
            "dbValue": "",
            "dispValue": ""
        },
        "itemname": {
            "displayName": "零件名称",
            "type": "STRING",
            "isRequired": "true",
            "isEditable": "true",
            "dbValue": "",
            "dispValue": ""
        },
        "itemdesc": {
            "displayName": "描述",
            "type": "STRING",
            "isRequired": "true",
            "isEditable": "true",
            "dbValue": "",
            "dispValue": ""
        }
       
    },
    "actions": {
        "buttonAction": {
            "actionType": "JSFunction",
            "method": "createitem",
            "inputData": {
                "itemid": "{{data.itemid.dbValue}}",
                "itemname": "{{data.itemname.dbValue}}",
                "itemdesc": "{{data.itemdesc.dbValue}}"
            },
            "deps": "js/myCreateItem"
        }
    },
    "i18n": {
        "submitButtonTitle": [
            "TCUICommandPanelsMessages"
        ]
    }
}
  • 在js文件中调用创建对象的soa服务
exports.createitem = function( itemid ,itemname,itemdesc) {
      var deferred = _$q.defer();
​
      var inputData = {
          properties:
          [{
          clientId: "",
          itemId: itemid,
          name: itemname,
          type: "Item",
          revId: "A",
          uom: "String",
          description:itemdesc,
          extendedAttributes:
          [{
          objectType: "",
          attributes:
          {
          SampleStringKey: ""
          }
          }]
          }],
          container: "",
          relationType: "",
          }
​
       _soaSvc.post("Core-2006-03-DataManagement", "createItems", inputData).then(function (response) {
          var output=response.output[0];
          
          var item=output.item;
​
          _dmSvc.getProperties( [item.uid], [ "item_id","object_name"] ).then( function() {
            _msg.showInfo("id为"+item.props.item_id.dbValues+"的对象创建完成");
          })
           deferred.resolve();
         })
  };
  • 点击创建后通过messagingService服务中的showInfo方法弹出提示框提示

你可能感兴趣的:(Teamcenter开发进阶)