diff --git a/packages/plugins/@hera/plugin-core/src/client/hooks/useFilterBlockActionProps.tsx b/packages/plugins/@hera/plugin-core/src/client/hooks/useFilterBlockActionProps.tsx index 82a0f9786..e717e3c4d 100644 --- a/packages/plugins/@hera/plugin-core/src/client/hooks/useFilterBlockActionProps.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/hooks/useFilterBlockActionProps.tsx @@ -122,7 +122,6 @@ export const useFilterBlockActionProps = () => { const param = block.service.params?.[0] || {}; // 保留原有的 filter const storedFilter = block.service.params?.[1]?.filters || {}; - storedFilter[uid] = removeNullCondition( transformToFilter(form.values, fieldSchema, getCollectionJoinField, name), fieldSchema, diff --git a/packages/plugins/@hera/plugin-core/src/client/index.tsx b/packages/plugins/@hera/plugin-core/src/client/index.tsx index 31e8df038..977193e29 100644 --- a/packages/plugins/@hera/plugin-core/src/client/index.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/index.tsx @@ -90,6 +90,7 @@ import { useGetCustomComponents } from './hooks/useGetCustomComponents'; import { SwiperBlock, SwiperBlockInitializer } from './schema-initializer/SwiperBlockInitializer'; import { NoticeBlock, NoticeBlockInitializer } from './schema-initializer/NoticeBlockInitializer'; import { TabSearchBlock, TabSearchBlockInitializer } from './schema-initializer/TabSearchBlockInitializer'; +import { AutoComplete } from './schema-components/AutoComplete/AutoComplete'; export enum CustomComponentType { CUSTOM_FORM_ITEM, @@ -197,6 +198,7 @@ export class PluginCoreClient extends Plugin { EditTitleField, AfterSuccess, GroupBlockConfigure, + AutoComplete, Menu: { ...Menu, // @ts-ignore diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/AutoComplete/AutoComplete.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/AutoComplete/AutoComplete.tsx new file mode 100644 index 000000000..9b33f77bd --- /dev/null +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/AutoComplete/AutoComplete.tsx @@ -0,0 +1,55 @@ +import React, { useEffect, useState } from 'react'; +import { AutoComplete as AntdAutoComplete } from 'antd'; +import { useFieldSchema, useForm } from '@formily/react'; +import { useDesigner } from '@nocobase/client'; + +export const AutoComplete = (props) => { + const fieldSchema = useFieldSchema(); + const { fieldNames, options: defultOptions } = fieldSchema['x-component-props']; + const defultValue = defultOptions.map((item) => { + item['label'] = item[fieldNames.label]; + item['value'] = item[fieldNames.value]; + return item; + }); + const [options, setOptions] = useState([...defultValue]); + const [value, setValue] = useState(''); + const form = useForm(); + if (!form.values['custom']) { + form.values['custom'] = {}; + } + + const onSearch = (data) => { + if (data) { + const searchValue = defultValue.filter((item) => item[fieldNames.label].includes(data)); + if (searchValue.length) { + setOptions(searchValue); + } else { + setOptions([]); + } + const valueLabel = options.filter((item) => item.value === data)[0]; + if (valueLabel) { + setValue(valueLabel.label); + form.values.custom[fieldSchema['collectionName']] = valueLabel; + } else { + setValue(data); + form.values.custom[fieldSchema['collectionName']] = {}; + form.values.custom[fieldSchema['collectionName']][fieldNames.label] = data; + } + } else { + setValue(data); + setOptions(defultValue); + } + }; + + return ( + { + onSearch(value); + }} + onChange={(data) => onSearch(data)} + allowClear + /> + ); +}; diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx index 44c82512c..3e01599b4 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx @@ -40,6 +40,7 @@ export const useFieldComponents = () => { const { t } = useTranslation(); const options = [ { label: t('Input'), value: 'Input' }, + { label: t('AutoComplete'), value: 'AutoComplete' }, { label: t('Select'), value: 'Select' }, ]; return { @@ -147,6 +148,7 @@ export const FilterCustomItemInitializer: React.FC<{ }, }, 'x-compoent-custom': true, + collectionName: collection, }), );