原子指令
CabloyJS将所有对业务数据的操作称为原子指令
指令分类
原子指令
分为两类:
基本指令
:create, read, write, delete, clone, enable, disable, authorize, deleteBulk, exportBulk
自定义指令
:与具体业务相关的自定义操作
基本指令
CabloyJS对基本指令
进行了统一封装,达到开箱即用
的效果。只要我们新建了业务模块,这些基本指令就自动赋能了。换句话说,在CabloyJS中采用统一的一套API来访问基本指令
此外,业务模块也可以对所有基本指令
进行扩展(二次开发),提供自定义逻辑
常量定义
模块a-base
提供了基本指令
的通用逻辑,其常量定义如下:
a-base/backend/src/config/constants.js
- 1atom: {
- 2 action: {
- 3 create: 1,
- 4 read: 2,
- 5 write: 3,
- 6 delete: 4,
- 7 clone: 5,
- 8 enable: 6,
- 9 disable: 7,
- 10
- 11 authorize: 25,
- 12
- 13 deleteBulk: 35,
- 14 exportBulk: 36,
- 15
- 16 custom: 100, // custom action start from custom
- 17 },
- 18 actionMeta: {
- 19 create: {
- 20 title: 'Create',
- 21 actionModule: moduleInfo.relativeName,
- 22 actionComponent: 'action',
- 23 bulk: true,
- 24 select: false,
- 25 icon: { material: 'add' },
- 26 },
- 27 read: {
- 28 title: 'View',
- 29 actionModule: moduleInfo.relativeName,
- 30 actionPath: '/a/basefront/atom/item?mode=view&atomId={{atomId}}&itemId={{itemId}}',
- 31 enableOnStatic: true,
- 32 enableOnOpened: true,
- 33 icon: { material: 'visibility' },
- 34 },
- 35 write: {
- 36 title: 'Edit',
- 37 actionModule: moduleInfo.relativeName,
- 38 actionComponent: 'action',
- 39 enableOnStatic: false,
- 40 enableOnOpened: false,
- 41 icon: { material: 'edit' },
- 42 },
- 43 delete: {
- 44 title: 'Delete',
- 45 actionModule: moduleInfo.relativeName,
- 46 actionComponent: 'action',
- 47 enableOnStatic: false,
- 48 enableOnOpened: false,
- 49 icon: { material: 'delete' },
- 50 },
- 51 clone: {
- 52 title: 'Clone',
- 53 actionModule: moduleInfo.relativeName,
- 54 actionComponent: 'action',
- 55 enableOnStatic: true,
- 56 enableOnOpened: true,
- 57 icon: { material: 'content_copy' },
- 58 },
- 59 enable: {
- 60 title: 'Enable',
- 61 actionModule: moduleInfo.relativeName,
- 62 actionComponent: 'action',
- 63 enableOnStatic: true,
- 64 enableOnOpened: true,
- 65 stage: 'formal',
- 66 icon: { material: 'play_arrow' },
- 67 },
- 68 disable: {
- 69 title: 'Disable',
- 70 actionModule: moduleInfo.relativeName,
- 71 actionComponent: 'action',
- 72 enableOnStatic: true,
- 73 enableOnOpened: true,
- 74 stage: 'formal',
- 75 icon: { material: 'stop' },
- 76 },
- 77 authorize: {
- 78 title: 'Authorize',
- 79 actionModule: moduleInfo.relativeName,
- 80 actionPath: '/a/basefront/resource/authorize?atomId={{atomId}}&itemId={{itemId}}',
- 81 enableOnStatic: true,
- 82 enableOnOpened: true,
- 83 stage: 'formal',
- 84 icon: { material: 'groups' },
- 85 },
- 86 deleteBulk: {
- 87 title: 'Delete',
- 88 actionModule: moduleInfo.relativeName,
- 89 actionComponent: 'actionBulk',
- 90 bulk: true,
- 91 select: true,
- 92 icon: { material: 'delete' },
- 93 },
- 94 exportBulk: {
- 95 title: 'Export',
- 96 actionModule: moduleInfo.relativeName,
- 97 actionComponent: 'actionBulk',
- 98 bulk: true,
- 99 select: null,
- 100 icon: { material: 'cloud_download' },
- 101 },
- 102 custom: {
- 103 title: 'Custom',
- 104 },
- 105 },
- 106},
名称 | 默认值 | 说明 |
---|---|---|
title | 指令的标题 | |
actionModule | 前端处理组件所属模块名 | |
actionComponent | 前端处理组件名 | |
actionPath | 前端页面组件路径 | |
bulk | false | 批量指令与列表操作相关 |
select | null | 对于批量指令,true:只有选择了条目才有效,false:没有选择条目才有效,null:总是有效 |
icon | 图标 | |
enableOnStatic | false | 对于静态数据 是否有效 |
enableOnOpened | false | 对于进入编辑状态的数据 是否有效 |
stage | 针对哪个原子阶段有效,draft/formal/history |
|
custom | 指令占位符,自定义指令 从101开始 |
指令定制
比如,我们可以在业务模块test-party
中重新定义create和read指令的实现逻辑
可以通过模块meta
定义中的base.atoms.[atomClass].actions.[actionName]
节点覆盖基本指令的常量定义
只需提供actionModule + actionComponent
或者actionModule + actionPath
即可
src/suite-vendor/test-party/modules/test-party/backend/src/meta.js
- 1base: {
- 2 atoms: {
- 3 party: {
- 4 actions: {
- 5 create: {
- 6 actionModule: moduleInfo.relativeName,
- 7 actionComponent: 'action',
- 8 },
- 9 read: {
- 10 actionModule: moduleInfo.relativeName,
- 11 actionPath: '/a/basefront/atom/item?mode=view&atomId={{atomId}}&itemId={{itemId}}',
- 12 },
- 13 },
- 14 },
- 15 },
- 16},
名称 | 说明 |
---|---|
actionModule + actionComponent | 通过自定义的前端组件执行指令 |
actionModule + actionPath | 直接打开自定义的前端页面。如果actionPath是绝对路径,actionModule可以忽略 |
评论: