用户在添加区块
时,可以显示一个Form表单
,用于配置参数。因此,在这里我们需要定义Form表单对应的Schema
及验证器
1. 定义Schema
src/suite-vendor/test-party/modules/test-party/backend/src/config/validation/schema/blocks.js
- 1module.exports = app => {
- 2 const schemas = {};
- 3 // blockArticleCommentCount
- 4 schemas.blockArticleCommentCount = {
- 5 type: 'object',
- 6 properties: {
- 7 interval: {
- 8 type: 'number',
- 9 ebType: 'text',
- 10 ebTitle: 'IntervalMS',
- 11 notEmpty: true,
- 12 },
- 13 },
- 14 };
- 15 return schemas;
- 16};
src/suite-vendor/test-party/modules/test-party/backend/src/config/validation/schemas.js
- 1const blocks = require('./schema/blocks.js');
- 2...
- 3
- 4module.exports = app => {
- 5 const schemas = {};
- 6 // blocks
- 7 Object.assign(schemas, blocks(app));
- 8 ...
- 9 // ok
- 10 return schemas;
- 11};
2. 国际化语言资源
src/suite-vendor/test-party/modules/test-party/front/src/config/locale/en-us.js
- 1export default {
- 2 IntervalMS: 'Interval(ms)',
- 3}
src/suite-vendor/test-party/modules/test-party/front/src/config/locale/zh-cn.js
- 1export default {
- 2 IntervalMS: '间隔(ms)',
- 3}
3. 注册Schema及验证器
- 1module.exports = app => {
- 2 const schemas = require('./config/validation/schemas.js')(app);
- 3 const blocks = require('./config/blocks.js')(app);
- 4 const meta = {
- 5 ...
- 6 validation: {
- 7 validators: {
- 8 ...
- 9 blockArticleCommentCount: {
- 10 schemas: 'blockArticleCommentCount',
- 11 },
- 12 },
- 13 keywords: {
- 14 ...
- 15 },
- 16 schemas,
- 17 },
- 18 };
- 19 return meta;
- 20};
-
行16:注册所有定义的
schema
,包括前面定义的schema:blockArticleCommentCount
-
行9:注册验证器
blockArticleCommentCount
评论: