数据字典除了用在编辑查看两个场景外,还经常用在搜索场景。比如,我们可以按国家检索宴会清单,也可以按城市检索宴会清单。由于城市树型三级字典,因此我们甚至可以按任意层级检索

下面就分别介绍国家城市如何设置搜索条件,因为他们刚好对应着数组型树型两种类别的数据字典

数组型数据字典

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

  1. 1 schemas.partySearch = {
  2. 2 type: 'object',
  3. 3 properties: {
  4. 4 ...
  5. 5 partyCountry: {
  6. 6 type: 'string',
  7. 7 ebType: 'dict',
  8. 8 ebTitle: 'Party Country',
  9. 9 ebParams: {
  10. 10 dictKey: 'a-dictbooster:countries',
  11. 11 mode: 'select',
  12. 12 },
  13. 13 ebOptionsBlankAuto: true,
  14. 14 },
  15. 15 ...
  16. 16 },
  17. 17 };

参数说明请参见:如何使用数组型数据字典:前端表单渲染

树型数据字典

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

  1. 1 schemas.partySearch = {
  2. 2 type: 'object',
  3. 3 properties: {
  4. 4 ...
  5. 5 partyCity: {
  6. 6 type: 'string',
  7. 7 ebType: 'component',
  8. 8 ebTitle: 'Party City',
  9. 9 ebRender: {
  10. 10 module: moduleInfo.relativeName,
  11. 11 name: 'renderPartyCity',
  12. 12 },
  13. 13 ebParams: {
  14. 14 separator: '/',
  15. 15 leafOnly: false,
  16. 16 },
  17. 17 ebSearch: {
  18. 18 operators: 'likeRight',
  19. 19 },
  20. 20 },
  21. 21 },
  22. 22 };

参数说明请参见:如何实现数据字典间的联动:前端表单渲染

在这里需要重点说明的有如下两点:

  • ebParams.leafOnly:设置为false,意味着可以选择任何层级的字典项

  • ebSearch:专门用于搜索功能的配置项

    • operators:指定当前字段所支持的SQL查询条件的操作符。设置为likeRight,从而构造形如partyCity like ‘110000/110100/%‘的SQL查询条件,从而实现任意层级的检索操作