lu-lowcode-package-form 0.10.80 → 0.10.81
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 +252 -252
- package/dist/index.es.js +19989 -19930
- package/package.json +1 -1
- package/src/App.jsx +77 -42
- package/src/components/form-container/index.jsx +107 -8
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -3,7 +3,7 @@ import './App.css';
|
|
3
3
|
import { Button, Input, Select } from 'antd';
|
4
4
|
import React, { useCallback, useEffect, useState } from 'react';
|
5
5
|
import Draggable from 'react-draggable';
|
6
|
-
import { throttle
|
6
|
+
import { throttle, debounce } from 'lodash';
|
7
7
|
import { SortList } from "./components"
|
8
8
|
import { TinyMCEEditor } from './components'
|
9
9
|
import { PrinterOutlined } from '@ant-design/icons';
|
@@ -81,16 +81,16 @@ function App() {
|
|
81
81
|
const [testCalcHidden, setTestCalcHidden] = useState(false);
|
82
82
|
const [readonly, setReadonly] = useState(true);
|
83
83
|
|
84
|
-
const testdebounce = useCallback(
|
85
|
-
console.log("testdebounce param1",param1)
|
86
|
-
console.log("testdebounce param2",param2)
|
87
|
-
},200))
|
84
|
+
const testdebounce = useCallback(debounce((param1, param2) => {
|
85
|
+
console.log("testdebounce param1", param1)
|
86
|
+
console.log("testdebounce param2", param2)
|
87
|
+
}, 200))
|
88
88
|
|
89
89
|
|
90
90
|
useEffect(() => {
|
91
|
-
testdebounce(1,2)
|
92
|
-
testdebounce(11,22)
|
93
|
-
testdebounce(111,222)
|
91
|
+
testdebounce(1, 2)
|
92
|
+
testdebounce(11, 22)
|
93
|
+
testdebounce(111, 222)
|
94
94
|
// console.log("testRef //////", testRef.current)
|
95
95
|
}, [testRef.current])
|
96
96
|
const [cols, setCols] = React.useState(3);
|
@@ -196,40 +196,75 @@ function App() {
|
|
196
196
|
|
197
197
|
<FormContainerWrapper cols={cols} className="" ref={formRef} >
|
198
198
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
199
|
+
<Field.RadioGroup
|
200
|
+
buttonStyle="solid"
|
201
|
+
optionType="button"
|
202
|
+
label="菜单类型"
|
203
|
+
__id="routeType"
|
204
|
+
options={[{ label: "菜单分组", value: 999 }, { label: "URL", value: 1 }, { label: "绑定表单", value: 2 }]} />
|
205
|
+
|
206
|
+
<Field.Select label="绑定表单"
|
207
|
+
option_label={"formTitle"}
|
208
|
+
__id="menuFormTemplateId"
|
209
|
+
withIds={["routeType"]}
|
210
|
+
withFunc={(fieldsValue) => {
|
211
|
+
const result = fieldsValue?.routeType == 2 ? true : false
|
212
|
+
// console.log("withFunc menuFormTemplateId", fieldsValue)
|
213
|
+
// console.log("withFunc menuFormTemplateId result", result)
|
214
|
+
return result
|
215
|
+
}} />
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
<Field.Input label="菜单URL" __id="route"
|
220
|
+
withIds={["routeType"]}
|
221
|
+
withFunc={(fieldsValue) => {
|
222
|
+
const result = fieldsValue?.routeType == 1 ? true : false
|
223
|
+
// console.log("withFunc route", fieldsValue)
|
224
|
+
// console.log("withFunc route result", result)
|
225
|
+
return result
|
226
|
+
}} />
|
227
|
+
<Field.TextArea label="备注" __id="remark"
|
228
|
+
withIds={["routeType"]}
|
229
|
+
withFunc={(fieldsValue) => {
|
230
|
+
return fieldsValue?.routeType != 999 ? true : false
|
231
|
+
}}
|
232
|
+
/>
|
233
|
+
|
234
|
+
<Field.WithSingleSelect
|
235
|
+
ref={testRef}
|
236
|
+
request={async (params) => {
|
237
|
+
console.log("request params", params)
|
238
|
+
return {
|
239
|
+
code: 0, data: {
|
240
|
+
list:
|
241
|
+
[
|
242
|
+
{ label: '选项1', value: '1', table_fill: [{ fill_tianchong1: { label: '选项1', value: '1' }, fill_tianchong2: { label: '选项2', value: '2' } }] },
|
243
|
+
{ label: '选项2', value: '2' },
|
244
|
+
{ label: '选项3', value: '3' }
|
245
|
+
]
|
212
246
|
}
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
247
|
+
}
|
248
|
+
}}
|
249
|
+
option_label="label"
|
250
|
+
option_value="value"
|
251
|
+
fillRules={[
|
252
|
+
{
|
253
|
+
"id": "636d3924-0298-4e9b-809a-26d4a10d7b19",
|
254
|
+
"type": 1,
|
255
|
+
"source": "table_fill",
|
256
|
+
"target": "table_fill",
|
257
|
+
"subRules": [
|
258
|
+
{
|
259
|
+
"id": "636d3924-0298-4e9b-809a-26d4a10d7b11",
|
260
|
+
"type": 0,
|
261
|
+
"source": "fill_tianchong1",
|
262
|
+
"target": "fill_tianchong1",
|
263
|
+
},
|
264
|
+
]
|
265
|
+
},
|
231
266
|
|
232
|
-
|
267
|
+
]} label="子表填充数据源" __id="fill_datasource1" />
|
233
268
|
<Layout.FormRow layout={'1'}>
|
234
269
|
<Field.Table label="测试主子表填充" __id="table_fill" isAllowAdd={true} isAllowCopy={false} >
|
235
270
|
|
@@ -370,7 +405,7 @@ function App() {
|
|
370
405
|
|
371
406
|
]} label="发票类型" options={[{ label: '选项1', value: '1', shuilv: 15, }, { label: '选项2', value: '2', shuilv: 50 }, { label: '选项3', value: '3', shuilv: 2 }]} __id="fapiaoleixing" />
|
372
407
|
|
373
|
-
<Field.Number label="税率(%)" __id="shuilv"
|
408
|
+
<Field.Number label="税率(%)" __id="shuilv" />
|
374
409
|
|
375
410
|
<Field.WithSingleSelect ref={testRef} fillRules={[
|
376
411
|
{
|
@@ -468,7 +503,7 @@ function App() {
|
|
468
503
|
<Layout.FormRow layout={'1'}>
|
469
504
|
<Field.Table label="子表格" __id="table" isAllowAdd={true} isAllowCopy={false} >
|
470
505
|
|
471
|
-
<Field.Number label="税率(%)"
|
506
|
+
<Field.Number label="税率(%)" __id="shuilv_table" withIds={[
|
472
507
|
"shuilv"
|
473
508
|
]}
|
474
509
|
withFill={{
|
@@ -158,6 +158,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
158
158
|
|
159
159
|
// 初始化字段的级联关系
|
160
160
|
const initializeFieldVisibility = (reloadFields = false) => {
|
161
|
+
console.log("initializeFieldVisibility")
|
161
162
|
const fieldValues = form.getFieldsValue();
|
162
163
|
for (let key of dependencyMap.current.keys()) {
|
163
164
|
handleFieldsWith(key, fieldValues, true);
|
@@ -183,10 +184,14 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
183
184
|
handleFillRules(identifier, parentIdentifier, fieldValues, dependent?.fillRules)
|
184
185
|
}
|
185
186
|
dependentChildren.forEach(child => {
|
186
|
-
if (child.component.props.
|
187
|
-
|
187
|
+
if (child.component.props.withVisibleFunc && typeof child.component.props.withVisibleFunc === 'function') {
|
188
|
+
let needRefresh_ = handleFieldsVisibleFunc(fieldValues, child, parentIdentifier)
|
189
|
+
needRefresh = needRefresh || needRefresh_
|
188
190
|
}
|
189
191
|
|
192
|
+
if (child.component.props.withVisible)
|
193
|
+
handleFieldsVisible(fieldValues, child, parentIdentifier, dependent?.componentName)
|
194
|
+
|
190
195
|
if (!init && child.component.props.withFill)
|
191
196
|
handleFieldsWithFill(fieldValues, child, parentIdentifier, dependent?.componentName)
|
192
197
|
|
@@ -305,9 +310,9 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
305
310
|
|
306
311
|
}
|
307
312
|
// 处理级联显示隐藏 @return {boolean} 是否需要重新渲染表单的字段
|
308
|
-
const
|
313
|
+
const handleFieldsVisibleFunc = (fieldValues, child, parentIdentifier) => {
|
309
314
|
let needRefresh = false;
|
310
|
-
const childShouldBeVisible = child?.component?.props?.
|
315
|
+
const childShouldBeVisible = child?.component?.props?.withVisibleFunc(fieldValues);
|
311
316
|
const childIdentifier = child?.identifier;
|
312
317
|
if (dependencyMap.current.has(childIdentifier)) {
|
313
318
|
const childData = dependencyMap.current.get(childIdentifier);
|
@@ -319,6 +324,99 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
319
324
|
}
|
320
325
|
return needRefresh
|
321
326
|
}
|
327
|
+
// 处理级联显示隐藏
|
328
|
+
const handleFieldsVisible = async (fieldValues, child, parentIdentifier, componentName) => {
|
329
|
+
let needRefresh = false;
|
330
|
+
const withFill = child?.component?.props.withVisible;
|
331
|
+
const withDataFetch = child?.component?.props.withDataFetch;
|
332
|
+
let withFillIndex = 0
|
333
|
+
let withFillGroup = ""
|
334
|
+
let childIdentifier = child.identifier;
|
335
|
+
|
336
|
+
if (parentIdentifier && Array.isArray(parentIdentifier) && parentIdentifier.length > 1) {
|
337
|
+
withFillGroup = parentIdentifier.filter(item => typeof item == "string").join(".")
|
338
|
+
withFillIndex = parentIdentifier[parentIdentifier.length - 1]
|
339
|
+
if (childIdentifier.startsWith(`${withFillGroup}.`)) {
|
340
|
+
childIdentifier = [...parentIdentifier, childIdentifier.replace(`${withFillGroup}.`, "")]
|
341
|
+
}
|
342
|
+
}
|
343
|
+
// 被依赖字段不是子表字段,依赖字段是子表字段的情况
|
344
|
+
else if (childIdentifier.indexOf(".") >= 0) {
|
345
|
+
childIdentifier = childIdentifier.split(".")
|
346
|
+
let table_values = getParamValue("fieldsValue", childIdentifier[0], fieldValues, [])
|
347
|
+
if (Array.isArray(table_values) && table_values.length > 0)
|
348
|
+
for (let index = 0; index < table_values.length; index++) {
|
349
|
+
await handleFieldsVisible(fieldValues, child, [childIdentifier[0], index], componentName)
|
350
|
+
}
|
351
|
+
return
|
352
|
+
}
|
353
|
+
let withDatas = [];
|
354
|
+
// 先处理依赖数据
|
355
|
+
if (withFill?.withData && withFill?.withData.length > 0 && withDataFetch && typeof withDataFetch === 'function') {
|
356
|
+
for (let index = 0; index < withFill?.withData.length; index++) {
|
357
|
+
const element = withFill?.withData[index];
|
358
|
+
let params = {}
|
359
|
+
params.tableName = element.withTable.table_name
|
360
|
+
params.filter = {}
|
361
|
+
for (let index = 0; index < element.withCondition.length; index++) {
|
362
|
+
const { value: condition_value, column: condition_column } = element.withCondition[index];
|
363
|
+
let filter_value = getParamValue(condition_value.group_key, condition_value.field_key, fieldValues, withDatas)
|
364
|
+
if (Array.isArray(filter_value)) {
|
365
|
+
if (Array.isArray(childIdentifier) && filter_value.length > withFillIndex) {
|
366
|
+
filter_value = filter_value[withFillIndex]
|
367
|
+
}
|
368
|
+
}
|
369
|
+
if (componentName == "Field.WithSingleSelect" && filter_value && filter_value?.value) filter_value = filter_value.value
|
370
|
+
params.filter[condition_column.column_name] = filter_value
|
371
|
+
}
|
372
|
+
|
373
|
+
// 访问接口获取数据
|
374
|
+
const response = await withDataFetch(params)
|
375
|
+
if (response.code === 0 && response.data.list) {
|
376
|
+
withDatas.push({
|
377
|
+
id: element.id,
|
378
|
+
data: response.data.list
|
379
|
+
})
|
380
|
+
}
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
// 构造计算公式
|
385
|
+
let formula;
|
386
|
+
if (withFill.value && withFill.value.length > 0) {
|
387
|
+
formula = withFill.value.map(item => {
|
388
|
+
let result = "";
|
389
|
+
const { insert, attributes } = item
|
390
|
+
if (typeof insert !== "string") {
|
391
|
+
if (insert?.span && attributes && attributes.tagKey && attributes.id) {
|
392
|
+
result = getParamValue(attributes.tagKey, attributes.id, fieldValues, withDatas)
|
393
|
+
if (Array.isArray(result)) {
|
394
|
+
if (Array.isArray(childIdentifier) && result.length > withFillIndex) {
|
395
|
+
result = result[withFillIndex]
|
396
|
+
}
|
397
|
+
else result = JSON.stringify(result)
|
398
|
+
}
|
399
|
+
else if (result.length > 0) result = `"${result}"`
|
400
|
+
}
|
401
|
+
}
|
402
|
+
else result = insert
|
403
|
+
return result
|
404
|
+
})
|
405
|
+
}
|
406
|
+
if (dependencyMap.current.has(childIdentifier)) {
|
407
|
+
const childData = dependencyMap.current.get(childIdentifier);
|
408
|
+
if (formula && formula.length > 0) {
|
409
|
+
console.log(`${childIdentifier} 计算公式:`, formula)
|
410
|
+
const formulaResult = evalFormula(formula);
|
411
|
+
if (childData.show != formulaResult) {
|
412
|
+
childData.show = formulaResult;
|
413
|
+
dependencyMap.current.set(childIdentifier, childData);
|
414
|
+
needRefresh = true;
|
415
|
+
}
|
416
|
+
}
|
417
|
+
}
|
418
|
+
return needRefresh
|
419
|
+
}
|
322
420
|
// 处理级联数据源
|
323
421
|
// 处理级联填充
|
324
422
|
const handleFieldsWithFill = async (fieldValues, child, parentIdentifier, componentName) => {
|
@@ -449,7 +547,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
449
547
|
|
450
548
|
timeoutRef.current = setTimeout(() => {
|
451
549
|
const fieldValues = form.getFieldsValue();
|
452
|
-
const lockStatus_ = lockStatus.current;
|
550
|
+
const lockStatus_ = lockStatus.current;
|
453
551
|
lockStatus.current = 0
|
454
552
|
let needRefresh = false;
|
455
553
|
if (!lastFormValues.current) lastFormValues.current = {}
|
@@ -458,6 +556,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
458
556
|
let field = changedFieldsState.current[key];
|
459
557
|
if (!isEqual(field.value || "", getLastFieldValue(field.name) || "")) {
|
460
558
|
if (lockStatus_ != 1) {
|
559
|
+
console.log("handleFieldsWith field.name", field.name)
|
461
560
|
needRefresh = handleFieldsWith(field.name, fieldValues);
|
462
561
|
}
|
463
562
|
lastFormValues.current[field.name] = field.value;
|
@@ -560,7 +659,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
560
659
|
|
561
660
|
let childComponent
|
562
661
|
if (isTable || isLayoutComponent) {
|
563
|
-
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, getTableWithIds, onTableRemoveRow: handleTableRemoveRow,removeLastFieldsValues, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode, recordFieldsChange })
|
662
|
+
childComponent = React.cloneElement(child, { onTableAddRow: handleTableAddRow, getTableWithIds, onTableRemoveRow: handleTableRemoveRow, removeLastFieldsValues, form: form, fieldName: identifier, onCustomChange, initializeFormRender, mode, recordFieldsChange })
|
564
663
|
}
|
565
664
|
else if (componentName === "Field.WithSingleSelect" || componentName === "Field.WithMultipleSelect" || componentName === "Show.WithTable") {
|
566
665
|
childComponent = <Form.Item
|
@@ -594,7 +693,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
594
693
|
{({ getFieldsValue }) => {
|
595
694
|
const fieldsValue = getFieldsValue();
|
596
695
|
let element = React.cloneElement(child, {
|
597
|
-
onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow,removeLastFieldsValues, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender, recordFieldsChange,
|
696
|
+
onTableAddRow: handleTableAddRow, onTableRemoveRow: handleTableRemoveRow, removeLastFieldsValues, form: form, fieldName: identifier, onCustomChange, fieldsValue, initializeFormRender, recordFieldsChange,
|
598
697
|
shouldUpdateKey: shouldUpdateKey.current[identifier],
|
599
698
|
})
|
600
699
|
return componentName === "show.WithTable" ? <>{element}</> : <Form.Item
|
@@ -615,7 +714,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
615
714
|
name={identifier}
|
616
715
|
rules={rules}
|
617
716
|
>
|
618
|
-
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender, recordFieldsChange,removeLastFieldsValues })}
|
717
|
+
{React.cloneElement(child, { form: form, fieldName: identifier, onCustomChange, initializeFormRender, recordFieldsChange, removeLastFieldsValues })}
|
619
718
|
</Form.Item>
|
620
719
|
}
|
621
720
|
return (
|