From c7569e12fd7225e5daf5316358a9385e40495ddf Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Thu, 7 Nov 2024 20:13:15 +0800 Subject: [PATCH] fix: fix linkage rules issue in subtable --- .../useLinkageRulesForSubTableOrSubForm.ts | 30 +++++++++++++++---- .../client/src/schema-initializer/utils.ts | 6 +++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/form-item/hooks/useLinkageRulesForSubTableOrSubForm.ts b/packages/core/client/src/schema-component/antd/form-item/hooks/useLinkageRulesForSubTableOrSubForm.ts index 835b5e6f3b..7495028aa9 100644 --- a/packages/core/client/src/schema-component/antd/form-item/hooks/useLinkageRulesForSubTableOrSubForm.ts +++ b/packages/core/client/src/schema-component/antd/form-item/hooks/useLinkageRulesForSubTableOrSubForm.ts @@ -9,27 +9,47 @@ /* eslint-disable react-hooks/rules-of-hooks */ import { Field } from '@formily/core'; -import { useField, useFieldSchema } from '@formily/react'; +import { Schema, useField, useFieldSchema } from '@formily/react'; import { useEffect } from 'react'; -import { useFlag } from '../../../../flag-provider'; import { bindLinkageRulesToFiled } from '../../../../schema-settings/LinkageRules/bindLinkageRulesToFiled'; import { forEachLinkageRule } from '../../../../schema-settings/LinkageRules/forEachLinkageRule'; import useLocalVariables from '../../../../variables/hooks/useLocalVariables'; import useVariables from '../../../../variables/hooks/useVariables'; import { useSubFormValue } from '../../association-field/hooks'; +import { isSubMode } from '../../association-field/util'; + +const useIsSubFormOrSubTableField = () => { + const isSubFormOrSubTableField = (fieldSchema: Schema) => { + while (fieldSchema) { + if (isSubMode(fieldSchema)) { + return true; + } + + if (fieldSchema['x-component'] === 'FormV2') { + return false; + } + + fieldSchema = fieldSchema.parent; + } + + return false; + }; + + return { isSubFormOrSubTableField }; +}; /** * used to bind the linkage rules of the sub-table or sub-form with the current field */ export const useLinkageRulesForSubTableOrSubForm = () => { - const { isInSubForm, isInSubTable } = useFlag(); + const fieldSchema = useFieldSchema(); + const { isSubFormOrSubTableField } = useIsSubFormOrSubTableField(); - if (!isInSubForm && !isInSubTable) { + if (!isSubFormOrSubTableField(fieldSchema)) { return; } const field = useField(); - const fieldSchema = useFieldSchema(); const { fieldSchema: schemaOfSubTableOrSubForm, formValue } = useSubFormValue(); const localVariables = useLocalVariables(); const variables = useVariables(); diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index e2d6de8c82..252829cd8e 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -152,6 +152,8 @@ export function useTableColumnInitializerFields() { display: 'none', }, }, + // 目前版本 1.4.0-alpha.2,先在这里占个位,后面会用到 + 'x-use-decorator-props': isSubTable ? 'useSubTableFormItemProps' : 'useTableFormItemProps', }; // interfaceConfig?.schemaInitialize?.(schema, { field, readPretty: true, block: 'Table' }); return { @@ -176,7 +178,7 @@ export function useTableColumnInitializerFields() { } export function useAssociatedTableColumnInitializerFields() { - const { name, fields } = useCollection_deprecated(); + const { fields } = useCollection_deprecated(); const { t } = useTranslation(); const { getInterface, getCollectionFields, getCollection } = useCollectionManager_deprecated(); const groups = fields @@ -346,6 +348,8 @@ export function useInheritsTableColumnInitializerFields() { display: 'none', }, }, + // 目前版本 1.4.0-alpha.2,先在这里占个位,后面会用到 + 'x-use-decorator-props': isSubTable ? 'useSubTableFormItemProps' : 'useTableFormItemProps', }; return { name: k?.uiSchema?.title || k.name,