perf: using evaluator to reduce package size
This commit is contained in:
parent
f06518a05c
commit
a5c5df6864
@ -17,7 +17,6 @@
|
||||
"copy-to-clipboard": "^3.3.3",
|
||||
"exceljs": "^4.4.0",
|
||||
"fs-extra": "^11.1.1",
|
||||
"mathjs2": "npm:mathjs@^10.6.0",
|
||||
"qrcode": "^1.5.1",
|
||||
"dayjs": "^1.11.8",
|
||||
"qrcode.react": "^3.1.0",
|
||||
|
@ -4,7 +4,7 @@ import { Input } from '@nocobase/client';
|
||||
import { Descriptions, DescriptionsProps } from 'antd';
|
||||
import _ from 'lodash';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { evaluate } from 'mathjs2';
|
||||
import { evaluators } from '@nocobase/evaluators/client';
|
||||
|
||||
const transformFormula = (formula: string) => {
|
||||
if (!formula) return [];
|
||||
@ -20,6 +20,8 @@ export const CalcResult = (props) => {
|
||||
const field = useField();
|
||||
const path: any = field.path.entire;
|
||||
const fieldPath = path?.replace(`.${fieldSchema.name}`, '');
|
||||
const engine = evaluators.get('math.js');
|
||||
const evaluate = engine.evaluate.bind(engine);
|
||||
const defaultValue = fieldSchema.name === 'subtotal' ? '¥0.00' : [];
|
||||
const [value, setValue] = useState<string | DescriptionsProps['items']>(defaultValue);
|
||||
|
||||
@ -69,7 +71,7 @@ export const CalcResult = (props) => {
|
||||
const varName = 'var' + count;
|
||||
const varValue = value;
|
||||
scopes[varName] = varValue;
|
||||
calculateData.push(varName);
|
||||
calculateData.push('{{' + varName + '}}');
|
||||
} else {
|
||||
calculateData.push(item);
|
||||
}
|
||||
@ -88,7 +90,7 @@ export const CalcResult = (props) => {
|
||||
result = pre + main + suf;
|
||||
} catch (error) {
|
||||
result = `${code}`;
|
||||
console.warn('code: ' + code + ' scopes: ' + scopes + 'error: ' + result + ' error message ' + error.message);
|
||||
console.warn('code: ', code, ' scopes: ', scopes, 'error: ', result, ' error message ', error.message);
|
||||
}
|
||||
setValue(result.toString());
|
||||
} else if (panel) {
|
||||
|
@ -18037,7 +18037,7 @@ matchdep@^2.0.0:
|
||||
resolve "^1.4.0"
|
||||
stack-trace "0.0.10"
|
||||
|
||||
"mathjs2@npm:mathjs@^10.6.0", mathjs@^10.6.0, mathjs@^10.6.1:
|
||||
mathjs@^10.6.0, mathjs@^10.6.1:
|
||||
version "10.6.4"
|
||||
resolved "https://registry.npmmirror.com/mathjs/-/mathjs-10.6.4.tgz#1b87a1268781d64f0c8b4e5e1b36cf7ecf58bb05"
|
||||
integrity sha512-omQyvRE1jIy+3k2qsqkWASOcd45aZguXZDckr3HtnTYyXk5+2xpVfC3kATgbO2Srjxlqww3TVdhD0oUdZ/hiFA==
|
||||
|
Loading…
Reference in New Issue
Block a user