diff --git a/packages/client/src/schema-component/antd/filter/DynamicComponent.tsx b/packages/client/src/schema-component/antd/filter/DynamicComponent.tsx index 61e00673b..d8a6cad3f 100644 --- a/packages/client/src/schema-component/antd/filter/DynamicComponent.tsx +++ b/packages/client/src/schema-component/antd/filter/DynamicComponent.tsx @@ -1,5 +1,6 @@ import { createForm, onFieldValueChange } from '@formily/core'; import { FieldContext, FormContext } from '@formily/react'; +import { merge } from '@formily/shared'; import React, { useContext, useMemo } from 'react'; import { SchemaComponent } from '../../core'; import { useComponent } from '../../hooks'; @@ -27,6 +28,11 @@ export const DynamicComponent = (props) => { schema={{ 'x-component': 'Input', ...props.schema, + 'x-component-props': merge(props?.schema?.['x-component-props'] || {}, { + style: { + minWidth: 150, + }, + }), name: 'value', 'x-read-pretty': false, 'x-validator': undefined, diff --git a/packages/client/src/schema-component/antd/filter/Filter.Action.Designer.tsx b/packages/client/src/schema-component/antd/filter/Filter.Action.Designer.tsx index bfe4b4d08..912f2f8e5 100644 --- a/packages/client/src/schema-component/antd/filter/Filter.Action.Designer.tsx +++ b/packages/client/src/schema-component/antd/filter/Filter.Action.Designer.tsx @@ -1,16 +1,66 @@ import { ISchema, useField, useFieldSchema } from '@formily/react'; import React from 'react'; import { useDesignable } from '../..'; +import { useCollection, useCollectionManager } from '../../../collection-manager'; import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings'; +export const useFilterableFields = (collectionName: string) => { + const { getCollectionFields, getInterface } = useCollectionManager(); + const fields = getCollectionFields(collectionName); + return fields?.filter?.((field) => { + if (!field.interface) { + return false; + } + const fieldInterface = getInterface(field.interface); + if (!fieldInterface.filterable) { + return false; + } + return true; + }); +}; + export const FilterActionDesigner = (props) => { - const initialValue = {}; const field = useField(); const fieldSchema = useFieldSchema(); const { dn } = useDesignable(); - const isPopupAction = ['create', 'update', 'view'].includes(fieldSchema['x-action'] || ''); + const { name } = useCollection(); + const fields = useFilterableFields(name); + const fieldNames = fieldSchema?.['x-component-props']?.fieldNames || []; return ( + + {fields.map((field) => { + const checked = fieldNames.includes(field.name); + return ( + { + fieldSchema['x-component-props'] = fieldSchema?.['x-component-props'] || {}; + const fieldNames = fieldSchema?.['x-component-props']?.fieldNames || []; + console.log('fieldNames.checked', value) + if (value) { + fieldNames.push(field.name); + } else { + const index = fieldNames.indexOf(field.name); + fieldNames.splice(index, 1); + } + fieldSchema['x-component-props'].fieldNames = fieldNames; + dn.emit('patch', { + schema: { + ['x-uid']: fieldSchema['x-uid'], + 'x-component-props': { + ...fieldSchema['x-component-props'], + }, + }, + }); + dn.refresh(); + }} + /> + ); + })} + + { } }} /> - {isPopupAction && ( - { - field.componentProps.openMode = value; - fieldSchema['x-component-props']['openMode'] = value; - dn.emit('patch', { - schema: { - 'x-uid': fieldSchema['x-uid'], - 'x-component-props': fieldSchema['x-component-props'], - }, - }); - dn.refresh(); - }} - /> - )} { const [visible, setVisible] = useState(false); const { designable, dn } = useDesignable(); const fieldSchema = useFieldSchema(); - const form = useMemo
(() => props.form || createForm(), [visible]); + const form = useMemo(() => props.form || createForm(), []); const { options, onSubmit, onReset, ...others } = useProps(props); return ( @@ -58,7 +58,7 @@ export const FilterAction = observer((props: any) => {