lu-lowcode-package-form 0.9.96 → 0.9.98
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 +159 -159
- package/dist/index.es.js +16320 -16206
- package/package.json +2 -1
- package/src/App.jsx +68 -12
- package/src/components/field/select/search-select.jsx +13 -10
- package/src/components/field/table/index.jsx +20 -2
- package/src/components/form-container/index.jsx +26 -14
- package/src/utils/events.jsx +5 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "lu-lowcode-package-form",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.98",
|
4
4
|
"dependencies": {
|
5
5
|
"@ant-design/icons": "^4.8.1",
|
6
6
|
"@dnd-kit/core": "^6.1.0",
|
@@ -15,6 +15,7 @@
|
|
15
15
|
"@wangeditor/editor-for-react": "^1.0.6",
|
16
16
|
"antd": "^5.13.2",
|
17
17
|
"dayjs": "^1.11.11",
|
18
|
+
"eventemitter3": "^5.0.1",
|
18
19
|
"nanoid": "^5.0.7",
|
19
20
|
"postcss-modules": "^6.0.0",
|
20
21
|
"quill": "^2.0.2",
|
package/src/App.jsx
CHANGED
@@ -102,7 +102,8 @@ function App() {
|
|
102
102
|
}
|
103
103
|
}
|
104
104
|
const setFormFields = () => {
|
105
|
-
formRef?.current?.
|
105
|
+
formRef?.current?.setFieldsValue({ "userselect": "1213131","tianchong1":{"label":"选项1","value":"1"}, "remark11": { "label": "选项1", "value": "1", "name": "1111", "table": "[{\"price\":1,\"num\":2, \"remark11\":\"{ label: '选项3', value: '3' }\"},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" }, "table": [{ "product_num1": "123", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "remark11": { "label": "选项2", "value": "2" }, "product_price12": "" }, { "product_num1": "213", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "datetime2": "2024-08-22 11:09:07", "product_price13": 1, "product_price14": 2, "product_price12": "", "remark11": { "label": "选项3", "value": "3" } }], "product_total_price": "0.00", "DeptSelect": ["leaf11"], "PostSelect": ["parent 1-1", "leaf11"], "searchuser": [{ "id": 2, "name": "2222", "label": "2222", "value": 2 }, { "id": 4, "name": "4444", "label": "4444", "value": 4 }], "product_price": "213", "product_num": "21", "product_num_range": [1, 22], "product_sum": "4473", "switch": false, "datetime": "2024-08-25", "datetime2": "2024-08-25", "datetime3": "", "datetime4": "2024-08-22 11:09:04", "remark12": [{ "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" }] })
|
106
|
+
// formRef?.current?.setFieldsValue({"tianchong1":{"label":"选项1","value":"1"}, })
|
106
107
|
}
|
107
108
|
const handleCols = () => {
|
108
109
|
setCols(cols - 1)
|
@@ -127,7 +128,7 @@ function App() {
|
|
127
128
|
<div className=" fflex fflex-col fitems-center fflex-1 foverflow-y-auto">
|
128
129
|
<DraggableBtn />
|
129
130
|
{/* <MyPureComponentWithRef ref={testRef} />; */}
|
130
|
-
<div className=' fp-4 fflex fjustify-center fw-[1336px]'>
|
131
|
+
{/* <div className=' fp-4 fflex fjustify-center fw-[1336px]'>
|
131
132
|
<div className='fflex fflex-col'>
|
132
133
|
<SortList
|
133
134
|
items={sortItems}
|
@@ -147,13 +148,13 @@ function App() {
|
|
147
148
|
</div>
|
148
149
|
)}
|
149
150
|
/></div>
|
150
|
-
</div>
|
151
|
+
</div> */}
|
151
152
|
{/* <div className=' fp-4 fflex fjustify-center fw-[1336px]'>
|
152
153
|
<WangEditorNext />
|
153
154
|
</div> */}
|
154
|
-
<div className='fw-full fp-4 fflex fjustify-center'>
|
155
|
+
{/* <div className='fw-full fp-4 fflex fjustify-center'>
|
155
156
|
<TinyMCEEditor />
|
156
|
-
</div>
|
157
|
+
</div> */}
|
157
158
|
{/* <div className='fw-full fp-4 fflex fjustify-center'>
|
158
159
|
<EditorWang />
|
159
160
|
</div> */}
|
@@ -173,12 +174,67 @@ function App() {
|
|
173
174
|
|
174
175
|
|
175
176
|
<FormContainerWrapper cols={cols} className="" ref={formRef} >
|
177
|
+
<Field.WithSingleSelect
|
178
|
+
isRequired={true} ref={testRef}
|
179
|
+
request={async (params) => {
|
180
|
+
return { code: 0, data: { list: [{ label: '选项1', value: '1', tianchong2: { label: '选项2', value: '2'} ,tcinput1: "1111" , }, { label: '选项2', value: '2' }, { label: '选项3', value: '3' }] } }
|
181
|
+
}}
|
182
|
+
option_label="label"
|
183
|
+
option_value="value"
|
184
|
+
fillRules={[
|
185
|
+
{
|
186
|
+
"id": "636d3924-0298-4e9b-809a-26d4a10d7b19",
|
187
|
+
"type": 0,
|
188
|
+
"source": "tianchong2",
|
189
|
+
"target": "tianchong2",
|
190
|
+
"subRules": [
|
191
|
+
]
|
192
|
+
},
|
193
|
+
{
|
194
|
+
"id": "636d3924-0298-4e9b-809a-26d4a10d7b11",
|
195
|
+
"type": 0,
|
196
|
+
"source": "tcinput1",
|
197
|
+
"target": "tcinput1",
|
198
|
+
"subRules": [
|
199
|
+
]
|
200
|
+
},
|
201
|
+
|
202
|
+
]} label="测试填充1" __id="tianchong1" />
|
203
|
+
<Field.WithSingleSelect
|
204
|
+
isRequired={true} ref={testRef}
|
205
|
+
request={async (params) => {
|
206
|
+
return { code: 0, data: { list: [{ label: '选项1', value: '1', }, { label: '选项2', value: '2' ,tcinput1: "8989",tcinput2: "2222" }, { label: '选项3', value: '3' }] } }
|
207
|
+
}}
|
208
|
+
option_label="label"
|
209
|
+
option_value="value"
|
210
|
+
fillRules={[
|
211
|
+
{
|
212
|
+
"id": "636d3924-0298-4e9b-809a-16d4a10d7b29",
|
213
|
+
"type": 0,
|
214
|
+
"source": "tcinput1",
|
215
|
+
"target": "tcinput1",
|
216
|
+
"subRules": [
|
217
|
+
]
|
218
|
+
},
|
219
|
+
{
|
220
|
+
"id": "636d3924-0298-4e9b-809a-26d4a10d7b29",
|
221
|
+
"type": 0,
|
222
|
+
"source": "tcinput2",
|
223
|
+
"target": "tcinput2",
|
224
|
+
"subRules": [
|
225
|
+
]
|
226
|
+
},
|
227
|
+
|
228
|
+
]} label="测试填充2" __id="tianchong2" />
|
229
|
+
<Field.Input label="测试被填充1" __id="tcinput1" />
|
230
|
+
<Field.Input label="测试被填充2" __id="tcinput2" />
|
231
|
+
|
176
232
|
<Field.UserSelect label="选择用户" __id="userselect" defaultValue={[{ id: 1, username: "十天" }]} />
|
177
233
|
<Layout.FormGroupTitle title={"基本信息"} />
|
178
234
|
<Field.WithSingleSelect
|
179
235
|
rightIconRender={({ form, fieldName }) => {
|
180
|
-
console.log("rightIconRender form", form,)
|
181
|
-
console.log("rightIconRender fieldName", fieldName)
|
236
|
+
// console.log("rightIconRender form", form,)
|
237
|
+
// console.log("rightIconRender fieldName", fieldName)
|
182
238
|
return <><PrinterOutlined /></>
|
183
239
|
}}
|
184
240
|
isRequired={true} ref={testRef} fillRules={[
|
@@ -255,11 +311,11 @@ function App() {
|
|
255
311
|
<Field.DatePicker defaultNow={true} label="日期时间" prompt="" datetype="date" __id="datetime2" />
|
256
312
|
|
257
313
|
<Field.WithSingleSelect ref={testRef}
|
258
|
-
request={async (params)=>{
|
314
|
+
request={async (params) => {
|
259
315
|
console.log("WithSingleSelect params", params)
|
260
|
-
if (params?.node_ocm009lpxt2 ==
|
261
|
-
return {code:0,data:{ list:[{ label: '选项1', value: '1', product_price11: "1111", product_price12: "2222", product_price1: 111 }, { label: '选项2', value: '2' }, { label: '选项3', value: '3' }]}}
|
262
|
-
else return {code:0,data:{ list:[{ label: '选项1', value: '1', product_price11: "1111", product_price12: "2222", product_price1: 111 }, { label: '选项2', value: '2' },]}}
|
316
|
+
if (params?.ruleParams?.node_ocm009lpxt2 == 111)
|
317
|
+
return { code: 0, data: { list: [{ label: '选项1', value: '1', product_price11: "1111", product_price12: "2222", product_price1: 111 }, { label: '选项2', value: '2' }, { label: '选项3', value: '3' }] } }
|
318
|
+
else return { code: 0, data: { list: [{ label: '选项1', value: '1', product_price11: "1111", product_price12: "2222", product_price1: 111 }, { label: '选项2', value: '2' },] } }
|
263
319
|
}}
|
264
320
|
option_label="label"
|
265
321
|
option_value="value"
|
@@ -300,7 +356,7 @@ function App() {
|
|
300
356
|
]
|
301
357
|
},
|
302
358
|
|
303
|
-
]} label="测试关联单选"
|
359
|
+
]} label="测试关联单选" __id="remark11" />
|
304
360
|
|
305
361
|
<Field.Switch label="开关" __id="switch_table"></Field.Switch>
|
306
362
|
<Field.Input defaultValue={3} isRequired={true} label="含税单价" __id="product_price11" />
|
@@ -9,6 +9,17 @@ import { debounce, isEqual } from 'lodash';
|
|
9
9
|
const SearchSelect = ({ 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 }) => {
|
10
10
|
const [nOptions, setNOptions] = React.useState([])
|
11
11
|
const [fetching, setFetching] = useState(false);
|
12
|
+
useEffect(() => {
|
13
|
+
// console.log("SearchSelect useEffect props", props)
|
14
|
+
// console.log(`SearchSelect ${fieldName} value`, value)
|
15
|
+
if (value && nOptions.length > 0) {
|
16
|
+
let item = nOptions.find(item => item.value == value?.value || item.value == value)
|
17
|
+
if (item && !isEqual(item, value)){
|
18
|
+
console.log("new value /////",item)
|
19
|
+
typeof onChange === 'function' && onChange(item)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
},[value])
|
12
23
|
useEffect(() => {
|
13
24
|
initData(requestParams)
|
14
25
|
}, [requestParams, fieldsValue])
|
@@ -37,22 +48,14 @@ const SearchSelect = ({ addWrapper = true, form, fieldName, fieldsValue, value,
|
|
37
48
|
}
|
38
49
|
}
|
39
50
|
if (request && typeof request === 'function') {
|
40
|
-
|
41
|
-
if (list && Array.isArray(list)) {
|
42
|
-
item = value ? list.find(item => item.value == value) : null
|
43
|
-
console.log("SearchSelect value", value)
|
44
|
-
console.log("SearchSelect item", item)
|
45
|
-
}
|
51
|
+
await fetchOptions(params, ruleParams)
|
46
52
|
}
|
47
53
|
|
48
54
|
if (options && options.length > 0) {
|
49
|
-
item = value ? options.find(item => item.value == value) : null
|
50
55
|
setNOptions(options)
|
51
56
|
}
|
52
57
|
|
53
|
-
|
54
|
-
onChange(item)
|
55
|
-
}
|
58
|
+
|
56
59
|
|
57
60
|
}
|
58
61
|
|
@@ -1,9 +1,10 @@
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
2
2
|
import { Button, Form, Input } from "antd";
|
3
3
|
import { 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";
|
7
|
+
import {eventEmitter} from '../../../utils/events'
|
7
8
|
|
8
9
|
const TableAction = ({ label, subTableIndex, children, subTableHead = false, ...props }) => {
|
9
10
|
//fsticky fright-0
|
@@ -29,6 +30,9 @@ const TableCol = ({ children, width, ...props }) => {
|
|
29
30
|
}
|
30
31
|
|
31
32
|
const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow, form, fieldName, ...props }) => {
|
33
|
+
useEffect(()=>{
|
34
|
+
console.log("Table form reload",form)
|
35
|
+
},[form])
|
32
36
|
const [init, setInit] = useState(false);
|
33
37
|
const name = props.componentId || props.__id
|
34
38
|
const childrenIds = React.Children.map(children, (child) => `${name}.${child.props.componentId || child.props.__id}`)
|
@@ -37,6 +41,20 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
37
41
|
if (!init) setInit(true);
|
38
42
|
form?.setFieldValue(fieldName, [{}])
|
39
43
|
}
|
44
|
+
const [tableId, setTableId] = useState()
|
45
|
+
const handleReloadTable = (target) => {
|
46
|
+
if(fieldName == target) {
|
47
|
+
setTableId(nanoid())
|
48
|
+
}
|
49
|
+
}
|
50
|
+
useEffect(() => {
|
51
|
+
setTableId(nanoid())
|
52
|
+
eventEmitter.on('reloadTable', handleReloadTable);
|
53
|
+
return () => {
|
54
|
+
eventEmitter.off('reloadTable', handleReloadTable);
|
55
|
+
}
|
56
|
+
|
57
|
+
},[])
|
40
58
|
|
41
59
|
if (props.isRequired)
|
42
60
|
rules.push({ required: true, message: `子表[${props.label}]必须填写` });
|
@@ -60,7 +78,7 @@ const Table = ({ children, onTableAddRow, disabled, readonly, onTableRemoveRow,
|
|
60
78
|
</TableAction>}
|
61
79
|
</div>}
|
62
80
|
{fields.map((field, index) => (
|
63
|
-
<div key={field.key} className="fborder-b fflex flex-nowrap fmin-w-full ">
|
81
|
+
<div key={`${tableId}.${field.key}`} className="fborder-b fflex flex-nowrap fmin-w-full ">
|
64
82
|
|
65
83
|
{React.Children.map(children, (child, childIndex) => {
|
66
84
|
let { props } = child;
|
@@ -4,7 +4,8 @@ import { Form, Row, Col, message } from "antd";
|
|
4
4
|
import { debounce, isEqual } from 'lodash';
|
5
5
|
import { evalFormula } from '../../utils/formula'
|
6
6
|
import { nanoid } from 'nanoid';
|
7
|
-
|
7
|
+
import {eventEmitter} from '../../utils/events'
|
8
|
+
|
8
9
|
|
9
10
|
function batchElements(elements, groupSize) {
|
10
11
|
const groupedElements = [];
|
@@ -48,11 +49,12 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
48
49
|
const [formContent, setFormContent] = React.useState(null);
|
49
50
|
|
50
51
|
const dependencyMap = React.useRef(null);
|
51
|
-
|
52
|
+
// 调用setFieldsValue时,进入锁定状态,阻止因字段值变化而触发级联处理
|
53
|
+
const lockStatus = React.useRef(0);
|
52
54
|
React.useImperativeHandle(ref, () => ({
|
53
55
|
formRef: form,
|
54
56
|
setFieldsValue: (values) => {
|
55
|
-
|
57
|
+
lockStatus.current = 1;
|
56
58
|
form.setFieldsValue(values)
|
57
59
|
},
|
58
60
|
initializeFieldVisibility,
|
@@ -202,6 +204,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
202
204
|
return target_item_value
|
203
205
|
})
|
204
206
|
setValue = target_value
|
207
|
+
eventEmitter.emit('reloadTable', target);
|
205
208
|
}
|
206
209
|
// 同级字段
|
207
210
|
else {
|
@@ -215,16 +218,18 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
215
218
|
setValue = current_value[withFillIndex]?.[source]
|
216
219
|
}
|
217
220
|
}
|
221
|
+
changedFields[target] = { name: [target], value: setValue};
|
218
222
|
}
|
219
223
|
if (rule?.type == 1) {
|
220
224
|
form.setFieldValue(target, undefined);
|
221
225
|
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
+
form.setFieldValue(target, setValue)
|
227
|
+
// handleFieldsWith(target, form.getFieldsValue())
|
228
|
+
// setTimeout(() => {
|
229
|
+
// form.setFieldValue(target, setValue)
|
230
|
+
// handleFieldsWith(target, form.getFieldsValue())
|
226
231
|
// if (idGroups.length > 0) handleTableAddRow(idGroups)
|
227
|
-
}, 0);
|
232
|
+
// }, 0);
|
228
233
|
|
229
234
|
|
230
235
|
// if (idGroups.length > 0) setTimeout(() => handleTableAddRow(idGroups), 0)
|
@@ -236,9 +241,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
236
241
|
changedKeys.forEach(key => {
|
237
242
|
changedFieldsState.current[key] = changedFields[key];
|
238
243
|
})
|
244
|
+
// console.log("changedFieldsState",changedFieldsState.current)
|
239
245
|
debounceHandleFieldsChange();
|
240
246
|
}
|
241
|
-
console.log("idGroups", idGroups)
|
247
|
+
// console.log("idGroups", idGroups)
|
242
248
|
if (idGroups.length > 0) idGroups.forEach(ids => { if (Array.isArray(ids) && ids.length > 0) handleTableAddRow(ids) })
|
243
249
|
}, 0)
|
244
250
|
|
@@ -343,7 +349,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
343
349
|
}
|
344
350
|
|
345
351
|
if (formula && formula.length > 0) {
|
346
|
-
console.log(`${childIdentifier} 计算公式:`, formula)
|
352
|
+
// console.log(`${childIdentifier} 计算公式:`, formula)
|
347
353
|
const formulaResult = evalFormula(formula);
|
348
354
|
form.setFieldValue(childIdentifier, formulaResult)
|
349
355
|
handleFieldsWith(childIdentifier, form.getFieldsValue())
|
@@ -379,12 +385,18 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
379
385
|
const changedFieldsState = React.useRef({});
|
380
386
|
const debounceHandleFieldsChange = debounce(() => {
|
381
387
|
const fieldValues = form.getFieldsValue();
|
388
|
+
const lockStatus_ = lockStatus.current;
|
389
|
+
lockStatus.current = 0
|
382
390
|
let needRefresh = false;
|
383
391
|
if (!lastFormValues.current) lastFormValues.current = {}
|
384
392
|
for (let key in changedFieldsState.current) {
|
385
393
|
let field = changedFieldsState.current[key];
|
394
|
+
// console.log("field",field.value)
|
395
|
+
// console.log("getLastFieldValue(field.name)",getLastFieldValue(field.name))
|
386
396
|
if (!isEqual(field.value, getLastFieldValue(field.name))) {
|
387
|
-
|
397
|
+
if (lockStatus_ !=1){
|
398
|
+
needRefresh = handleFieldsWith(field.name, fieldValues);
|
399
|
+
}
|
388
400
|
lastFormValues.current[field.name] = field.value;
|
389
401
|
}
|
390
402
|
}
|
@@ -393,10 +405,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
393
405
|
}
|
394
406
|
// lastFormValues.current = form.getFieldsValue();
|
395
407
|
changedFieldsState.current = {};
|
396
|
-
},
|
408
|
+
}, 100);
|
397
409
|
|
398
410
|
const handleFieldsChange = (changedFields) => {
|
399
|
-
console.log("changedFields", changedFields)
|
411
|
+
// console.log("changedFields", changedFields)
|
400
412
|
changedFields.filter(field => {
|
401
413
|
if (field.name && field.name.length > 0) {
|
402
414
|
// const fieldKey = field.name.filter(item => typeof item == "string").join(".")
|
@@ -527,7 +539,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
527
539
|
|
528
540
|
return (
|
529
541
|
<Form form={form} className={"form-container fp-0 fw-full fh-full box-border fflex fflex-col fgap-y-2" + (mode == "desgin" ? " fp-6" : "")} onValuesChange={(changedValues, allValues) => {
|
530
|
-
console.log("changedValues", changedValues)
|
542
|
+
// console.log("changedValues", changedValues)
|
531
543
|
// console.log("allValues", allValues)
|
532
544
|
}} onFieldsChange={handleFieldsChange}>
|
533
545
|
{formContent}
|