lu-lowcode-package-form 0.9.31 → 0.9.32
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 +118 -118
- package/dist/index.es.js +8825 -8853
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/App.jsx +1 -0
- package/src/components/field/base.jsx +18 -11
- package/src/components/field/checkbox/checkbox-tree.jsx +0 -1
- package/src/components/field/table/index copy 2.jsx +268 -0
- package/src/components/field/table/index copy.jsx +268 -0
- package/src/components/field/table/index.jsx +80 -247
- package/src/components/form-container/index copy.jsx +302 -0
- package/src/components/form-container/index.jsx +72 -41
- package/src/components/form-container/layout/form-row.jsx +0 -1
|
@@ -59,16 +59,26 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
59
59
|
|
|
60
60
|
const initializeDependencyMap = () => {
|
|
61
61
|
const fields = [];
|
|
62
|
-
function traverse(currentNode) {
|
|
62
|
+
function traverse(currentNode,parentNode = null) {
|
|
63
63
|
var componentName = currentNode.type?.displayName || currentNode.props?._componentName;
|
|
64
64
|
const { props } = currentNode;
|
|
65
65
|
if (componentName && (componentName.startsWith('Field.') || componentName.startsWith('Layout.'))) {
|
|
66
|
-
|
|
66
|
+
let identifier = props?.componentId || props?.__id;
|
|
67
|
+
let withIds = []
|
|
68
|
+
if(parentNode && parentNode?.props) {
|
|
69
|
+
identifier = `${parentNode?.props?.componentId || parentNode?.props?.__id}.${identifier}`
|
|
70
|
+
}
|
|
71
|
+
if (props?.withId)
|
|
72
|
+
withIds.push(props?.withId)
|
|
73
|
+
if (props?.withIds)
|
|
74
|
+
withIds = [...withIds,...props?.withIds]
|
|
75
|
+
|
|
76
|
+
fields.push({identifier, withIds,component: currentNode});
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
if (props?.children) {
|
|
70
80
|
let children = React.Children.toArray(props?.children)
|
|
71
|
-
children.forEach(child => traverse(child));
|
|
81
|
+
children.forEach(child => traverse(child,(componentName && (componentName.startsWith('Field.')))?currentNode:null));
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
84
|
dependencyMap.current = new Map();
|
|
@@ -77,13 +87,14 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
77
87
|
const element = childrenArray[index];
|
|
78
88
|
traverse(element)
|
|
79
89
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const identifier =
|
|
90
|
+
console.log("fields", fields)
|
|
91
|
+
fields.forEach(field => {
|
|
92
|
+
const { identifier } = field;
|
|
83
93
|
dependencyMap.current.set(identifier, {
|
|
84
|
-
children:
|
|
85
|
-
|
|
86
|
-
})),
|
|
94
|
+
// children: childrenArray.filter(item => item.props.withId === identifier || item.props.withIds?.some(item => {
|
|
95
|
+
// return identifier == item || item.startsWith(identifier + '.')
|
|
96
|
+
// })),
|
|
97
|
+
children: fields.filter(item=>item.withIds.some(item=>item == identifier)),
|
|
87
98
|
show: true,
|
|
88
99
|
});
|
|
89
100
|
});
|
|
@@ -103,15 +114,22 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
103
114
|
// 计算字段级联关系
|
|
104
115
|
const handleFieldsWith = (identifier, fieldValues) => {
|
|
105
116
|
let needRefresh = false;
|
|
117
|
+
let parentIdentifier = [];
|
|
118
|
+
if (Array.isArray(identifier)) {
|
|
119
|
+
parentIdentifier = [...(identifier.slice(0,-1))]
|
|
120
|
+
identifier = identifier.filter(item=>typeof item == "string").join(".")
|
|
121
|
+
}
|
|
106
122
|
if (dependencyMap.current.has(identifier)) {
|
|
107
123
|
const dependentChildren = dependencyMap.current.get(identifier).children;
|
|
124
|
+
console.log("dependentChildren", dependentChildren)
|
|
125
|
+
|
|
108
126
|
dependentChildren.forEach(child => {
|
|
109
|
-
if (child.props.withFunc && typeof child.props.withFunc === 'function') {
|
|
110
|
-
needRefresh = handleFieldsVisible(fieldValues, child)
|
|
127
|
+
if (child.component.props.withFunc && typeof child.component.props.withFunc === 'function') {
|
|
128
|
+
needRefresh = handleFieldsVisible(fieldValues, child,parentIdentifier)
|
|
111
129
|
}
|
|
112
130
|
|
|
113
|
-
if (child.props.withFill)
|
|
114
|
-
handleFieldsWithFill(fieldValues, child)
|
|
131
|
+
if (child.component.props.withFill)
|
|
132
|
+
handleFieldsWithFill(fieldValues, child,parentIdentifier)
|
|
115
133
|
|
|
116
134
|
});
|
|
117
135
|
}
|
|
@@ -119,10 +137,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
119
137
|
};
|
|
120
138
|
|
|
121
139
|
// 处理级联显示隐藏 @return {boolean} 是否需要重新渲染表单的字段
|
|
122
|
-
const handleFieldsVisible = (fieldValues, child) => {
|
|
140
|
+
const handleFieldsVisible = (fieldValues, child,parentIdentifier) => {
|
|
123
141
|
let needRefresh = false;
|
|
124
|
-
const childShouldBeVisible = child
|
|
125
|
-
const childIdentifier = child
|
|
142
|
+
const childShouldBeVisible = child?.component?.props?.withFunc(fieldValues);
|
|
143
|
+
const childIdentifier = child?.identifier;
|
|
126
144
|
if (dependencyMap.current.has(childIdentifier)) {
|
|
127
145
|
const childData = dependencyMap.current.get(childIdentifier);
|
|
128
146
|
if (childData.show !== childShouldBeVisible) {
|
|
@@ -135,13 +153,19 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
135
153
|
}
|
|
136
154
|
// 处理级联数据源
|
|
137
155
|
// 处理级联填充
|
|
138
|
-
const handleFieldsWithFill = async (fieldValues, child) => {
|
|
139
|
-
const withFill = child
|
|
140
|
-
const withDataFetch = child
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
156
|
+
const handleFieldsWithFill = async (fieldValues, child,parentIdentifier) => {
|
|
157
|
+
const withFill = child?.component?.props.withFill;
|
|
158
|
+
const withDataFetch = child?.component?.props.withDataFetch;
|
|
159
|
+
let withFillIndex = 0
|
|
160
|
+
let withFillGroup = ""
|
|
161
|
+
let childIdentifier = child.identifier;
|
|
162
|
+
if (parentIdentifier && Array.isArray(parentIdentifier) && parentIdentifier.length > 1){
|
|
163
|
+
withFillGroup = parentIdentifier.filter(item=>typeof item == "string").join(".")
|
|
164
|
+
withFillIndex = parentIdentifier[parentIdentifier.length-1]
|
|
165
|
+
if(childIdentifier.startsWith(`${withFillGroup}.`)) {
|
|
166
|
+
childIdentifier = [...parentIdentifier, childIdentifier.replace(`${withFillGroup}.`,"")]
|
|
167
|
+
}
|
|
168
|
+
}
|
|
145
169
|
let withDatas = [];
|
|
146
170
|
// 先处理依赖数据
|
|
147
171
|
if (withFill?.withData && withFill?.withData.length > 0 && withDataFetch && typeof withDataFetch === 'function') {
|
|
@@ -174,8 +198,14 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
174
198
|
const { insert, attributes } = item
|
|
175
199
|
if (typeof insert !== "string") {
|
|
176
200
|
if (insert?.span && attributes && attributes.tagKey && attributes.id) {
|
|
201
|
+
|
|
177
202
|
result = getParamValue(attributes.tagKey, attributes.id, fieldValues, withDatas)
|
|
178
|
-
if (Array.isArray(result))
|
|
203
|
+
if (Array.isArray(result)){
|
|
204
|
+
if (Array.isArray(childIdentifier) && result.length > withFillIndex) {
|
|
205
|
+
result = result[withFillIndex]
|
|
206
|
+
}
|
|
207
|
+
else result = JSON.stringify(result)
|
|
208
|
+
}
|
|
179
209
|
else if (result) result = `"${result}"`
|
|
180
210
|
}
|
|
181
211
|
}
|
|
@@ -183,10 +213,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
183
213
|
return result
|
|
184
214
|
})
|
|
185
215
|
}
|
|
186
|
-
console.log("formula", formula)
|
|
187
216
|
if (formula && formula.length > 0) {
|
|
188
|
-
const
|
|
189
|
-
form.setFieldValue(childIdentifier,
|
|
217
|
+
const formulaResult = evalFormula(formula);
|
|
218
|
+
form.setFieldValue(childIdentifier,formulaResult)
|
|
219
|
+
handleFieldsWith(childIdentifier, form.getFieldsValue())
|
|
190
220
|
}
|
|
191
221
|
}
|
|
192
222
|
|
|
@@ -219,9 +249,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
219
249
|
const handleFieldsChange = debounce((changedFields, allFields) => {
|
|
220
250
|
const fieldValues = form.getFieldsValue();
|
|
221
251
|
let needRefresh = false;
|
|
252
|
+
console.log("changedFields",changedFields)
|
|
222
253
|
changedFields.forEach(field => {
|
|
223
254
|
if (field.name && field.name.length > 0) {
|
|
224
|
-
needRefresh = handleFieldsWith(field.name
|
|
255
|
+
needRefresh = handleFieldsWith(field.name, fieldValues);
|
|
225
256
|
}
|
|
226
257
|
});
|
|
227
258
|
|
|
@@ -236,7 +267,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
236
267
|
const groupedChildren = batchElements(
|
|
237
268
|
childrenArray.filter(child => {
|
|
238
269
|
const identifier = child.props.componentId || child.props.__id;
|
|
239
|
-
return dependencyMap.current.has(identifier)
|
|
270
|
+
return !dependencyMap.current.has(identifier) || dependencyMap.current.get(identifier)?.show;
|
|
240
271
|
}),
|
|
241
272
|
cols
|
|
242
273
|
);
|
|
@@ -248,6 +279,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
248
279
|
const componentName = child.type?.displayName || _componentName;
|
|
249
280
|
const identifier = componentId || __id;
|
|
250
281
|
const isLayoutComponent = componentName && componentName.startsWith('Layout.');
|
|
282
|
+
const isTable = componentName && componentName == 'Field.Table';
|
|
251
283
|
const rules = []
|
|
252
284
|
if (props.isRequired)
|
|
253
285
|
rules.push({ required: true, message: `${props.label}必须填写` });
|
|
@@ -261,18 +293,17 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
|
261
293
|
}
|
|
262
294
|
return (
|
|
263
295
|
<Col key={identifier || `col-${index}`} span={isLayoutComponent ? 24 : 24 / group.length} style={{ marginBottom: 0 }}>
|
|
264
|
-
{isLayoutComponent
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
)}
|
|
296
|
+
{(isLayoutComponent || isTable) && child}
|
|
297
|
+
{!isLayoutComponent && <Form.Item
|
|
298
|
+
style={{ marginBottom: 0 }}
|
|
299
|
+
label=""
|
|
300
|
+
name={identifier}
|
|
301
|
+
rules={rules}
|
|
302
|
+
>
|
|
303
|
+
{child}
|
|
304
|
+
</Form.Item>
|
|
305
|
+
}
|
|
306
|
+
|
|
276
307
|
</Col>
|
|
277
308
|
);
|
|
278
309
|
})}
|
|
@@ -11,7 +11,6 @@ const LayoutFormRow = ({ children, layout }) => {
|
|
|
11
11
|
|
|
12
12
|
const colSpans = useMemo(() => getColSpan(layout), [layout]);
|
|
13
13
|
|
|
14
|
-
console.log("colSpans", colSpans)
|
|
15
14
|
|
|
16
15
|
const formItems = useMemo(() => {
|
|
17
16
|
return React.Children.toArray(children).map((child, index) => {
|