lu-lowcode-package-form 0.11.95 → 0.11.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +28 -27
- package/dist/index.es.js +380 -376
- package/package.json +1 -1
- package/src/components/form-container/index.jsx +4 -2
- package/src/utils/formula.js +5 -4
package/package.json
CHANGED
@@ -552,7 +552,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
552
552
|
if (dependencyMap.current.has(childIdentifier)) {
|
553
553
|
const childData = dependencyMap.current.get(childIdentifier);
|
554
554
|
if (formula && formula.length > 0) {
|
555
|
-
const
|
555
|
+
const __current = fieldValues[childIdentifier]
|
556
|
+
const formulaResult = (evalFormula(formula, __current) == "true");
|
556
557
|
// console.log(`${childIdentifier} 计算公式:`, formula)
|
557
558
|
// console.log(`${childIdentifier} 计算结果:`, formulaResult)
|
558
559
|
// console.log(`${childIdentifier} childData.show:`, childData.show)
|
@@ -689,7 +690,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
689
690
|
}
|
690
691
|
|
691
692
|
if (formula && formula.length > 0) {
|
692
|
-
const
|
693
|
+
const __current = fieldValues[childIdentifier]
|
694
|
+
const formulaResult = evalFormula(formula, __current);
|
693
695
|
console.log(`${childIdentifier} 计算公式:`, formula)
|
694
696
|
console.log(`${childIdentifier} 计算结果:`, formulaResult)
|
695
697
|
|
package/src/utils/formula.js
CHANGED
@@ -3,21 +3,22 @@ import Decimal from 'decimal.js';
|
|
3
3
|
|
4
4
|
// 不安全的Function函数,有时间的话需要重新编写公式编译器
|
5
5
|
// 可以使用库 expr-eval 来替换(undo)
|
6
|
-
const evalFormula = memoizee((formula) => {
|
6
|
+
const evalFormula = memoizee((formula, current) => {
|
7
7
|
let result = "";
|
8
8
|
let funcCode = "";
|
9
9
|
try {
|
10
10
|
// 注入 Decimal 库并包装计算逻辑
|
11
11
|
funcCode = `
|
12
|
-
const D = Decimal;
|
12
|
+
const D = opts.Decimal;
|
13
|
+
const __current = opts.__current;
|
13
14
|
const decimal = (num) => new D(num);
|
14
15
|
return (function() {
|
15
16
|
const __result = ${formula.join("")};
|
16
17
|
return __result;
|
17
18
|
})()
|
18
19
|
`;
|
19
|
-
const func = new Function('
|
20
|
-
result = func(Decimal);
|
20
|
+
const func = new Function('opts', funcCode);
|
21
|
+
result = func({Decimal,__current:current});
|
21
22
|
// result = eval(formula.join(""));
|
22
23
|
if (!(typeof result === "object" && result !== null))
|
23
24
|
result = result.toString();
|