lu-lowcode-package-form 0.9.71 → 0.9.73
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 +3 -3
- package/dist/index.es.js +463 -458
- package/package.json +1 -1
- package/src/App.jsx +36 -35
- package/src/components/field/base.jsx +4 -1
- package/src/components/form-container/index.jsx +17 -5
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -139,6 +139,39 @@ function App() {
|
|
139
139
|
<Field.UserSelect label="选择用户" __id="userselect" defaultValue={[{ id: 1, username: "十天" }]} />
|
140
140
|
<Layout.FormGroupTitle title={"基本信息"} />
|
141
141
|
<Field.Number label="税率(%)" __id="shuilv" />
|
142
|
+
|
143
|
+
<Field.WithSingleSelect isRequired={true} ref={testRef} fillRules={[
|
144
|
+
{
|
145
|
+
"id": "636d3924-0298-4e9b-809a-26d4a10d7b89",
|
146
|
+
"type": 0,
|
147
|
+
"source": "name",
|
148
|
+
"target": "name",
|
149
|
+
"subRules": [
|
150
|
+
|
151
|
+
]
|
152
|
+
},
|
153
|
+
{
|
154
|
+
"id": "93401e38-60a4-4acf-84a6-8958785a4a30",
|
155
|
+
"type": 1,
|
156
|
+
"source": "table",
|
157
|
+
"target": "table",
|
158
|
+
"subRules": [
|
159
|
+
{
|
160
|
+
"id": "c4a65ae5-58ff-4d7f-8738-a04de1acab61",
|
161
|
+
"type": 0,
|
162
|
+
"source": "price",
|
163
|
+
"target": "product_price1"
|
164
|
+
},
|
165
|
+
|
166
|
+
{
|
167
|
+
"id": "c4a65ae5-58ff-4d7f-8738-a04de1acab61",
|
168
|
+
"type": 0,
|
169
|
+
"source": "num",
|
170
|
+
"target": "product_num1"
|
171
|
+
},
|
172
|
+
]
|
173
|
+
}
|
174
|
+
]} label="测试关联单选" options={[{ label: '选项1', value: '1', name: "1111", table: "[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" }, { label: '选项2', value: '2' }]} __id="remark11" />
|
142
175
|
<Layout.FormRow layout={'1'}>
|
143
176
|
<Field.Table label="子表格" __id="table" >
|
144
177
|
<Field.DatePicker defaultNow={true} label="日期时间" prompt="" datetype="date" __id="datetime2" />
|
@@ -171,7 +204,7 @@ function App() {
|
|
171
204
|
]
|
172
205
|
},
|
173
206
|
|
174
|
-
]} label="测试关联单选" options={[{ label: '选项1', value: '1', product_price11: "1111", product_price12: "2222", product_price1: 111 }, { label: '选项2', value: '2' }]} __id="remark11" />
|
207
|
+
]} label="测试关联单选" options={[{ label: '选项1', value: '1', product_price11: "1111", product_price12: "2222", product_price1: 111 }, { label: '选项2', value: '2' }, { label: '选项2', value: '2' }]} __id="remark11" />
|
175
208
|
|
176
209
|
<Field.Switch label="开关" __id="switch_table"></Field.Switch>
|
177
210
|
<Field.Input defaultValue={3} isRequired={true} label="含税单价" __id="product_price11" />
|
@@ -220,8 +253,8 @@ function App() {
|
|
220
253
|
]
|
221
254
|
}}
|
222
255
|
/>
|
223
|
-
<Field.Input isRequired={true} label="商品价格" __id="product_price13" />
|
224
|
-
<Field.Input isRequired={true} label="商品价格" __id="product_price14" />
|
256
|
+
<Field.Input isRequired={true} defaultValue={1} label="商品价格" __id="product_price13" />
|
257
|
+
<Field.Input isRequired={true} defaultValue={2} label="商品价格" __id="product_price14" />
|
225
258
|
<Field.Input isRequired={true} label="商品价格" __id="product_price1" />
|
226
259
|
<Field.Input isRequired={true} label="商品个数" __id="product_num1" />
|
227
260
|
<Field.Input label="商品总价" __id="product_sum1"
|
@@ -381,38 +414,6 @@ function App() {
|
|
381
414
|
</Layout.FormRow>
|
382
415
|
<Field.CheckboxTree label="角色权限" __id="permissions" addRoot={false} treeData={treeData} />
|
383
416
|
<Layout.FormGroupTitle title={"关联信息"} />
|
384
|
-
<Field.WithSingleSelect ref={testRef} disabled={true} fillRules={[
|
385
|
-
{
|
386
|
-
"id": "636d3924-0298-4e9b-809a-26d4a10d7b89",
|
387
|
-
"type": 0,
|
388
|
-
"source": "name",
|
389
|
-
"target": "name",
|
390
|
-
"subRules": [
|
391
|
-
|
392
|
-
]
|
393
|
-
},
|
394
|
-
{
|
395
|
-
"id": "93401e38-60a4-4acf-84a6-8958785a4a30",
|
396
|
-
"type": 1,
|
397
|
-
"source": "table",
|
398
|
-
"target": "table",
|
399
|
-
"subRules": [
|
400
|
-
{
|
401
|
-
"id": "c4a65ae5-58ff-4d7f-8738-a04de1acab61",
|
402
|
-
"type": 0,
|
403
|
-
"source": "price",
|
404
|
-
"target": "product_price1"
|
405
|
-
},
|
406
|
-
|
407
|
-
{
|
408
|
-
"id": "c4a65ae5-58ff-4d7f-8738-a04de1acab61",
|
409
|
-
"type": 0,
|
410
|
-
"source": "num",
|
411
|
-
"target": "product_num1"
|
412
|
-
},
|
413
|
-
]
|
414
|
-
}
|
415
|
-
]} label="测试关联单选" options={[{ label: '选项1', value: '1', name: "1111", table: "[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2}]" }, { label: '选项2', value: '2' }]} __id="remark11" />
|
416
417
|
<Field.WithMultipleSelect disabled={true} label="测试关联多选" options={[{ label: '选项1', value: '1' }, { label: '选项2', value: '2' }]} __id="remark12" />
|
417
418
|
<Layout.FormRow > <Field.TextArea label="备注" __id="remark" /></Layout.FormRow>
|
418
419
|
|
@@ -31,7 +31,10 @@ export const BaseWrapper = ({
|
|
31
31
|
...otherProps
|
32
32
|
}) => {
|
33
33
|
useEffect(()=>{
|
34
|
-
if (defaultValue && typeof onChange === "function")
|
34
|
+
if (defaultValue && typeof onChange === "function") {
|
35
|
+
console.log("defaultValue changed", defaultValue)
|
36
|
+
onChange(defaultValue)
|
37
|
+
}
|
35
38
|
},[defaultValue])
|
36
39
|
if (!addWrapper) return children;
|
37
40
|
// 不接管只读属性的组件
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React, { forwardRef, useEffect } from "react";
|
2
2
|
import { Form, Row, Col, message } from "antd";
|
3
3
|
|
4
|
-
import { debounce } from 'lodash';
|
4
|
+
import { debounce, isEqual } from 'lodash';
|
5
5
|
import { evalFormula } from '../../utils/formula'
|
6
6
|
|
7
7
|
|
@@ -45,6 +45,7 @@ function batchElements(elements, groupSize) {
|
|
45
45
|
const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) => {
|
46
46
|
const [form] = Form.useForm();
|
47
47
|
const [formContent, setFormContent] = React.useState(null);
|
48
|
+
|
48
49
|
const dependencyMap = React.useRef(null);
|
49
50
|
|
50
51
|
React.useImperativeHandle(ref, () => ({
|
@@ -57,6 +58,18 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
57
58
|
setFormContent(renderChildren());
|
58
59
|
}, [children, cols]);
|
59
60
|
|
61
|
+
|
62
|
+
const lastFormValues = React.useRef(null);
|
63
|
+
const getLastFieldValue = (path) => {
|
64
|
+
let current = lastFormValues.current;
|
65
|
+
for (let i = 0; i < path.length; i++) {
|
66
|
+
if (current == null) {
|
67
|
+
return undefined;
|
68
|
+
}
|
69
|
+
current = current[path[i]];
|
70
|
+
}
|
71
|
+
return current;
|
72
|
+
}
|
60
73
|
const initializeDependencyMap = () => {
|
61
74
|
const fields = [];
|
62
75
|
function traverse(currentNode, parentNode = null) {
|
@@ -165,7 +178,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
165
178
|
if (rule?.subRules && Array.isArray(rule?.subRules) && rule?.subRules.length > 0)
|
166
179
|
for (let index = 0; index < rule?.subRules.length; index++) {
|
167
180
|
const { source: subSource, target: subTarget } = rule?.subRules[index];
|
168
|
-
|
181
|
+
target_item_value[subTarget] = item?.[subSource]
|
169
182
|
}
|
170
183
|
return target_item_value
|
171
184
|
})
|
@@ -274,7 +287,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
274
287
|
const { insert, attributes } = item
|
275
288
|
if (typeof insert !== "string") {
|
276
289
|
if (insert?.span && attributes && attributes.tagKey && attributes.id) {
|
277
|
-
|
278
290
|
result = getParamValue(attributes.tagKey, attributes.id, fieldValues, withDatas)
|
279
291
|
if (Array.isArray(result)) {
|
280
292
|
if (Array.isArray(childIdentifier) && result.length > withFillIndex) {
|
@@ -328,9 +340,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
328
340
|
const handleFieldsChange = debounce((changedFields, allFields) => {
|
329
341
|
const fieldValues = form.getFieldsValue();
|
330
342
|
let needRefresh = false;
|
331
|
-
// console.log("changedFields", changedFields)
|
332
343
|
changedFields.forEach(field => {
|
333
|
-
if (field.name && field.name.length > 0) {
|
344
|
+
if (field.name && field.name.length > 0 && !isEqual(field.value, getLastFieldValue(field.name))) {
|
334
345
|
needRefresh = handleFieldsWith(field.name, fieldValues);
|
335
346
|
}
|
336
347
|
});
|
@@ -338,6 +349,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
338
349
|
if (needRefresh) {
|
339
350
|
setFormContent(renderChildren());
|
340
351
|
}
|
352
|
+
lastFormValues.current = form.getFieldsValue();
|
341
353
|
}, 200);
|
342
354
|
|
343
355
|
const renderChildren = () => {
|