From 3072cd67db9ea0d5467f94528109e1aa8e5d3fc0 Mon Sep 17 00:00:00 2001 From: wjh Date: Thu, 9 May 2024 16:03:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=A0=91=E5=BD=A2=E7=BB=93=E6=9E=84=E6=97=B6?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=BA=E7=BA=A7=E8=81=94=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=20(#948)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/948 Reviewed-by: sealday Co-authored-by: wjh Co-committed-by: wjh --- .../core/client/src/common/useFieldComponentName.tsx | 9 ++++++--- .../association-field/AssociationFieldProvider.tsx | 10 +++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) 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], );