1.0.5 • Published 4 years ago

vue-xcrmsdk v1.0.5

Weekly downloads
132
License
-
Repository
-
Last release
4 years ago

Vue-xcrmsdk 使用说明

前言

在portal和移动开发中,使用crm webapi格式访问后台api,减少后台代码量,基本的CRUD都可使用vue-xcrmsdk实现,无需额外实现后台自定义接口

Portal版本要求

portal v6.18.5+

安装方式

  • 使用yarn
    yarn add vue-xcrmsdk
  • 使用npm
    npm install vue-xcrmsdk

引入方式 - 按需引用

import { retrieve, retrieveMultiple, create, update, fetch, deleteEntity } from '@/assets/js/crmUtil'

Begin =====vue-xcrmsdk - 1.0.x+升级注意事项===== 2019-9-11编辑

升级说明

  • 将vue-xcrmsdk升级至1.0.x+
  • 导入平台CRM最新的解决方案,包含如下操作:
    • CRUD 记录查询
    • CRUD Fetch查询
    • CRUD 创建
    • CRUD 更新
    • CRUD 删除

升级调整说明

数据结构调整
  • 查询返回数据结构变更【retrieve/retrieveMultiple】

    • PickList类型数据返回int类型,如:statecode:0
    • 原有的PickList名称默认放到FormattedValues属性中
    {
        FormattedValues:{
            statecode:是
        }
    }
    • lookup类型的结构现变更为
    {
        createdby:{
            id:"00000000-0000-0000-0000-000000000000",
            logicalname:"systemuser",
            name:"Administrator"
        },
        cratedbyname:"Administrator"
    }
    • 完整的数据结构格式
    {
        FormattedValues:{
            statecode:是,
            participatesinworkflow:否
        },
        accountid:"00000000-0000-0000-0000-000000000000",
        name:"客户",
        createdby:{
            id:"00000000-0000-0000-0000-000000000000",
            logicalname:"systemuser",
            name:"Administrator"
        },
        createdon:"2019-08-23T16:58:37.017",
        cratedbyname:"Administrator",
        participatesinworkflow:0,
        state:0
    }
  • 创建/更新提交数据结构变更【create/update】

    • 格式按照查询返回的数据结构提交
    • 更新【update】的时候带上id,如:
    accountid:"00000000-0000-0000-0000-000000000000"
调用方法变更说明
  • 入参实体名称
    • 原先使用的是复数名称,现改成单数格式
    如:accounts => account, opportunities => opportunity
  • retrieve查询指定字段调整,默认查询全部不做调整
    • 移除入参:config,原先使用的是config.select
    • 改成使用columnSet
  • create
    • 移除入参:config,原先使用的是config.select,用于查询创建后返回的查询字段
    • 现默认返回创建记录的ID
  • update
    • 移除入参:config,原先使用的是config.select,用于查询更新后返回的查询字段
    • 现默认返回当前记录的ID

crm新解决方案导入变更

  • 添加系统参数:
    • LanguageSource, 默认值: WebResource

End =====vue-xcrmsdk - 1.0.x+升级注意事项===== 2019-9-11编辑

