From e0ed2aeb7c73091f93beccbef0b4e713321bbed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=98=B6?= Date: Wed, 15 Jun 2022 21:28:51 +0800 Subject: [PATCH] fix: formula bug --- .../antd/formula-input/Compute.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/formula-input/Compute.tsx b/packages/core/client/src/schema-component/antd/formula-input/Compute.tsx index e5a8b58ff..b28feee10 100644 --- a/packages/core/client/src/schema-component/antd/formula-input/Compute.tsx +++ b/packages/core/client/src/schema-component/antd/formula-input/Compute.tsx @@ -3,18 +3,16 @@ import { connect, mapReadPretty, useFieldSchema, useFormEffects } from '@formily import { InputNumber } from 'antd'; import _ from 'lodash'; import * as math from 'mathjs'; -import React, { useState } from 'react'; +import React from 'react'; import { useCollection } from '../../../collection-manager/hooks'; import { ReadPretty } from '../input-number/ReadPretty'; const AntdCompute = (props) => { - const { value, onChange, step } = props; - // const { expression } = useCollectionField(); + const { onChange, ...others } = props; const { getField } = useCollection(); const fieldSchema = useFieldSchema(); const options = getField(fieldSchema.name); const { expression } = options; - const [computeValue, setComputeValue] = useState(value); useFormEffects(() => { onFormValuesChange((form) => { @@ -24,17 +22,14 @@ const AntdCompute = (props) => { result = math.evaluate(expression, scope); result = math.round(result, 9); } catch {} - if (result) { - setComputeValue(result); - if (onChange) { - onChange(result); - } + if (onChange) { + onChange(result); } }) }) return ( - + ); }