CabloyJS将所有业务数据的操作称为原子指令,主要分两类:

  1. 基本指令create, read, write, delete, clone, enable, disable, authorize, deleteBulk, exportBulk
  2. 自定义指令:与具体业务相关的自定义操作

CabloyJS对基本指令进行了统一封装,达到开箱即用的效果。只要我们新建了业务模块,这些基本指令就自动赋能了

此外,业务模块也可以对所有基本指令进行扩展,提供自定义逻辑

常量定义

模块a-base提供了基本指令的通用逻辑,其常量定义如下:

a-base/backend/src/config/constants.js

atom: {
  action: {
    create: 1,
    read: 2,
    write: 3,
    delete: 4,
    clone: 5,
    enable: 6,
    disable: 7,

    authorize: 25,

    deleteBulk: 35,
    exportBulk: 36,

    custom: 100, // custom action start from custom
  },
  actionMeta: {
    create: {
      title: 'Create',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      bulk: true,
      select: false,
      icon: { material: 'add' },
    },
    read: {
      title: 'View',
      actionModule: moduleInfo.relativeName,
      actionPath: '/a/basefront/atom/item?mode=view&atomId={{atomId}}&itemId={{itemId}}',
      enableOnStatic: true,
      enableOnOpened: true,
      icon: { material: 'visibility' },
    },
    write: {
      title: 'Edit',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      enableOnStatic: false,
      enableOnOpened: false,
      icon: { material: 'edit' },
    },
    delete: {
      title: 'Delete',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      enableOnStatic: false,
      enableOnOpened: false,
      icon: { material: 'delete' },
    },
    clone: {
      title: 'Clone',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      enableOnStatic: true,
      enableOnOpened: true,
      icon: { material: 'content_copy' },
    },
    enable: {
      title: 'Enable',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      enableOnStatic: true,
      enableOnOpened: true,
      stage: 'formal',
      icon: { material: 'play_arrow' },
    },
    disable: {
      title: 'Disable',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      enableOnStatic: true,
      enableOnOpened: true,
      stage: 'formal',
      icon: { material: 'stop' },
    },
    authorize: {
      title: 'Authorize',
      actionModule: moduleInfo.relativeName,
      actionPath: '/a/basefront/resource/authorize?atomId={{atomId}}&itemId={{itemId}}',
      enableOnStatic: true,
      enableOnOpened: true,
      stage: 'formal',
      icon: { material: 'groups' },
    },
    deleteBulk: {
      title: 'Delete',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'actionBulk',
      bulk: true,
      select: true,
      icon: { material: 'delete' },
    },
    exportBulk: {
      title: 'Export',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'actionBulk',
      bulk: true,
      select: null,
      icon: { material: 'cloud_download' },
    },
    custom: {
      title: 'Custom',
    },
  },
},
名称 默认值 说明
title 指令的标题
actionModule 前端处理组件所属模块名
actionComponent 前端处理组件名
actionPath 前端页面组件路径
bulk false 批量指令与列表操作相关
select null 对于批量指令,true:只有选择了条目才有效,false:没有选择条目才有效,null:总是有效
icon 图标
enableOnStatic false 对于静态数据是否有效
enableOnOpened false 对于进入编辑状态的数据是否有效
stage 针对哪个原子阶段有效,draft/formal/history
custom 指令占位符,自定义指令从101开始

指令定制

可以通过模块meta定义中的base.atoms.[atomClass].actions.[actionName]节点覆盖基本指令的常量定义

只需提供actionModule + actionComponent或者actionModule + actionPath 即可

base: {
  atoms: {
    party: {
      actions: {
        create: {
          actionModule: moduleInfo.relativeName,
          actionComponent: 'action',
        },
        read: {
          actionModule: moduleInfo.relativeName,
          actionPath: '/a/basefront/atom/item?mode=view&atomId={{atomId}}&itemId={{itemId}}',
        },
      },
    },
  },
},
名称 说明
actionModule + actionComponent 通过自定义的前端组件执行指令
actionModule + actionPath 直接打开自定义的前端页面。如果actionPath是绝对路径,actionModule可以忽略