Resource Classification

Resources are mainly divided into two categories:

  • Dynamic Resource: The resource can be created through the management UI page

  • Static Resource: The resource is managed by code. When the system started, it is automatically initialized to the database

    • Static Resource is implemented on the basis of Static Atom. See: Static Atom

Menu is a type of Resource

As mentioned earlier, a menu is a type of resource. Therefore, you can create a menu by creating a static resource. Next, take the module test-party as an example to create a menu:

Define Static Resource/Menu

Define a static resource array

src/suite-vendor/test-party/modules/test-party/backend/src/config/static/resources.js

  1. 1module.exports = app => {
  2. 2 const moduleInfo = app.meta.mockUtil.parseInfoFromPackage(__dirname);
  3. 3 const resources = [
  4. 4 // menu
  5. 5 {
  6. 6 atomName: 'Kitchen-sink',
  7. 7 atomStaticKey: 'kitchenSink',
  8. 8 atomRevision: 1,
  9. 9 atomCategoryId: 'a-base:menu.Tools',
  10. 10 resourceType: 'a-base:menu',
  11. 11 resourceConfig: JSON.stringify({
  12. 12 actionModule: moduleInfo.relativeName,
  13. 13 actionPath: 'kitchen-sink/index',
  14. 14 }),
  15. 15 resourceIcon: ':business:kitchen-set',
  16. 16 appKey: 'test-party:appParty',
  17. 17 resourceRoles: 'root',
  18. 18 },
  19. 19 ];
  20. 20 return resources;
  21. 21};
  • atomName:The resource name, supporting i18n. Here, menu’s name is Kitchen-sink

  • atomStaticKey:The system will automatically add the module name as a prefix to form the unique atom key. Here is test-party:kitchenSink

  • atomRevision: Start at 0. When there is any attribute change in the static resource, the atomRevision will be incremented in order, and the system will automatically update the data in the database

  • atomCategoryId: Resource Category

    • Format: {resourceType}.{category}
    • resourceType: The module a-base provides a resource type menu, which is called a-base:menu. Because the resource types provided by different modules are managed uniformly, the full name of the resource type is used as the first level directory to facilitate the classification management of the resource directory
    • category: Resource Category
    • The system will automatically parse the category structure to get the category id, and automatically create it if the category does not exist
  • resourceType: Resource Type, here is a-base:menu

  • resourceConfig: Resource configuration information. Different types of resources have different structural conventions

  • resourceConfig.actionModule + actionPath: This is how menu resources are defined: when you click a menu item, the path of the front page will be displayed

  • resourceIcon: Resource Icon, here is menu icon :business:kitchen-set

  • appKey: Applicaition’s atomStaticKey. Here is Party App test-party:appParty

    • Associate menu resources with App to determine which menu resources are displayed by App. See: 将菜单资源与App应用关联,从而决定App应用显示哪些菜单资源。参见:About Application
  • resourceRoles: Specify resource authorization object. The system will automatically resolve the role name to get the role Id and authorize the resource. The following optional values are available:

    • Simple role name, such as authenticated
    • Multi-level role name, such as template.system
    • More role name by comma, such as authenticated,template.system

Register Static Resource/Menu

After defining a set of static resources, you need to register them in the module’s meta file

src/suite-vendor/test-party/modules/test-party/backend/src/meta.js

  1. 1const staticResources = require('./config/static/resources.js')(app);
  2. 2
  3. 3base: {
  4. 4 statics: {
  5. 5 'a-base.resource': {
  6. 6 items: staticResources,
  7. 7 },
  8. 8 },
  9. 9},
Name Description
a-base.resource Atom Class of Resource. Here is a-base.resource
items Array of static resources