order: 7 group: order: 3 title: 高级用法

toc: content

列表的展示

列表的展示对于简单需求占位太多,复杂需求定制不够一直是痛点。所以我们给出了 5 种展示,充分满足从极简到复杂的所有需求。

  1. 默认展示使用 widget: ‘cardList’,卡片类型,用于展示数量不太多但结构复杂的 list
  1. import React from 'react';
  2. import Form from '../demo/display';
  3. const schema = {
  4. type: 'object',
  5. properties: {
  6. listName2: {
  7. title: '对象数组',
  8. description: '对象数组嵌套功能',
  9. type: 'array',
  10. // widget: 'cardList',
  11. items: {
  12. type: 'object',
  13. properties: {
  14. input1: {
  15. title: '简单输入框',
  16. type: 'string',
  17. required: true,
  18. },
  19. select1: {
  20. title: '单选',
  21. type: 'string',
  22. enum: ['a', 'b', 'c'],
  23. enumNames: ['早', '中', '晚'],
  24. default: 'a',
  25. },
  26. obj: {
  27. title: '对象',
  28. type: 'object',
  29. properties: {
  30. input1: {
  31. title: '简单输入框',
  32. type: 'string',
  33. required: true,
  34. default: '卡片列表',
  35. },
  36. select1: {
  37. title: '单选',
  38. type: 'string',
  39. enum: ['a', 'b', 'c'],
  40. enumNames: ['早', '中', '晚'],
  41. },
  42. },
  43. },
  44. },
  45. },
  46. },
  47. },
  48. };
  49. const Demo = () => {
  50. return <Form schema={schema} />;
  51. };
  52. export default Demo;



  1. widget: ‘simpleList’ 用于展示每行只有 1-3 个简单元素的情况
  1. import React from 'react';
  2. import Form from '../demo/display';
  3. const schema = {
  4. type: 'object',
  5. properties: {
  6. listName2: {
  7. title: '对象数组',
  8. description: '对象数组嵌套功能',
  9. type: 'array',
  10. widget: 'simpleList',
  11. items: {
  12. type: 'object',
  13. properties: {
  14. input1: {
  15. title: '简单输入框',
  16. type: 'string',
  17. required: true,
  18. },
  19. select1: {
  20. title: '单选',
  21. type: 'string',
  22. enum: ['a', 'b', 'c'],
  23. enumNames: ['早', '中', '晚'],
  24. },
  25. },
  26. },
  27. },
  28. },
  29. };
  30. const Demo = () => {
  31. return <Form schema={schema} />;
  32. };
  33. export default Demo;



  1. widget: ‘tableList’ 用于展示每行只有 3 - n 个简单元素的情况,特别是数据量很大需要分页的
  1. import React from 'react';
  2. import Form from '../demo/display';
  3. const schema = {
  4. type: 'object',
  5. properties: {
  6. listName2: {
  7. title: '对象数组',
  8. description: '对象数组嵌套功能',
  9. type: 'array',
  10. widget: 'tableList',
  11. items: {
  12. type: 'object',
  13. properties: {
  14. input1: {
  15. title: '简单输入框',
  16. type: 'string',
  17. required: true,
  18. },
  19. input2: {
  20. title: '简单输入框2',
  21. type: 'string',
  22. },
  23. input3: {
  24. title: '简单输入框3',
  25. type: 'string',
  26. },
  27. select1: {
  28. title: '单选',
  29. type: 'string',
  30. enum: ['a', 'b', 'c'],
  31. enumNames: ['早', '中', '晚'],
  32. widget: 'select',
  33. },
  34. },
  35. },
  36. },
  37. },
  38. };
  39. const Demo = () => {
  40. return <Form schema={schema} />;
  41. };
  42. export default Demo;



  1. widget: ‘drawerList’ 用于展示存在列表套列表,列表套对象等复杂元素的情况
  1. import React from 'react';
  2. import Form from '../demo/display';
  3. const schema = {
  4. type: 'object',
  5. properties: {
  6. listName2: {
  7. title: '对象数组',
  8. description: '对象数组嵌套功能',
  9. type: 'array',
  10. widget: 'drawerList',
  11. items: {
  12. type: 'object',
  13. properties: {
  14. input1: {
  15. title: '简单输入框',
  16. type: 'string',
  17. required: true,
  18. },
  19. select1: {
  20. title: '单选',
  21. type: 'string',
  22. enum: ['a', 'b', 'c'],
  23. enumNames: ['早', '中', '晚'],
  24. },
  25. listName2: {
  26. title: '对象数组',
  27. description: '对象数组嵌套功能',
  28. type: 'array',
  29. widget: 'simpleList',
  30. props: {
  31. hideMove: true,
  32. },
  33. items: {
  34. type: 'object',
  35. properties: {
  36. input1: {
  37. title: '简单输入框',
  38. type: 'string',
  39. required: true,
  40. },
  41. select1: {
  42. title: '单选',
  43. type: 'string',
  44. enum: ['a', 'b', 'c'],
  45. enumNames: ['早', '中', '晚'],
  46. },
  47. },
  48. },
  49. },
  50. },
  51. },
  52. },
  53. },
  54. };
  55. const Demo = () => {
  56. return <Form schema={schema} />;
  57. };
  58. export default Demo;



  1. widget: ‘tabList’ 用于展示可新增/关闭页签的 Tabs 标签页
  1. import React from 'react';
  2. import Form from '../demo/display';
  3. const schema = {
  4. type: 'object',
  5. properties: {
  6. tabsName1: {
  7. title: '对象数组',
  8. description: '对象数组嵌套功能',
  9. type: 'array',
  10. widget: 'tabList',
  11. props: {
  12. type: 'editable-card',
  13. tabName: '项目', // 选项卡显示文字,对应antd中Tabs的tab属性。 这里也可以是数组
  14. draggable: true, // 是否可拖拽
  15. },
  16. items: {
  17. type: 'object',
  18. properties: {
  19. input1: {
  20. title: '简单输入框',
  21. type: 'string',
  22. required: true,
  23. },
  24. select1: {
  25. title: '单选',
  26. type: 'string',
  27. enum: ['a', 'b', 'c'],
  28. enumNames: ['早', '中', '晚'],
  29. },
  30. listName1: {
  31. title: '对象数组',
  32. type: 'array',
  33. widget: 'list1',
  34. props: {
  35. hideMove: true,
  36. },
  37. items: {
  38. type: 'object',
  39. properties: {
  40. input1: {
  41. title: '简单输入框',
  42. type: 'string',
  43. required: true,
  44. },
  45. select1: {
  46. title: '单选',
  47. type: 'string',
  48. enum: ['a', 'b', 'c'],
  49. enumNames: ['早', '中', '晚'],
  50. },
  51. },
  52. },
  53. },
  54. },
  55. },
  56. },
  57. },
  58. };
  59. const Demo = () => <Form schema={schema} />;
  60. export default Demo;



  1. widget: ‘virtualList’ 在展示上与 ‘tableList’ 基本相同,但以虚拟滚动替代了传统的分页
  1. import React from 'react';
  2. import Form from '../demo/display';
  3. const schema = {
  4. type: 'object',
  5. properties: {
  6. listName2: {
  7. title: '对象数组',
  8. description: '对象数组嵌套功能',
  9. type: 'array',
  10. widget: 'virtualList',
  11. itemProps: {
  12. buttons: [
  13. {
  14. callback: 'hello',
  15. text: '复制',
  16. },
  17. ],
  18. },
  19. items: {
  20. type: 'object',
  21. properties: {
  22. input1: {
  23. title: '简单输入框',
  24. type: 'string',
  25. required: true,
  26. },
  27. input2: {
  28. title: '简单输入框2',
  29. type: 'string',
  30. },
  31. input3: {
  32. title: '简单输入框3',
  33. type: 'string',
  34. },
  35. select1: {
  36. title: '单选',
  37. type: 'string',
  38. enum: ['a', 'b', 'c'],
  39. enumNames: ['早', '中', '晚'],
  40. widget: 'select',
  41. },
  42. },
  43. },
  44. },
  45. },
  46. };
  47. const Demo = () => {
  48. return <Form schema={schema} />;
  49. };
  50. export default Demo;