CabloyJS将所有明细数据的操作称为明细指令,主要分两类:

  1. 基本指令create, read, write, delete, clone, moveUp, moveDown
  2. 自定义指令:与具体业务相关的自定义操作

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

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

常量定义

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

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

detail: {
  action: {
    create: 1,
    read: 2,
    write: 3,
    delete: 4,
    clone: 5,
    moveUp: 6,
    moveDown: 7,

    save: 51,

    custom: 100, // custom action start from custom
  },
  actionMeta: {
    create: {
      title: 'Create',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      bulk: true,
      icon: { material: 'add' },
      inherit: 'write',
      mode: 'edit',
      stage: 'draft',
    },
    read: {
      title: 'View',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      icon: { material: 'visibility' },
      inherit: 'read',
      mode: 'view',
      stage: '',
    },
    write: {
      title: 'Edit',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      icon: { material: 'edit' },
      inherit: 'write',
      mode: 'edit',
      stage: 'draft',
    },
    delete: {
      title: 'Delete',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      icon: { material: 'delete' },
      inherit: 'write',
      mode: 'edit',
      stage: 'draft',
    },
    clone: {
      title: 'Clone',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      icon: { material: 'content_copy' },
      inherit: 'write',
      mode: 'edit',
      stage: 'draft',
    },
    moveUp: {
      title: 'Move Up',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      icon: { material: 'arrow_upward' },
      inherit: 'write',
      mode: 'edit',
      stage: 'draft',
    },
    moveDown: {
      title: 'Move Down',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      icon: { material: 'arrow_downward' },
      inherit: 'write',
      mode: 'edit',
      stage: 'draft',
    },
    save: {
      title: 'Save',
      actionModule: moduleInfo.relativeName,
      actionComponent: 'action',
      authorize: false,
      icon: { material: 'save' },
      inherit: 'write',
      mode: 'edit',
      stage: 'draft',
    },
    custom: {
      title: 'Custom',
    },
  },
},
名称 默认值 说明
title 指令的标题
actionModule 前端处理组件所属模块名
actionComponent 前端处理组件名
actionPath 前端页面组件路径
bulk false 批量指令与列表操作相关
icon 图标
inherit 权限继承自哪个原子指令
mode 在哪个场景使用:edit/view,如果为空就是同时支持edit/view
stage 针对哪个原子阶段有效,draft/formal/history
custom 指令占位符,自定义指令从101开始

指令定制

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

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

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