From 7b371706ef8d4cff41462cb8b4054c0b91306588 Mon Sep 17 00:00:00 2001
From: lyf-coder <58352715+lyf-coder@users.noreply.github.com>
Date: Mon, 10 Oct 2022 15:54:57 +0800
Subject: [PATCH] fix(formula): support integer and fix NaN error (#879)
* fix(formula): support integer and fix NaN error
* style(formula-input): remove debugger
(cherry picked from commit 86f24a35ec25d415b5319aba4de7b509774683fd)
---
.../collection-manager/interfaces/formula.ts | 2 +-
.../antd/formula-input/Compute.tsx | 23 ++++++++-----------
2 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/packages/core/client/src/collection-manager/interfaces/formula.ts b/packages/core/client/src/collection-manager/interfaces/formula.ts
index 949c44d5e..99e41a26c 100644
--- a/packages/core/client/src/collection-manager/interfaces/formula.ts
+++ b/packages/core/client/src/collection-manager/interfaces/formula.ts
@@ -33,7 +33,7 @@ export const formula: IField = {
'x-component': 'Formula.Expression',
'x-decorator': 'FormItem',
'x-component-props': {
- 'supports': ['number', 'percent'],
+ 'supports': ['number', 'percent', 'integer'],
'useCurrentFields': '{{ useCurrentFields }}'
},
},
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 b28feee10..e69293d7a 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
@@ -20,22 +20,17 @@ const AntdCompute = (props) => {
let result;
try {
result = math.evaluate(expression, scope);
- result = math.round(result, 9);
- } catch {}
+ result = Number.isFinite(result) ? math.round(result, 9) : null;
+ } catch{}
if (onChange) {
onChange(result);
}
- })
- })
-
- return (
-
- );
-}
+ });
+ });
-export const Compute = connect(
- AntdCompute,
- mapReadPretty(ReadPretty)
-);
+ return ;
+};
-export default Compute;
\ No newline at end of file
+export const Compute = connect(AntdCompute, mapReadPretty(ReadPretty));
+
+export default Compute;