| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- import { createSchemaField } from '@formily/react';
- import { 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';
- import Editable from '../EditTable';
- interface Props {
- isFunction?: boolean;
- }
- const ArrayParam = (props: Props) => {
- 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' && item.value !== 'object',
- // ['int', 'long', 'float', 'double', 'string', 'boolean', 'date'].includes(item.value),
- ),
- 'x-validator': [
- {
- required: true,
- message: '请选择元素类型',
- },
- ],
- },
- scale: {
- title: '精度',
- 'x-decorator': 'FormItem',
- 'x-component': 'NumberPicker',
- 'x-component-props': {
- min: 1,
- },
- default: 2,
- 'x-validator': [
- {
- format: 'integer',
- message: '请输入0-2147483647之间的正整数',
- },
- {
- max: 2147483647,
- message: '请输入0-2147483647之间的正整数',
- },
- {
- min: 0,
- message: '请输入0-2147483647之间的正整数',
- },
- ],
- 'x-reactions': {
- dependencies: ['.type'],
- fulfill: {
- state: {
- visible: !props.isFunction && "{{['float','double'].includes($deps[0])}}",
- },
- },
- },
- },
- unit: {
- title: '单位',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- 'x-visible': false,
- 'x-component-props': {
- showSearch: true,
- allowClear: 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:
- !props.isFunction && "{{['int','float','long','double'].includes($deps[0])}}",
- },
- },
- },
- },
- format: {
- title: '时间格式',
- 'x-decorator': 'FormItem',
- 'x-component': 'Select',
- enum: DateTypeList,
- default: 'string',
- 'x-validator': [
- {
- required: true,
- message: '请选择时间格式',
- },
- ],
- 'x-visible': false,
- // 'x-reactions': {
- // dependencies: ['.type'],
- // fulfill: {
- // state: {
- // visible: "{{['date'].includes($deps[0])}}",
- // },
- // },
- // },
- },
- expands: {
- type: 'object',
- properties: {
- maxLength: {
- title: '最大长度',
- 'x-decorator': 'FormItem',
- 'x-component': 'NumberPicker',
- 'x-component-props': {
- min: 1,
- },
- 'x-decorator-props': {
- tooltip: '字节',
- },
- 'x-validator': [
- {
- format: 'integer',
- message: '请输入1-2147483647之间的正整数',
- },
- {
- max: 2147483647,
- message: '请输入1-2147483647之间的正整数',
- },
- {
- min: 1,
- message: '请输入1-2147483647之间的正整数',
- },
- ],
- 'x-reactions': {
- dependencies: ['..type'],
- fulfill: {
- state: {
- visible: !props.isFunction && "{{['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-component-props': {
- isFunction: props.isFunction,
- },
- '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;
|