lu-lowcode-package-form 0.11.5 → 0.11.7

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.5",
3
+ "version": "0.11.7",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^4.8.1",
6
6
  "@dnd-kit/core": "^6.1.0",
package/src/App.jsx CHANGED
@@ -244,6 +244,32 @@ function App() {
244
244
  "content": "当前表单.开关"
245
245
  }
246
246
  },
247
+ {
248
+ "insert": " == 1\n"
249
+ }
250
+ ],
251
+ "version": 1734400834533,
252
+ "withData": [
253
+
254
+ ]
255
+ }}
256
+ />
257
+ <Field.Input label="测试 withVisible2" __id="withVisible2"
258
+ isRequired={true}
259
+ withIds={["routeType"]}
260
+ withVisible={{
261
+ "value": [
262
+ {
263
+ "insert": {
264
+ "span": true
265
+ },
266
+ "attributes": {
267
+ "id": "routeType",
268
+ "color": "blue",
269
+ "tagKey": "fieldsValue",
270
+ "content": "当前表单.开关2"
271
+ }
272
+ },
247
273
  {
248
274
  "insert": " == 2\n"
249
275
  }
@@ -254,7 +280,32 @@ function App() {
254
280
  ]
255
281
  }}
256
282
  />
283
+ <Field.Input label="测试 withVisible21" __id="withVisible21"
284
+ isRequired={true}
285
+ withIds={["routeType"]}
286
+ withVisible={{
287
+ "value": [
288
+ {
289
+ "insert": {
290
+ "span": true
291
+ },
292
+ "attributes": {
293
+ "id": "routeType",
294
+ "color": "blue",
295
+ "tagKey": "fieldsValue",
296
+ "content": "当前表单.开关2"
297
+ }
298
+ },
299
+ {
300
+ "insert": " == 2\n"
301
+ }
302
+ ],
303
+ "version": 1734400834533,
304
+ "withData": [
257
305
 
306
+ ]
307
+ }}
308
+ />
258
309
  <Field.Select label="绑定表单"
259
310
  option_label={"formTitle"}
260
311
  __id="menuFormTemplateId"
@@ -267,6 +318,9 @@ function App() {
267
318
  }} />
268
319
 
269
320
 
321
+ <Field.Input label="隐藏字段" __id="hidden1"
322
+ calcHidden={true}
323
+ />
270
324
 
271
325
  <Field.Input label="菜单URL" __id="route"
272
326
  withIds={["routeType"]}
@@ -39,7 +39,7 @@ export const BaseWrapper = ({
39
39
  {
40
40
  console.log(label+" calcHiddenRef.current", calcHiddenRef.current)
41
41
  console.log(label+" calcHiddenRef.current", calcHidden)
42
- typeof initializeFormRender == "function" && initializeFormRender();
42
+ // typeof initializeFormRender == "function" && initializeFormRender();
43
43
  calcHiddenRef.current = calcHidden;
44
44
  }
45
45
  },[calcHidden])
@@ -7,7 +7,7 @@ import { nanoid } from 'nanoid';
7
7
  import { eventEmitter } from '../../utils/events'
8
8
 
9
9
 
10
- function batchElements(elements, groupSize) {
10
+ function batchElements(elements, groupSize,dmap) {
11
11
  const groupedElements = [];
12
12
  let tempArray = [];
13
13
 
@@ -29,7 +29,11 @@ function batchElements(elements, groupSize) {
29
29
  groupedElements.push([element]);
30
30
  } else {
31
31
  tempArray.push(element);
32
- const visibleElementsCount = tempArray.filter(el => !el?.props?.calcHidden).length;
32
+ const visibleElementsCount = tempArray.filter(el => {
33
+ const identifier = el.props?.componentId || el.props?.__id;
34
+ const isShow = !dmap.has(identifier) || dmap.get(identifier)?.show;
35
+ return isShow && !el?.props?.calcHidden
36
+ }).length;
33
37
  if (visibleElementsCount === groupSize) {
34
38
  groupedElements.push(tempArray);
35
39
  tempArray = [];
@@ -41,7 +45,6 @@ function batchElements(elements, groupSize) {
41
45
  fillWithReactElement(groupSize, tempArray);
42
46
  groupedElements.push(tempArray);
43
47
  }
44
-
45
48
  return groupedElements;
46
49
  }
47
50
 
@@ -78,6 +81,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
78
81
  // 添加节流后的 initializeFormRender
79
82
  const throttledInitializeFormRender = React.useCallback(
80
83
  throttle(() => {
84
+ console.log("throttledInitializeFormRender")
81
85
  initializeDependencyMap();
82
86
  setFormContent(renderChildren());
83
87
  }, 300),
@@ -157,18 +161,18 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
157
161
  };
158
162
 
159
163
  // 初始化字段的级联关系
160
- const initializeFieldVisibility = async (reloadFields = false) => {
161
- console.log("initializeFieldVisibility")
164
+ const initializeFieldVisibility = debounce(async (reloadFields = false) => {
165
+ console.log("initializeFieldVisibility *************************************")
162
166
  const fieldValues = form.getFieldsValue();
163
167
  for (let key of dependencyMap.current.keys()) {
164
- handleFieldsWith(key, fieldValues, true);
168
+ await handleFieldsWith(key, fieldValues, true);
165
169
  }
166
170
  if (reloadFields) setFormContent(renderChildren());
167
- };
171
+ }, 100);
168
172
 
169
173
  // 计算字段级联关系
170
174
  const handleFieldsWith = async (identifier, fieldValues, init = false) => {
171
- console.log("handleFieldsWith identifier", identifier)
175
+ // console.log("handleFieldsWith identifier", identifier)
172
176
  let needRefresh = false;
173
177
  let parentIdentifier = [];
174
178
  if (Array.isArray(identifier)) {
@@ -639,11 +643,13 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
639
643
  console.log("renderChildren")
640
644
  const childrenArray = React.Children.toArray(children);
641
645
  const groupedChildren = batchElements(
642
- childrenArray.filter(child => {
643
- const identifier = child.props.componentId || child.props.__id;
644
- return !dependencyMap.current.has(identifier) || dependencyMap.current.get(identifier)?.show;
645
- }),
646
- cols
646
+ childrenArray,
647
+ // childrenArray.filter(child => {
648
+ // const identifier = child.props.componentId || child.props.__id;
649
+ // return !dependencyMap.current.has(identifier) || dependencyMap.current.get(identifier)?.show;
650
+ // }),
651
+ cols,
652
+ dependencyMap.current
647
653
  );
648
654
 
649
655
 
@@ -660,7 +666,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
660
666
  }
661
667
  const isLayoutComponent = componentName && componentName.startsWith('Layout.');
662
668
  const isTable = componentName && componentName == 'Field.Table';
663
- const hidden = props.calcHidden && mode != "desgin";
669
+ const isShow = !dependencyMap.current.has(identifier) || dependencyMap.current.get(identifier)?.show;
670
+ const hidden = (props.calcHidden || !isShow) && mode != "desgin";
664
671
 
665
672
  const rules = []
666
673
  if (props.isRequired)
@@ -740,7 +747,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
740
747
  return (
741
748
  <Col
742
749
  key={identifier || `col-${index}`}
743
- span={props.calcHidden ? 0 : (isLayoutComponent ? 24 : 24 / cols)}
750
+ span={hidden ? 0 : (isLayoutComponent ? 24 : 24 / cols)}
744
751
  style={{ marginBottom: 0 }}
745
752
  >
746
753
  {childComponent}