lu-lowcode-package-form 0.10.41 → 0.10.43
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs.js +343 -343
- package/dist/index.es.js +36386 -35888
- package/package.json +1 -1
- package/src/App.jsx +5 -1
- package/src/components/field/base.jsx +1 -1
- package/src/components/field/select/search-select.jsx +4 -3
- package/src/components/field/table/index.jsx +22 -7
- package/src/components/form-container/index.jsx +28 -16
- package/src/components/form-container/layout/form-row.jsx +4 -4
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -259,7 +259,11 @@ function App() {
|
|
259
259
|
<Layout.FormRow layout={'1'}>
|
260
260
|
<Field.Number label="测试规则" isRequired={true} __id="ceshi_rule1" />
|
261
261
|
</Layout.FormRow>
|
262
|
-
|
262
|
+
<Layout.FormRow layout={'1'}>
|
263
|
+
<Field.Table label="子表格" __id="table2" >
|
264
|
+
<Field.Number label="测试规则2" __id="ceshi_rule2" />
|
265
|
+
</Field.Table>
|
266
|
+
</Layout.FormRow>
|
263
267
|
<Layout.FormRow layout={'1'}>
|
264
268
|
<Field.Table label="子表格" __id="table" >
|
265
269
|
|
@@ -6,7 +6,7 @@ import { BaseWrapper } from "../base"
|
|
6
6
|
import { debounce, isEqual } from 'lodash';
|
7
7
|
|
8
8
|
|
9
|
-
const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsValue, value, type, defaultValue, onChange, option_label, option_value, option_search, options, request, requestParams, callError, subRequest, sub_option_label = "label", mode = "single", sub_option_value = "id", rightIconRender, rightIcon, rightIconClick, ...props }, ref) => {
|
9
|
+
const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsValue, value, type, defaultValue, onChange, option_label, option_value, option_search, options, request, requestParams, callError, subRequest, sub_option_label = "label", mode = "single", sub_option_value = "id", rightIconRender, rightIcon, rightIconClick,recordFieldsChange, ...props }, ref) => {
|
10
10
|
const [nOptions, setNOptions] = React.useState([])
|
11
11
|
const [fetching, setFetching] = useState(false);
|
12
12
|
useEffect(() => {
|
@@ -26,6 +26,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
26
26
|
if (!item) loadSelectOptions()
|
27
27
|
}
|
28
28
|
}, [value])
|
29
|
+
|
29
30
|
// useEffect(() => {
|
30
31
|
// initData(requestParams)
|
31
32
|
// }, [requestParams, fieldsValue])
|
@@ -186,7 +187,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
186
187
|
|
187
188
|
</OriginalSelect>
|
188
189
|
{!props?.disabled && rightIcon}
|
189
|
-
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName })}
|
190
|
+
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName,recordFieldsChange })}
|
190
191
|
</BaseWrapper>
|
191
192
|
) : (<>
|
192
193
|
<OriginalSelect
|
@@ -204,7 +205,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
|
|
204
205
|
|
205
206
|
</OriginalSelect>
|
206
207
|
{!props?.disabled && rightIcon}
|
207
|
-
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName })}
|
208
|
+
{!props?.disabled && typeof rightIconRender === 'function' && rightIconRender({ value, onChange, form, fieldName ,recordFieldsChange})}
|
208
209
|
</>
|
209
210
|
)
|
210
211
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React, { useEffect, useRef, useState } from "react";
|
2
|
-
import { Button, Form, Input } from "antd";
|
3
|
-
import { DeleteOutlined } from "@ant-design/icons";
|
2
|
+
import { Button, Form, Input,Popconfirm } from "antd";
|
3
|
+
import { CopyOutlined, DeleteOutlined } from "@ant-design/icons";
|
4
4
|
import { BaseWrapper } from "../base.jsx"
|
5
5
|
import { type } from "@testing-library/user-event/dist/type/index.js";
|
6
6
|
import { nanoid } from "nanoid";
|
@@ -11,7 +11,7 @@ const TableAction = ({ label, subTableIndex, children, subTableHead = false, ...
|
|
11
11
|
return <div className="fw-12 ">
|
12
12
|
<div className="frelative fw-full fh-full fflex fflex-col foverflow-hidden">
|
13
13
|
{label && subTableHead && <div className='fh-12 ffont-semibold fbg-[#fafafa] ftext-sm fflex fflex-nowrap ftext-nowrap fjustify-between fitems-center fpx-2 fborder-b'>{label}</div>}
|
14
|
-
<div className="fw-full fflex-1 fflex fitems-center fjustify-center fp-2 fbox-border ">
|
14
|
+
<div className="fw-full fflex-1 fflex fitems-center fjustify-center fp-2 fbox-border fgap-2 ">
|
15
15
|
{children}
|
16
16
|
</div>
|
17
17
|
</div>
|
@@ -30,7 +30,7 @@ const TableCol = ({ children, width, hidden, ...props }) => {
|
|
30
30
|
</div>
|
31
31
|
}
|
32
32
|
|
33
|
-
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, initializeFormRender, mode, ...props }) => {
|
33
|
+
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, initializeFormRender, recordFieldsChange, mode, ...props }) => {
|
34
34
|
useEffect(() => {
|
35
35
|
// console.log("Table form reload", form)
|
36
36
|
}, [form])
|
@@ -160,6 +160,7 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
160
160
|
fieldName: [fieldName, field.name, col_id],
|
161
161
|
fieldsValue: fieldsValue,
|
162
162
|
initializeFormRender,
|
163
|
+
recordFieldsChange
|
163
164
|
})}
|
164
165
|
</Form.Item>
|
165
166
|
}}
|
@@ -168,10 +169,24 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
168
169
|
</TableCol>
|
169
170
|
})}
|
170
171
|
{disabled != true && readonly != true && <TableAction subTableHead={index == 0} key={`row_${index}_action`} subTable={true} subTableIndex={index} label={"操作"}>
|
171
|
-
<
|
172
|
-
|
173
|
-
|
172
|
+
<CopyOutlined className="fcursor-pointer" onClick={() => {
|
173
|
+
let tableValues = form.getFieldValue(fieldName)
|
174
|
+
const copyRow = {...tableValues[index]}
|
175
|
+
tableValues.splice(index + 1, 0, copyRow)
|
176
|
+
form?.setFieldValue(fieldName, tableValues)
|
174
177
|
}} />
|
178
|
+
<Popconfirm
|
179
|
+
title="删除确认"
|
180
|
+
description="确定要删除这一行吗?"
|
181
|
+
onConfirm={() => {
|
182
|
+
remove(index)
|
183
|
+
typeof onTableRemoveRow === "function" && onTableRemoveRow(childrenIds);
|
184
|
+
}}
|
185
|
+
okText="确定"
|
186
|
+
cancelText="取消"
|
187
|
+
>
|
188
|
+
<DeleteOutlined className="fcursor-pointer ftext-red-500" />
|
189
|
+
</Popconfirm>
|
175
190
|
</TableAction>}
|
176
191
|
</div>
|
177
192
|
))}
|
@@ -57,7 +57,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
57
57
|
formRef: form,
|
58
58
|
setFieldsValue: (values) => {
|
59
59
|
lockStatus.current = 1;
|
60
|
-
form.setFieldsValue({...values,__id: values?.id })
|
60
|
+
form.setFieldsValue({ ...values, __id: values?.id })
|
61
61
|
},
|
62
62
|
initializeFieldVisibility,
|
63
63
|
}), []);
|
@@ -180,7 +180,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
180
180
|
return needRefresh;
|
181
181
|
|
182
182
|
};
|
183
|
-
const removeLastFieldsValues = (name
|
183
|
+
const removeLastFieldsValues = (name, isTable = false) => {
|
184
184
|
if (!lastFormValues.current) return
|
185
185
|
if (isTable) {
|
186
186
|
const lastFormValuesKeys = Object.keys(lastFormValues.current)
|
@@ -193,6 +193,23 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
193
193
|
}
|
194
194
|
else delete lastFormValues.current[name]
|
195
195
|
}
|
196
|
+
|
197
|
+
const recordFieldChange = (fieldName, fieldValue) => {
|
198
|
+
if (!changedFieldsState.current) {
|
199
|
+
changedFieldsState.current = {};
|
200
|
+
}
|
201
|
+
changedFieldsState.current[fieldName] = fieldValue;
|
202
|
+
}
|
203
|
+
const recordFieldsChange = (changedFields, handleChange = false) => {
|
204
|
+
var changedKeys = Object.keys(changedFields)
|
205
|
+
if (changedKeys.length > 0) {
|
206
|
+
changedKeys.forEach(key => {
|
207
|
+
recordFieldChange(key, changedFields[key])
|
208
|
+
})
|
209
|
+
if (handleChange) debounceHandleFieldsChange();
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
196
213
|
// 处理填充规则
|
197
214
|
const handleFillRules = (current_identifier, parentIdentifier, fieldValues, fillRules) => {
|
198
215
|
// 获取当前变更的字段数据
|
@@ -266,14 +283,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
266
283
|
}
|
267
284
|
|
268
285
|
setTimeout(() => {
|
269
|
-
|
270
|
-
if (changedKeys.length > 0) {
|
271
|
-
changedKeys.forEach(key => {
|
272
|
-
changedFieldsState.current[key] = changedFields[key];
|
273
|
-
})
|
274
|
-
|
275
|
-
debounceHandleFieldsChange();
|
276
|
-
}
|
286
|
+
recordFieldsChange(changedFields,true)
|
277
287
|
// console.log("idGroups", idGroups)
|
278
288
|
if (idGroups.length > 0) idGroups.forEach(ids => { if (Array.isArray(ids) && ids.length > 0) handleTableAddRow(ids) })
|
279
289
|
}, 0)
|
@@ -407,7 +417,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
407
417
|
}
|
408
418
|
return result
|
409
419
|
}
|
410
|
-
|
420
|
+
|
411
421
|
|
412
422
|
const changedFieldsState = React.useRef({});
|
413
423
|
const debounceHandleFieldsChange = debounce(() => {
|
@@ -416,7 +426,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
416
426
|
lockStatus.current = 0
|
417
427
|
let needRefresh = false;
|
418
428
|
if (!lastFormValues.current) lastFormValues.current = {}
|
419
|
-
|
429
|
+
|
420
430
|
for (let key in changedFieldsState.current) {
|
421
431
|
let field = changedFieldsState.current[key];
|
422
432
|
if (!isEqual(field.value, getLastFieldValue(field.name))) {
|
@@ -506,9 +516,11 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
506
516
|
const onCustomChange = (value) => {
|
507
517
|
form.setFieldValue(identifier, value)
|
508
518
|
}
|
519
|
+
|
509
520
|
let childComponent
|
510
|
-
if (isTable || isLayoutComponent)
|
511
|
-
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode })
|
521
|
+
if (isTable || isLayoutComponent){
|
522
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode , recordFieldsChange })
|
523
|
+
}
|
512
524
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
513
525
|
childComponent = <Form.Item
|
514
526
|
hidden={hidden}
|
@@ -537,7 +549,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
537
549
|
>
|
538
550
|
{({ getFieldsValue }) => {
|
539
551
|
const fieldsValue = getFieldsValue();
|
540
|
-
let element = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender })
|
552
|
+
let element = React.cloneElement(child, { onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender ,recordFieldsChange})
|
541
553
|
return componentName === "show.WithTable" ? <>{element}</> : <Form.Item
|
542
554
|
style={{ marginBottom: 0 }}
|
543
555
|
label=""
|
@@ -556,7 +568,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
556
568
|
name={identifier}
|
557
569
|
rules={rules}
|
558
570
|
>
|
559
|
-
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender })}
|
571
|
+
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender,recordFieldsChange })}
|
560
572
|
</Form.Item>
|
561
573
|
}
|
562
574
|
return (
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React, { useMemo } from 'react';
|
2
2
|
import { Form, Row, Col } from 'antd';
|
3
3
|
|
4
|
-
const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form, initializeFormRender, mode }) => {
|
4
|
+
const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form, initializeFormRender,recordFieldsChange, mode }) => {
|
5
5
|
layout = layout || '1';
|
6
6
|
const getColSpan = (layoutStr) => {
|
7
7
|
const layoutArray = layoutStr.split(',').map(Number);
|
@@ -40,7 +40,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
40
40
|
}
|
41
41
|
let childComponent = null
|
42
42
|
if (componentName == 'Field.Table')
|
43
|
-
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: name, initializeFormRender, mode })
|
43
|
+
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: name, initializeFormRender, mode,recordFieldsChange })
|
44
44
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
45
45
|
childComponent = <Form.Item
|
46
46
|
hidden={hidden}
|
@@ -68,7 +68,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
68
68
|
>
|
69
69
|
{({ getFieldsValue }) => {
|
70
70
|
const fieldsValue = getFieldsValue();
|
71
|
-
let element = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender })
|
71
|
+
let element = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender,recordFieldsChange })
|
72
72
|
return componentName === "Show.WithTable" ? <>{element}</> : <Form.Item
|
73
73
|
style={{ marginBottom: 0 }}
|
74
74
|
label=""
|
@@ -88,7 +88,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow, onTableRemoveRow, form
|
|
88
88
|
name={name}
|
89
89
|
rules={rules}
|
90
90
|
>
|
91
|
-
{React.cloneElement(child, { form: form, fieldName: name, initializeFormRender })}
|
91
|
+
{React.cloneElement(child, { form: form, fieldName: name, initializeFormRender,recordFieldsChange })}
|
92
92
|
</Form.Item>
|
93
93
|
else childComponent = child
|
94
94
|
|