index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { createSchemaField } from '@formily/react';
  2. import { ArrayItems, FormItem, FormLayout, Input } from '@formily/antd';
  3. import type { ISchema } from '@formily/json-schema';
  4. import Editable from '../EditTable';
  5. const EnumParam = () => {
  6. const SchemaField = createSchemaField({
  7. components: {
  8. FormItem,
  9. Input,
  10. ArrayItems,
  11. Editable,
  12. FormLayout,
  13. },
  14. });
  15. const schema: ISchema = {
  16. type: 'object',
  17. properties: {
  18. elements: {
  19. type: 'array',
  20. 'x-component': 'ArrayItems',
  21. 'x-decorator': 'FormItem',
  22. 'x-validator': [
  23. {
  24. triggerType: 'onBlur',
  25. validator: (value: any[]) => {
  26. return new Promise((resolve) => {
  27. if (value.length === 0) resolve('请配置枚举项');
  28. const flag = value.every((item: any) => {
  29. return item.value && item.text;
  30. });
  31. if (!!flag) {
  32. resolve('');
  33. } else {
  34. resolve('请配置枚举项');
  35. }
  36. });
  37. },
  38. },
  39. ],
  40. 'x-reactions': {
  41. dependencies: ['.type'],
  42. fulfill: {
  43. state: {
  44. value: [{}],
  45. },
  46. },
  47. },
  48. items: {
  49. type: 'void',
  50. 'x-component': 'ArrayItems.Item',
  51. properties: {
  52. sort: {
  53. type: 'void',
  54. 'x-decorator': 'FormItem',
  55. 'x-component': 'ArrayItems.SortHandle',
  56. },
  57. popover: {
  58. type: 'object',
  59. title: '枚举项配置',
  60. 'x-decorator': 'Editable.Popover',
  61. 'x-component': 'FormLayout',
  62. 'x-component-props': {
  63. layout: 'vertical',
  64. },
  65. 'x-reactions':
  66. '{{(field)=>field.title = field.value && (field.value.text) || field.title}}',
  67. properties: {
  68. value: {
  69. type: 'string',
  70. title: 'Value',
  71. 'x-decorator': 'FormItem',
  72. 'x-component': 'Input',
  73. 'x-component-props': {
  74. placeholder: '请输入标识',
  75. },
  76. 'x-validator': [
  77. {
  78. max: 64,
  79. message: '最多可输入64个字符',
  80. },
  81. {
  82. required: true,
  83. message: '请输入Value',
  84. },
  85. ],
  86. },
  87. text: {
  88. type: 'string',
  89. title: 'Text',
  90. 'x-decorator': 'FormItem',
  91. 'x-component': 'Input',
  92. 'x-component-props': {
  93. placeholder: '对该枚举项的描述',
  94. },
  95. 'x-validator': [
  96. {
  97. max: 64,
  98. message: '最多可输入64个字符',
  99. },
  100. {
  101. required: true,
  102. message: '请输入Text',
  103. },
  104. ],
  105. },
  106. },
  107. },
  108. remove: {
  109. type: 'void',
  110. 'x-decorator': 'FormItem',
  111. 'x-component': 'ArrayItems.Remove',
  112. },
  113. },
  114. },
  115. properties: {
  116. addition: {
  117. type: 'void',
  118. title: '新增枚举项',
  119. 'x-component': 'ArrayItems.Addition',
  120. },
  121. },
  122. },
  123. },
  124. };
  125. return <SchemaField schema={schema} />;
  126. };
  127. export default EnumParam;