lu-lowcode-package-form 0.11.94 → 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 +257 -256
- package/dist/index.es.js +19433 -19421
- package/package.json +1 -1
- package/src/components/field/select/search-select.jsx +8 -2
- package/src/components/form-container/index.jsx +4 -2
- package/src/utils/formula.js +5 -4
package/package.json
CHANGED
@@ -20,6 +20,12 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
20
20
|
const callbackQueue = useRef([]);
|
21
21
|
const debounceFetchOptionsRef = useRef(null);
|
22
22
|
|
23
|
+
const getOptions = () => {
|
24
|
+
return nOptions
|
25
|
+
}
|
26
|
+
const setOptions = (options) => {
|
27
|
+
setNOptions(options)
|
28
|
+
}
|
23
29
|
|
24
30
|
useEffect(() => {
|
25
31
|
// console.log("SearchSelect useEffect props", props)
|
@@ -264,7 +270,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
264
270
|
|
265
271
|
</OriginalSelect>
|
266
272
|
{!props?.disabled && rightIcon}
|
267
|
-
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName, recordFieldsChange, getAllWithIds, removeLastFieldsValues })}
|
273
|
+
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName, recordFieldsChange, getAllWithIds, removeLastFieldsValues,getOptions,setOptions })}
|
268
274
|
</BaseWrapper>
|
269
275
|
) : (<>
|
270
276
|
<OriginalSelect
|
@@ -283,7 +289,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
283
289
|
|
284
290
|
</OriginalSelect>
|
285
291
|
{!props?.disabled && rightIcon}
|
286
|
-
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName, recordFieldsChange, getAllWithIds, removeLastFieldsValues })}
|
292
|
+
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName, recordFieldsChange, getAllWithIds, removeLastFieldsValues,getOptions,setOptions })}
|
287
293
|
</>
|
288
294
|
)
|
289
295
|
|
@@ -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();
|