原子指令

CabloyJS将所有对业务数据的操作称为原子指令

指令分类

原子指令分为两类:

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

基本指令

CabloyJS对基本指令进行了统一封装,达到开箱即用的效果。只要我们新建了业务模块,这些基本指令就自动赋能了。换句话说,在CabloyJS中采用统一的一套API来访问基本指令

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

常量定义

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

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

  1. 1atom: {
  2. 2 action: {
  3. 3 create: 1,
  4. 4 read: 2,
  5. 5 write: 3,
  6. 6 delete: 4,
  7. 7 clone: 5,
  8. 8 enable: 6,
  9. 9 disable: 7,
  10. 10
  11. 11 authorize: 25,
  12. 12
  13. 13 deleteBulk: 35,
  14. 14 exportBulk: 36,
  15. 15
  16. 16 custom: 100, // custom action start from custom
  17. 17 },
  18. 18 actionMeta: {
  19. 19 create: {
  20. 20 title: 'Create',
  21. 21 actionModule: moduleInfo.relativeName,
  22. 22 actionComponent: 'action',
  23. 23 bulk: true,
  24. 24 select: false,
  25. 25 icon: { material: 'add' },
  26. 26 },
  27. 27 read: {
  28. 28 title: 'View',
  29. 29 actionModule: moduleInfo.relativeName,
  30. 30 actionPath: '/a/basefront/atom/item?mode=view&atomId={{atomId}}&itemId={{itemId}}',
  31. 31 enableOnStatic: true,
  32. 32 enableOnOpened: true,
  33. 33 icon: { material: 'visibility' },
  34. 34 },
  35. 35 write: {
  36. 36 title: 'Edit',
  37. 37 actionModule: moduleInfo.relativeName,
  38. 38 actionComponent: 'action',
  39. 39 enableOnStatic: false,
  40. 40 enableOnOpened: false,
  41. 41 icon: { material: 'edit' },
  42. 42 },
  43. 43 delete: {
  44. 44 title: 'Delete',
  45. 45 actionModule: moduleInfo.relativeName,
  46. 46 actionComponent: 'action',
  47. 47 enableOnStatic: false,
  48. 48 enableOnOpened: false,
  49. 49 icon: { material: 'delete' },
  50. 50 },
  51. 51 clone: {
  52. 52 title: 'Clone',
  53. 53 actionModule: moduleInfo.relativeName,
  54. 54 actionComponent: 'action',
  55. 55 enableOnStatic: true,
  56. 56 enableOnOpened: true,
  57. 57 icon: { material: 'content_copy' },
  58. 58 },
  59. 59 enable: {
  60. 60 title: 'Enable',
  61. 61 actionModule: moduleInfo.relativeName,
  62. 62 actionComponent: 'action',
  63. 63 enableOnStatic: true,
  64. 64 enableOnOpened: true,
  65. 65 stage: 'formal',
  66. 66 icon: { material: 'play_arrow' },
  67. 67 },
  68. 68 disable: {
  69. 69 title: 'Disable',
  70. 70 actionModule: moduleInfo.relativeName,
  71. 71 actionComponent: 'action',
  72. 72 enableOnStatic: true,
  73. 73 enableOnOpened: true,
  74. 74 stage: 'formal',
  75. 75 icon: { material: 'stop' },
  76. 76 },
  77. 77 authorize: {
  78. 78 title: 'Authorize',
  79. 79 actionModule: moduleInfo.relativeName,
  80. 80 actionPath: '/a/basefront/resource/authorize?atomId={{atomId}}&itemId={{itemId}}',
  81. 81 enableOnStatic: true,
  82. 82 enableOnOpened: true,
  83. 83 stage: 'formal',
  84. 84 icon: { material: 'groups' },
  85. 85 },
  86. 86 deleteBulk: {
  87. 87 title: 'Delete',
  88. 88 actionModule: moduleInfo.relativeName,
  89. 89 actionComponent: 'actionBulk',
  90. 90 bulk: true,
  91. 91 select: true,
  92. 92 icon: { material: 'delete' },
  93. 93 },
  94. 94 exportBulk: {
  95. 95 title: 'Export',
  96. 96 actionModule: moduleInfo.relativeName,
  97. 97 actionComponent: 'actionBulk',
  98. 98 bulk: true,
  99. 99 select: null,
  100. 100 icon: { material: 'cloud_download' },
  101. 101 },
  102. 102 custom: {
  103. 103 title: 'Custom',
  104. 104 },
  105. 105 },
  106. 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

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