用户在添加区块时,可以显示一个Form表单,用于配置参数。因此,在这里我们需要定义Form表单对应的Schema验证器

1. 定义Schema

src/suite-vendor/test-party/modules/test-party/backend/src/config/validation/schema/blocks.js

  1. 1module.exports = app => {
  2. 2 const schemas = {};
  3. 3 // blockArticleCommentCount
  4. 4 schemas.blockArticleCommentCount = {
  5. 5 type: 'object',
  6. 6 properties: {
  7. 7 interval: {
  8. 8 type: 'number',
  9. 9 ebType: 'text',
  10. 10 ebTitle: 'IntervalMS',
  11. 11 notEmpty: true,
  12. 12 },
  13. 13 },
  14. 14 };
  15. 15 return schemas;
  16. 16};

src/suite-vendor/test-party/modules/test-party/backend/src/config/validation/schemas.js

  1. 1const blocks = require('./schema/blocks.js');
  2. 2...
  3. 3
  4. 4module.exports = app => {
  5. 5 const schemas = {};
  6. 6 // blocks
  7. 7 Object.assign(schemas, blocks(app));
  8. 8 ...
  9. 9 // ok
  10. 10 return schemas;
  11. 11};

2. 国际化语言资源

src/suite-vendor/test-party/modules/test-party/front/src/config/locale/en-us.js

  1. 1export default {
  2. 2 IntervalMS: 'Interval(ms)',
  3. 3}

src/suite-vendor/test-party/modules/test-party/front/src/config/locale/zh-cn.js

  1. 1export default {
  2. 2 IntervalMS: '间隔(ms)',
  3. 3}

3. 注册Schema及验证器

  1. 1module.exports = app => {
  2. 2 const schemas = require('./config/validation/schemas.js')(app);
  3. 3 const blocks = require('./config/blocks.js')(app);
  4. 4 const meta = {
  5. 5 ...
  6. 6 validation: {
  7. 7 validators: {
  8. 8 ...
  9. 9 blockArticleCommentCount: {
  10. 10 schemas: 'blockArticleCommentCount',
  11. 11 },
  12. 12 },
  13. 13 keywords: {
  14. 14 ...
  15. 15 },
  16. 16 schemas,
  17. 17 },
  18. 18 };
  19. 19 return meta;
  20. 20};
  • 行16:注册所有定义的schema,包括前面定义的schema:blockArticleCommentCount

  • 行9:注册验证器blockArticleCommentCount