lu-lowcode-package-form 0.11.95 → 0.11.98

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lu-lowcode-package-form",
3
- "version": "0.11.95",
3
+ "version": "0.11.98",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^4.8.1",
6
6
  "@dnd-kit/core": "^6.1.0",
@@ -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 formulaResult = (evalFormula(formula) == "true");
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 formulaResult = evalFormula(formula);
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
 
@@ -3,21 +3,23 @@ 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
+ console.log("evalFormula current",current);
9
10
  try {
10
11
  // 注入 Decimal 库并包装计算逻辑
11
12
  funcCode = `
12
- const D = Decimal;
13
+ const D = opts.Decimal;
14
+ const __current = opts.__current;
13
15
  const decimal = (num) => new D(num);
14
16
  return (function() {
15
17
  const __result = ${formula.join("")};
16
18
  return __result;
17
19
  })()
18
20
  `;
19
- const func = new Function('Decimal', funcCode);
20
- result = func(Decimal);
21
+ const func = new Function('opts', funcCode);
22
+ result = func({Decimal,__current:current});
21
23
  // result = eval(formula.join(""));
22
24
  if (!(typeof result === "object" && result !== null))
23
25
  result = result.toString();