| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import { createSchemaField } from '@formily/react';
- import { Editable, FormItem, FormLayout, Input, NumberPicker, Select } from '@formily/antd';
- import type { ISchema } from '@formily/json-schema';
- import './index.less';
- import { DataTypeList, DateTypeList, FileTypeList } from '@/pages/device/data';
- import { Store } from 'jetlinks-store';
- import JsonParam from '@/components/Metadata/JsonParam';
- import EnumParam from '@/components/Metadata/EnumParam';
- import BooleanEnum from '@/components/Metadata/BooleanParam';
- const ArrayParam = () => {
- const SchemaField = createSchemaField({
- components: {
- FormItem,
- Input,
- Select,
- Editable,
- FormLayout,
- NumberPicker,
- JsonParam,
- ArrayParam,
- EnumParam,
- BooleanEnum,
- },
- });
- const schema: ISchema = {
- type: 'object',
- properties: {
- config: {
- type: 'void',
- title: '配置元素',
- 'x-component': 'FormLayout',
- 'x-component-props': {
- layout: 'vertical',
- },
- 'x-decorator': 'Editable.Popover',
- 'x-decorator-props': {
- className: 'config-array',
- placement: 'left',
- },
- 'x-reactions':
- "{{(field) => field.title = field.query('.void.date2').get('value') || field.title}}",
- properties: {
- type: {
- title: '元素类型',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- enum: DataTypeList.filter((item) => item.value !== 'array'),
- },
- scale: {
- title: '精度',
- 'x-decorator': 'FormItem',
- 'x-component': 'NumberPicker',
- 'x-reactions': {
- dependencies: ['.type'],
- fulfill: {
- state: {
- visible: "{{['float','double'].includes($deps[0])}}",
- },
- },
- },
- },
- unit: {
- title: '单位',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- 'x-visible': false,
- 'x-component-props': {
- showSearch: true,
- showArrow: true,
- filterOption: (input: string, option: any) =>
- option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
- },
- enum: Store.get('units'),
- 'x-reactions': {
- dependencies: ['.type'],
- fulfill: {
- state: {
- visible: "{{['int','float','long','double'].includes($deps[0])}}",
- },
- },
- },
- },
- format: {
- title: '时间格式',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- enum: DateTypeList,
- 'x-reactions': {
- dependencies: ['.type'],
- fulfill: {
- state: {
- visible: "{{['date'].includes($deps[0])}}",
- },
- },
- },
- },
- expands: {
- type: 'object',
- properties: {
- maxLength: {
- title: '最大长度',
- 'x-decorator': 'FormItem',
- 'x-component': 'NumberPicker',
- 'x-decorator-props': {
- tooltip: '字节',
- },
- 'x-reactions': {
- dependencies: ['..type'],
- fulfill: {
- state: {
- visible: "{{['string','password'].includes($deps[0])}}",
- },
- },
- },
- },
- },
- },
- booleanConfig: {
- title: '布尔值',
- 'x-decorator': 'FormItem',
- 'x-component': 'BooleanEnum',
- type: 'void',
- 'x-reactions': {
- dependencies: ['.type'],
- fulfill: {
- state: {
- visible: "{{['boolean'].includes($deps[0])}}",
- },
- },
- },
- },
- enumConfig: {
- title: '枚举项',
- type: 'void',
- 'x-decorator': 'FormItem',
- 'x-component': 'EnumParam',
- 'x-reactions': {
- dependencies: ['.type'],
- fulfill: {
- state: {
- visible: "{{['enum'].includes($deps[0])}}",
- },
- },
- },
- },
- fileType: {
- title: '文件类型',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- 'x-visible': false,
- enum: FileTypeList,
- 'x-reactions': {
- dependencies: ['.type'],
- fulfill: {
- state: {
- visible: "{{['file'].includes($deps[0])}}",
- },
- },
- },
- },
- jsonConfig: {
- title: 'JSON对象',
- type: 'void',
- 'x-decorator': 'FormItem',
- 'x-component': 'JsonParam',
- 'x-reactions': {
- dependencies: ['.type'],
- fulfill: {
- state: {
- visible: "{{['object'].includes($deps[0])}}",
- },
- },
- },
- },
- description: {
- title: '说明',
- 'x-decorator': 'FormItem',
- 'x-component': 'Input.TextArea',
- },
- },
- },
- },
- };
- return <SchemaField schema={schema} />;
- };
- export default ArrayParam;
|