使用方式

  • retrieve 查询单条数据
    	```
    	 //第一个参数为实体的复数
    retrieve('accounts', '01e9b6e1-f133-e911-80d1-000c2957a8ce', { select: 'name,createdon' }) .then(resp => { //resp.data 返回的结果 }) .catch(error => { rt.showErrorToast(error.message) })
    	```
  • retrieveMultiple 查询多条数据, 含返回记录总条数,对象可查看【附录-retrieveMultiple对象示例】
    	```
    	retrieveMultiple('opportunities', {
    	      entityName: 'opportunity',
    	      page: 1,
    	      count: 20,
    	      returnTotalRecordCount: true,
    	      columnSet: ['name', 'createdon']
    	    })
    	      .then((resp1,resp2) => {
    	        //resp1.data 为列表结果集
    	        //resp2.data 为返回的总记录数
    	      })
    	      .catch(error => {
    	        rt.showErrorToast(error.message)
    	      })
    	```
  • retrieveMultiple 查询多条数据, 不含返回总条数,对象可查看【附录-retrieveMultiple对象示例】
    	```
    	retrieveMultiple('opportunities', {
    	      entityName: 'opportunity',
    	      page: 1,
    	      count: 20,
    	      returnTotalRecordCount: false,
    	      columnSet: ['name', 'createdon']
    	    })
    	      .then((resp) => {
    	        //resp.data 为列表结果集
    	      })
    	      .catch(error => {
    	        rt.showErrorToast(error.message)
    	      })
    	```
  • create 创建一条记录
    	```
    create( 'accounts', { //需要创建的字段以及值 name: 'Sample Account one - 9527 - test', creditonhold: false, address1_latitude: 47.639583, description: 'This is the description ', revenue: 5000000, accountcategorycode: 1 }, { //创建后,需要返回查询的字段 select: 'name,createdby' } ) .then(resp => { //resp.data 返回的结果 }) .catch(error => { rt.showErrorToast(error.message) })
    	```
  • update 更新一条记录
    	```
    update( 'accounts', 'AF9EE779-5854-E911-80DA-000C2957A8CE', { //需要更新的字段以及值 name: 'Sample Account one - 9527 - test for update', creditonhold: false, address1_latitude: 47.639583, description: 'This is the description ', revenue: 5000000, accountcategorycode: 1 }, { //更新后需要返回查询的值 select: 'name,createdby' } ) .then(resp => { //resp.data 返回的结果 }) .catch(error => { rt.showErrorToast(error.message) })
    	```
  • fetch 使用fetch自定义查询
    	```
    	   let fetchXml = `<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    	  <entity name="account">
    	    <attribute name="name" />
    	    <attribute name="primarycontactid" />
    	    <attribute name="telephone1" />
    	    <attribute name="accountid" />
    	    <order attribute="name" descending="false" />
    	    <filter type="and">
    	      <condition attribute="name" operator="ne" value="kane" />
    	      <condition attribute="accountnumber" operator="ne" value="kane" />
    	    </filter>
    	  </entity>
    	</fetch>`
    	```
    	```
    	  fetch('accounts', fetchXml)
    	    .then(resp => {
    	      //resp.data 返回的结果
    	    })
    	    .catch(error => {
    	      rt.showErrorToast(error.message)
    	    })
    	```
  • deleteEntity 调用操作

    	```
    	 deleteEntity('accounts', '761c73fa-7544-e911-80d8-000c2957a8ce')
    	```
  • 使用invokeAction 调用操作

    	```
    	 invokeAction('new_getautonumber', {
    	      EntityName: 'account'
    	    })
    	      .then(resp => {
    	        //resp.data 返回的结果
    	      })
    	      .catch(error => {
    	        rt.showErrorToast(error.message)
    	      })
    	```
  • invokeEntityAction 调用操作
    	```
    	 invokeEntityAction('new_ord_saleorder_getorderlinelist','new_ord_invoices','DA7944A1-7262-E911-80DB-000C29C12AB0', {
    	      EntityName: 'account'
    	    })
    	      .then(resp => {
    	        //resp.data 返回的结果
    	      })
    	      .catch(error => {
    	        rt.showErrorToast(error.message)
    	      })
    	```

注意事项

  • url特殊字符转义

    由于http请求,会将url的一些特殊字符进行转义:

    所在在使用fetch调用查询的时候,查询参数包含有【%,# ,中文.....】等特殊符号的时候。 使用:encodeURIComponent('%name%') 转义后再进行fetch拼接,然后调用,不然会造成xml无效的结果

附录-retrieveMultiple对象示例

//查询数据对象
var config = {
  entityName: 'account',
  page: 1,
  count: 20,
  returnTotalRecordCount: true,
  columnSet: ['name', 'accountnumber', 'new_telephone', 'createdon'],
  order: [
    { name: 'name', descending: false },
    { name: 'createdon', descending: true }
  ],
  filter: {
    type: 'and',
    conditions: [
      { attribute: 'statecode', operator: 'eq', value: 0 },
      {
        filter: {
          type: 'or',
          conditions: [
            { attribute: 'statecode', operator: 'eq', value: 0 },
            {
              attribute: 'createdon',
              operator: 'between',
              value: [1, 2]
            },
            { attribute: 'statecode', operator: 'today' }
          ]
        }
      }
    ]
  },
  linkEntities: [
    {
      entityName: 'systemuser',
      alias: 't',
      from: 'systemuserid',
      to: 'ownerid',
      linkType: 'inner',
      columnSet: ['name', 'accountnumber', 'new_telephone', 'createdon'],
      filter: {
        type: 'and',
        conditions: [
          { attribute: 'statecode', operator: 'eq', value: 0 },
          {
            filter: {
              type: 'or',
              conditions: [
                {
                  attribute: 'statecode',
                  operator: 'eq',
                  value: 0
                },
                {
                  attribute: 'statecode',
                  operator: 'between',
                  value: [1, 2]
                },
                { attribute: 'statecode', operator: 'today' }
              ]
            }
          }
        ]
      },
      linkEntities: []
    },
    {
      entityName: 'systemuser',
      alias: 's',
      from: 'systemuserid',
      to: 'ownerid',
      linkType: 'inner',
      columnSet: ['name', 'accountnumber', 'new_telephone', 'createdon'],
      filter: {
        type: 'and',
        conditions: [
          { attribute: 'statecode', operator: 'eq', value: 0 }
        ]
      },
      linkEntities: []
    }
  ]
}
1.0.5

4 years ago

1.0.4

4 years ago

0.3.21

4 years ago

0.3.20

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

5 years ago

0.3.19

5 years ago

0.3.18

5 years ago

0.3.17

5 years ago

0.3.16

5 years ago

0.3.15

5 years ago

0.3.14

5 years ago

0.3.11

5 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago