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 86f24a35ec)
This commit is contained in:
lyf-coder 2022-10-10 15:54:57 +08:00 committed by chenos
parent 72372f34e9
commit 7b371706ef
2 changed files with 10 additions and 15 deletions

View File

@ -33,7 +33,7 @@ export const formula: IField = {
'x-component': 'Formula.Expression', 'x-component': 'Formula.Expression',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component-props': { 'x-component-props': {
'supports': ['number', 'percent'], 'supports': ['number', 'percent', 'integer'],
'useCurrentFields': '{{ useCurrentFields }}' 'useCurrentFields': '{{ useCurrentFields }}'
}, },
}, },

View File

@ -20,22 +20,17 @@ const AntdCompute = (props) => {
let result; let result;
try { try {
result = math.evaluate(expression, scope); result = math.evaluate(expression, scope);
result = math.round(result, 9); result = Number.isFinite(result) ? math.round(result, 9) : null;
} catch {} } catch{}
if (onChange) { if (onChange) {
onChange(result); onChange(result);
} }
}) });
}) });
return (
<InputNumber {...others} readOnly stringMode={true} />
);
}
export const Compute = connect( return <InputNumber {...others} readOnly stringMode={true} />;
AntdCompute, };
mapReadPretty(ReadPretty)
);
export default Compute; export const Compute = connect(AntdCompute, mapReadPretty(ReadPretty));
export default Compute;