diff --git a/packages/core/client/src/common/useFieldComponentName.tsx b/packages/core/client/src/common/useFieldComponentName.tsx index e4e58739c..9897020ed 100644 --- a/packages/core/client/src/common/useFieldComponentName.tsx +++ b/packages/core/client/src/common/useFieldComponentName.tsx @@ -2,21 +2,24 @@ import { Field } from '@tachybase/schema'; import { useField, useFieldSchema } from '@tachybase/schema'; import { useIsFileField } from '../schema-component/antd/form-item/FormItem.Settings'; import { useColumnSchema } from '../schema-component/antd/table-v2/Table.Column.Decorator'; -import { useCollectionField } from '../data-source'; +import { useCollectionField, useCollectionManager } from '../data-source'; export function useFieldComponentName(): string { const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema(); const field = useField(); + const cm = useCollectionManager(); const isFileField = useIsFileField(); const schema = useFieldSchema(); const targetCollectionField = useCollectionField(); + const targetCollection = cm.getCollection(targetCollectionField?.target); + const isTreeCollection = targetCollection?.template === 'tree'; const fieldSchema = tableColumnSchema || schema; const collectionField = tableColumnField || targetCollectionField; - const map = { // AssociationField 的 mode 默认值是 Select - AssociationField: 'Select', + AssociationField: isTreeCollection ? 'Cascader' : 'Select', }; + const fieldComponentName = fieldSchema?.['x-component-props']?.['mode'] || field?.componentProps?.['mode'] || diff --git a/packages/core/client/src/schema-component/antd/association-field/AssociationFieldProvider.tsx b/packages/core/client/src/schema-component/antd/association-field/AssociationFieldProvider.tsx index dac49e127..a2c6aa77e 100644 --- a/packages/core/client/src/schema-component/antd/association-field/AssociationFieldProvider.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/AssociationFieldProvider.tsx @@ -23,8 +23,16 @@ export const AssociationFieldProvider = observer( // eslint-disable-next-line react-hooks/exhaustive-deps [fieldSchema['x-collection-field']], ); + const isTreeCollection = useMemo( + () => getCollection(collectionField?.target)?.template === 'tree', + // eslint-disable-next-line react-hooks/exhaustive-deps + [fieldSchema['x-collection-field']], + ); + const currentMode = useMemo( - () => fieldSchema['x-component-props']?.mode || (isFileCollection ? 'FileManager' : 'Select'), + () => + fieldSchema['x-component-props']?.mode || + (isTreeCollection ? 'Cascader' : isFileCollection ? 'FileManager' : 'Select'), // eslint-disable-next-line react-hooks/exhaustive-deps [fieldSchema['x-component-props']?.mode], );