index.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { createSchemaField } from '@formily/react';
  2. import { Editable, FormItem, FormLayout, Input, NumberPicker, Select } from '@formily/antd';
  3. import type { ISchema } from '@formily/json-schema';
  4. import './index.less';
  5. import { DataTypeList, DateTypeList, FileTypeList } from '@/pages/device/data';
  6. import { Store } from 'jetlinks-store';
  7. import JsonParam from '@/components/Metadata/JsonParam';
  8. import EnumParam from '@/components/Metadata/EnumParam';
  9. import BooleanEnum from '@/components/Metadata/BooleanParam';
  10. const ArrayParam = () => {
  11. const SchemaField = createSchemaField({
  12. components: {
  13. FormItem,
  14. Input,
  15. Select,
  16. Editable,
  17. FormLayout,
  18. NumberPicker,
  19. JsonParam,
  20. ArrayParam,
  21. EnumParam,
  22. BooleanEnum,
  23. },
  24. });
  25. const schema: ISchema = {
  26. type: 'object',
  27. properties: {
  28. config: {
  29. type: 'void',
  30. title: '配置元素',
  31. 'x-component': 'FormLayout',
  32. 'x-component-props': {
  33. layout: 'vertical',
  34. },
  35. 'x-decorator': 'Editable.Popover',
  36. 'x-decorator-props': {
  37. className: 'config-array',
  38. placement: 'left',
  39. },
  40. 'x-reactions':
  41. "{{(field) => field.title = field.query('.void.date2').get('value') || field.title}}",
  42. properties: {
  43. type: {
  44. title: '元素类型',
  45. 'x-decorator': 'FormItem',
  46. 'x-component': 'Select',
  47. enum: DataTypeList.filter((item) => item.value !== 'array'),
  48. },
  49. scale: {
  50. title: '精度',
  51. 'x-decorator': 'FormItem',
  52. 'x-component': 'NumberPicker',
  53. 'x-reactions': {
  54. dependencies: ['.type'],
  55. fulfill: {
  56. state: {
  57. visible: "{{['float','double'].includes($deps[0])}}",
  58. },
  59. },
  60. },
  61. },
  62. unit: {
  63. title: '单位',
  64. 'x-decorator': 'FormItem',
  65. 'x-component': 'Select',
  66. 'x-visible': false,
  67. 'x-component-props': {
  68. showSearch: true,
  69. showArrow: true,
  70. filterOption: (input: string, option: any) =>
  71. option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
  72. },
  73. enum: Store.get('units'),
  74. 'x-reactions': {
  75. dependencies: ['.type'],
  76. fulfill: {
  77. state: {
  78. visible: "{{['int','float','long','double'].includes($deps[0])}}",
  79. },
  80. },
  81. },
  82. },
  83. format: {
  84. title: '时间格式',
  85. 'x-decorator': 'FormItem',
  86. 'x-component': 'Select',
  87. enum: DateTypeList,
  88. 'x-reactions': {
  89. dependencies: ['.type'],
  90. fulfill: {
  91. state: {
  92. visible: "{{['date'].includes($deps[0])}}",
  93. },
  94. },
  95. },
  96. },
  97. expands: {
  98. type: 'object',
  99. properties: {
  100. maxLength: {
  101. title: '最大长度',
  102. 'x-decorator': 'FormItem',
  103. 'x-component': 'NumberPicker',
  104. 'x-decorator-props': {
  105. tooltip: '字节',
  106. },
  107. 'x-reactions': {
  108. dependencies: ['..type'],
  109. fulfill: {
  110. state: {
  111. visible: "{{['string','password'].includes($deps[0])}}",
  112. },
  113. },
  114. },
  115. },
  116. },
  117. },
  118. booleanConfig: {
  119. title: '布尔值',
  120. 'x-decorator': 'FormItem',
  121. 'x-component': 'BooleanEnum',
  122. type: 'void',
  123. 'x-reactions': {
  124. dependencies: ['.type'],
  125. fulfill: {
  126. state: {
  127. visible: "{{['boolean'].includes($deps[0])}}",
  128. },
  129. },
  130. },
  131. },
  132. enumConfig: {
  133. title: '枚举项',
  134. type: 'void',
  135. 'x-decorator': 'FormItem',
  136. 'x-component': 'EnumParam',
  137. 'x-reactions': {
  138. dependencies: ['.type'],
  139. fulfill: {
  140. state: {
  141. visible: "{{['enum'].includes($deps[0])}}",
  142. },
  143. },
  144. },
  145. },
  146. fileType: {
  147. title: '文件类型',
  148. 'x-decorator': 'FormItem',
  149. 'x-component': 'Select',
  150. 'x-visible': false,
  151. enum: FileTypeList,
  152. 'x-reactions': {
  153. dependencies: ['.type'],
  154. fulfill: {
  155. state: {
  156. visible: "{{['file'].includes($deps[0])}}",
  157. },
  158. },
  159. },
  160. },
  161. jsonConfig: {
  162. title: 'JSON对象',
  163. type: 'void',
  164. 'x-decorator': 'FormItem',
  165. 'x-component': 'JsonParam',
  166. 'x-reactions': {
  167. dependencies: ['.type'],
  168. fulfill: {
  169. state: {
  170. visible: "{{['object'].includes($deps[0])}}",
  171. },
  172. },
  173. },
  174. },
  175. description: {
  176. title: '说明',
  177. 'x-decorator': 'FormItem',
  178. 'x-component': 'Input.TextArea',
  179. },
  180. },
  181. },
  182. },
  183. };
  184. return <SchemaField schema={schema} />;
  185. };
  186. export default ArrayParam;