diff --git a/packages/core/client/src/collection-manager/Configuration/ConfigurationTable.tsx b/packages/core/client/src/collection-manager/Configuration/ConfigurationTable.tsx index a71fe52dd..1bb81e927 100644 --- a/packages/core/client/src/collection-manager/Configuration/ConfigurationTable.tsx +++ b/packages/core/client/src/collection-manager/Configuration/ConfigurationTable.tsx @@ -1,11 +1,14 @@ -import { useForm } from '@formily/react'; +import { Field } from '@formily/core'; +import { useFieldSchema, useForm } from '@formily/react'; import { action } from '@formily/reactive'; import { uid } from '@formily/shared'; -import React, { useEffect, useState } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { useRequest } from '../../api-client'; import { useRecord } from '../../record-provider'; import { SchemaComponent, useActionContext, useCompile } from '../../schema-component'; +import { useCollection } from '../hooks'; import { useCollectionManager } from '../hooks/useCollectionManager'; +import { DataSourceContext } from '../sub-table'; import { AddSubFieldAction } from './AddSubFieldAction'; import { EditSubFieldAction } from './EditSubFieldAction'; import { collectionSchema } from './schemas/collections'; @@ -149,6 +152,19 @@ const useBulkDestroySubField = () => { }; }; +const useCurrentFields = () => { + const record = useRecord(); + + if (record.__parent && record.__parent.interface === 'subTable') { + const ctx = useContext(DataSourceContext); + return ctx.dataSource; + } + + const { getCollectionFields } = useCollectionManager(); + const fields = getCollectionFields(record.collectionName || record.name) as any[]; + return fields; +} + export const ConfigurationTable = () => { const { collections = [] } = useCollectionManager(); const compile = useCompile(); @@ -173,6 +189,7 @@ export const ConfigurationTable = () => { useCollectionValues, useAsyncDataSource, loadCollections, + useCurrentFields, }} /> diff --git a/packages/core/client/src/collection-manager/interfaces/formula.ts b/packages/core/client/src/collection-manager/interfaces/formula.ts index b9776e81d..c0cd44984 100644 --- a/packages/core/client/src/collection-manager/interfaces/formula.ts +++ b/packages/core/client/src/collection-manager/interfaces/formula.ts @@ -32,8 +32,9 @@ export const formula: IField = { 'x-component': 'Formula.Expression', 'x-decorator': 'FormItem', 'x-component-props': { - 'supports': ['number', 'percent'] - } + 'supports': ['number', 'percent'], + 'useCurrentFields': '{{ useCurrentFields }}' + }, }, 'uiSchema.x-component-props.step': { type: 'string', diff --git a/packages/core/client/src/schema-component/antd/formula-input/FormulaInput.tsx b/packages/core/client/src/schema-component/antd/formula-input/FormulaInput.tsx index 4ae630a20..b037c2e4f 100644 --- a/packages/core/client/src/schema-component/antd/formula-input/FormulaInput.tsx +++ b/packages/core/client/src/schema-component/antd/formula-input/FormulaInput.tsx @@ -1,23 +1,16 @@ -import { CloseOutlined, LoadingOutlined } from '@ant-design/icons'; -import { useFormLayout } from '@formily/antd'; import { Field, onFormSubmitValidateStart } from '@formily/core'; import { connect, mapProps, mapReadPretty, useField, useFieldSchema, useFormEffects } from '@formily/react'; -import { isValid } from '@formily/shared'; import { Button, Input, Popover, Tag, Menu, Dropdown } from 'antd'; -import React, { useEffect, useRef, useState } from 'react'; +import React, { useContext, useEffect, useRef, useState } from 'react'; import ContentEditable from 'react-contenteditable'; import { useTranslation } from 'react-i18next'; import * as math from 'mathjs'; -import { useCollectionManager } from '../../../collection-manager/hooks'; -import { useRecord } from '../../../record-provider'; const AntdFormulaInput = (props) => { - const { value, onChange, supports } = props; + const { value, onChange, supports, useCurrentFields } = props; const field = useField(); const { t } = useTranslation(); - const record = useRecord(); - const { getCollectionFields } = useCollectionManager(); - const fields = getCollectionFields(record.collectionName || record.name) as any[]; + const fields = useCurrentFields(); const inputRef = useRef(); const [dropdownVisible, setDropdownVisible] = useState(false); @@ -121,7 +114,8 @@ const AntdFormulaInput = (props) => { export const FormulaInput = connect( AntdFormulaInput, - mapProps(), + mapProps({ + }), ); export default FormulaInput; \ No newline at end of file diff --git a/packages/core/client/src/schema-component/antd/percent/Percent.tsx b/packages/core/client/src/schema-component/antd/percent/Percent.tsx index ae5fa13ff..39f223e2f 100644 --- a/packages/core/client/src/schema-component/antd/percent/Percent.tsx +++ b/packages/core/client/src/schema-component/antd/percent/Percent.tsx @@ -2,6 +2,7 @@ import { connect, mapReadPretty } from '@formily/react'; import { InputNumber } from 'antd'; import React from 'react'; import { ReadPretty } from '../input-number/ReadPretty'; +import * as math from 'mathjs'; export const Percent = connect( (props) => { @@ -11,16 +12,16 @@ export const Percent = connect( { if (onChange) { - onChange(v / 100); + onChange(math.round(v / 100, 9)); } }} /> ); }, mapReadPretty((props) => { - return (); + return (); }), );