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 databaseStatic Resource
is implemented on the basis ofStatic 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
- 1module.exports = app => {
- 2 const moduleInfo = app.meta.mockUtil.parseInfoFromPackage(__dirname);
- 3 const resources = [
- 4 // menu
- 5 {
- 6 atomName: 'Kitchen-sink',
- 7 atomStaticKey: 'kitchenSink',
- 8 atomRevision: 1,
- 9 atomCategoryId: 'a-base:menu.Tools',
- 10 resourceType: 'a-base:menu',
- 11 resourceConfig: JSON.stringify({
- 12 actionModule: moduleInfo.relativeName,
- 13 actionPath: 'kitchen-sink/index',
- 14 }),
- 15 resourceIcon: ':business:kitchen-set',
- 16 appKey: 'test-party:appParty',
- 17 resourceRoles: 'root',
- 18 },
- 19 ];
- 20 return resources;
- 21};
-
atomName
:The resource name, supporting i18n. Here, menu’s name isKitchen-sink
-
atomStaticKey
:The system will automatically add the module name as a prefix to form the unique atom key. Here istest-party:kitchenSink
-
atomRevision
: Start at 0. When there is any attribute change in the static resource, theatomRevision
will be incremented in order, and the system will automatically update the data in the database -
atomCategoryId
: Resource Category- Format:
{resourceType}.{category}
resourceType
: The modulea-base
provides a resource typemenu
, which is calleda-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 directorycategory
: 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
- Format:
-
resourceType
: Resource Type, here isa-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 Apptest-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
- Simple role name, such as
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
- 1const staticResources = require('./config/static/resources.js')(app);
- 2
- 3base: {
- 4 statics: {
- 5 'a-base.resource': {
- 6 items: staticResources,
- 7 },
- 8 },
- 9},
Name | Description |
---|---|
a-base.resource | Atom Class of Resource. Here is a-base.resource |
items | Array of static resources |
Comments: