lu-lowcode-package-form 0.9.77 → 0.9.79
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 +133 -133
- package/dist/index.es.js +3844 -3824
- package/package.json +1 -1
- package/src/App.jsx +2 -2
- package/src/components/field/select/search-select.jsx +46 -22
- package/src/components/field/table/index.jsx +5 -2
- package/src/components/form-container/index.jsx +12 -4
- package/src/components/form-container/layout/form-row.jsx +2 -2
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -100,7 +100,7 @@ function App() {
|
|
100
100
|
}
|
101
101
|
const setFormFields = () => {
|
102
102
|
formRef?.current?.formRef?.setFieldsValue({ datetime: "2024-08-25",datetime2: "2024-08-25",datetime3: "",
|
103
|
-
"remark11": { "label": "选项2",
|
103
|
+
"remark11": { "label": "选项2", value: '1'},
|
104
104
|
"remark12": [{ "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" }],
|
105
105
|
"userselect": "1213131", "DeptSelect": ["leaf11"],
|
106
106
|
"searchuser": [{ "id": 2, "name": "2222", "label": "2222", "value": 2 }, { "id": 4, "name": "4444", "label": "4444", "value": 4 }],
|
@@ -278,7 +278,7 @@ function App() {
|
|
278
278
|
<Field.Input isRequired={true} defaultValue={2} label="商品价格" __id="product_price14" />
|
279
279
|
<Field.Input isRequired={true} label="商品价格" __id="product_price1"/>
|
280
280
|
<Field.Input isRequired={true} label="商品个数" __id="product_num1" />
|
281
|
-
<Field.Input label="商品总价" __id="product_sum1"
|
281
|
+
<Field.Input disabled={true} label="商品总价" __id="product_sum1"
|
282
282
|
withIds={["table.product_price1", "table.product_num1"]}
|
283
283
|
withFill={{
|
284
284
|
"value": [
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import { Input, Select as OriginalSelect, Spin } from 'antd';
|
4
4
|
import React, { useEffect, useState } from 'react';
|
5
5
|
import { BaseWrapper } from "../base"
|
6
|
-
import { debounce } from 'lodash';
|
6
|
+
import { debounce, isEqual } from 'lodash';
|
7
7
|
|
8
8
|
|
9
9
|
const SearchSelect = ({ addWrapper = true, 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", rightIcon, rightIconClick, ...props }) => {
|
@@ -18,8 +18,11 @@ const SearchSelect = ({ addWrapper = true, value, type, defaultValue, onChange,
|
|
18
18
|
|
19
19
|
if (request && typeof request === 'function') {
|
20
20
|
const list = await fetchOptions(params)
|
21
|
-
if (list && Array.isArray(list))
|
21
|
+
if (list && Array.isArray(list)) {
|
22
22
|
item = value ? list.find(item => item.value == value) : null
|
23
|
+
console.log("SearchSelect value", value)
|
24
|
+
console.log("SearchSelect item", item)
|
25
|
+
}
|
23
26
|
}
|
24
27
|
|
25
28
|
if (options && options.length > 0) {
|
@@ -33,6 +36,27 @@ const SearchSelect = ({ addWrapper = true, value, type, defaultValue, onChange,
|
|
33
36
|
|
34
37
|
}
|
35
38
|
|
39
|
+
useEffect(() => {
|
40
|
+
console.log("useEffect SearchSelect value", value)
|
41
|
+
if (value && nOptions.length > 0) {
|
42
|
+
let item = value
|
43
|
+
if (Array.isArray(value)) {
|
44
|
+
item = nOptions.filter(item => {
|
45
|
+
return value.filter(v => item.value == v?.value || item.value == v).length > 0
|
46
|
+
})
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
item = nOptions.find(item => item.value == value?.value || item.value == value)
|
50
|
+
}
|
51
|
+
|
52
|
+
if (item && !isEqual(item, value)) {
|
53
|
+
onChange(item)
|
54
|
+
console.log("SearchSelect onChange value", item)
|
55
|
+
}
|
56
|
+
|
57
|
+
}
|
58
|
+
}, [value, nOptions])
|
59
|
+
|
36
60
|
const handleSearch = debounce(async (value) => {
|
37
61
|
const params = { ...requestParams }
|
38
62
|
params[option_search] = value
|
@@ -88,24 +112,8 @@ const SearchSelect = ({ addWrapper = true, value, type, defaultValue, onChange,
|
|
88
112
|
|
89
113
|
return addWrapper ? (
|
90
114
|
<BaseWrapper {...props}>
|
91
|
-
<OriginalSelect
|
92
|
-
|
93
|
-
notFoundContent={fetching ? <Spin size="small" /> : null}
|
94
|
-
value={value}
|
95
|
-
{...props}
|
96
|
-
filterOption={false}
|
97
|
-
showSearch={request && option_search ? true : false}
|
98
|
-
onSearch={request && option_search ? handleSearch : null}
|
99
|
-
onChange={handleChange}
|
100
|
-
style={{ width: '100%', flex: 1 }}
|
101
|
-
options={nOptions}
|
102
|
-
mode={mode} >
|
103
|
-
|
104
|
-
</OriginalSelect>
|
105
|
-
{!props?.disabled && rightIcon}
|
106
|
-
</BaseWrapper>
|
107
|
-
) : (<>
|
108
115
|
<OriginalSelect
|
116
|
+
|
109
117
|
notFoundContent={fetching ? <Spin size="small" /> : null}
|
110
118
|
value={value}
|
111
119
|
{...props}
|
@@ -113,12 +121,28 @@ const SearchSelect = ({ addWrapper = true, value, type, defaultValue, onChange,
|
|
113
121
|
showSearch={request && option_search ? true : false}
|
114
122
|
onSearch={request && option_search ? handleSearch : null}
|
115
123
|
onChange={handleChange}
|
116
|
-
style={{ width: '100%' }}
|
124
|
+
style={{ width: '100%', flex: 1 }}
|
117
125
|
options={nOptions}
|
118
|
-
mode={mode}
|
126
|
+
mode={mode} >
|
119
127
|
|
120
128
|
</OriginalSelect>
|
121
|
-
{!props?.disabled && rightIcon}
|
129
|
+
{!props?.disabled && rightIcon}
|
130
|
+
</BaseWrapper>
|
131
|
+
) : (<>
|
132
|
+
<OriginalSelect
|
133
|
+
notFoundContent={fetching ? <Spin size="small" /> : null}
|
134
|
+
value={value}
|
135
|
+
{...props}
|
136
|
+
filterOption={false}
|
137
|
+
showSearch={request && option_search ? true : false}
|
138
|
+
onSearch={request && option_search ? handleSearch : null}
|
139
|
+
onChange={handleChange}
|
140
|
+
style={{ width: '100%' }}
|
141
|
+
options={nOptions}
|
142
|
+
mode={mode} >
|
143
|
+
|
144
|
+
</OriginalSelect>
|
145
|
+
{!props?.disabled && rightIcon}</>
|
122
146
|
)
|
123
147
|
|
124
148
|
}
|
@@ -28,7 +28,7 @@ const TableCol = ({ children, width, ...props }) => {
|
|
28
28
|
</div>
|
29
29
|
}
|
30
30
|
|
31
|
-
const Table = ({ children, onTableAddRow, ...props }) => {
|
31
|
+
const Table = ({ children, onTableAddRow,onTableRemoveRow, ...props }) => {
|
32
32
|
const [init, setInit] = useState(false);
|
33
33
|
const name = props.componentId || props.__id
|
34
34
|
const childrenIds = React.Children.map(children, (child) => `${name}.${child.props.componentId || child.props.__id}`)
|
@@ -96,7 +96,10 @@ const Table = ({ children, onTableAddRow, ...props }) => {
|
|
96
96
|
</TableCol>
|
97
97
|
})}
|
98
98
|
{!props?.readonly && <TableAction subTableHead={index == 0} key={`row_${index}_action`} subTable={true} subTableIndex={index} label={"操作"}>
|
99
|
-
<DeleteOutlined className="fcursor-pointer" onClick={() =>
|
99
|
+
<DeleteOutlined className="fcursor-pointer" onClick={() =>{
|
100
|
+
remove(index)
|
101
|
+
typeof onTableRemoveRow === "function" && onTableRemoveRow(childrenIds);
|
102
|
+
}} />
|
100
103
|
</TableAction>}
|
101
104
|
</div>
|
102
105
|
))}
|
@@ -219,7 +219,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
219
219
|
setTimeout(() => {
|
220
220
|
form.setFieldValue(target, setValue)
|
221
221
|
handleFieldsWith(target, form.getFieldsValue())
|
222
|
-
if (ids.length > 0)
|
222
|
+
// if (ids.length > 0) handleTableAddRow(ids)
|
223
223
|
}, 0);
|
224
224
|
|
225
225
|
}
|
@@ -233,9 +233,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
233
233
|
debounceHandleFieldsChange();
|
234
234
|
}
|
235
235
|
|
236
|
-
|
236
|
+
console.log("ids", ids)
|
237
237
|
if (ids.length > 0) handleTableAddRow(ids)
|
238
|
-
},
|
238
|
+
}, 300)
|
239
239
|
|
240
240
|
}
|
241
241
|
// 处理级联显示隐藏 @return {boolean} 是否需要重新渲染表单的字段
|
@@ -421,6 +421,14 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
421
421
|
})
|
422
422
|
}, 0);
|
423
423
|
}
|
424
|
+
const handleTableRemoveRow = (ids) => {
|
425
|
+
const fieldValues = form.getFieldsValue();
|
426
|
+
setTimeout(() => {
|
427
|
+
ids.forEach(id => {
|
428
|
+
handleFieldsWith(id, fieldValues);
|
429
|
+
})
|
430
|
+
}, 0);
|
431
|
+
}
|
424
432
|
const renderChildren = () => {
|
425
433
|
const childrenArray = React.Children.toArray(children);
|
426
434
|
const groupedChildren = batchElements(
|
@@ -452,7 +460,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
452
460
|
}
|
453
461
|
let childComponent = child;
|
454
462
|
if (isTable || isLayoutComponent) {
|
455
|
-
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow })
|
463
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow ,onTableRemoveRow: handleTableRemoveRow })
|
456
464
|
}
|
457
465
|
return (
|
458
466
|
<Col key={identifier || `col-${index}`} span={isLayoutComponent ? 24 : 24 / group.length} style={{ marginBottom: 0 }}>
|
@@ -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}) => {
|
4
|
+
const LayoutFormRow = ({ children, layout, onTableAddRow,onTableRemoveRow}) => {
|
5
5
|
layout = layout || '1';
|
6
6
|
const getColSpan = (layoutStr) => {
|
7
7
|
const layoutArray = layoutStr.split(',').map(Number);
|
@@ -20,7 +20,7 @@ const LayoutFormRow = ({ children, layout, onTableAddRow}) => {
|
|
20
20
|
// console.log("initializeDependencyMap componentName", componentName)
|
21
21
|
let childComponent = child;
|
22
22
|
if (componentName == 'Field.Table')
|
23
|
-
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow })
|
23
|
+
childComponent = React.cloneElement(child, { onTableAddRow: onTableAddRow, onTableRemoveRow: onTableRemoveRow })
|
24
24
|
|
25
25
|
if (name) {
|
26
26
|
return (
|