lu-lowcode-package-form 0.10.75 → 0.10.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lu-lowcode-package-form",
3
- "version": "0.10.75",
3
+ "version": "0.10.77",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^4.8.1",
6
6
  "@dnd-kit/core": "^6.1.0",
@@ -14,6 +14,7 @@
14
14
  "@wangeditor-next/editor-for-react": "^1.0.7",
15
15
  "@wangeditor/editor": "^5.1.23",
16
16
  "@wangeditor/editor-for-react": "^1.0.6",
17
+ "ahooks": "^3.8.4",
17
18
  "antd": "^5.13.2",
18
19
  "dayjs": "^1.11.11",
19
20
  "eventemitter3": "^5.0.1",
package/src/App.jsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import { FormContainer, Field, FormContainerWrapper, Layout, Setter, EditorQuill, EditorWang, EditorWang2, EditorWang3, WangEditor, WangEditorNext, Show } from './components';
2
2
  import './App.css';
3
3
  import { Button, Input, Select } from 'antd';
4
- import React, { useEffect, useState } from 'react';
4
+ import React, { useCallback, useEffect, useState } from 'react';
5
5
  import Draggable from 'react-draggable';
6
- import { throttle } from 'lodash';
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,7 +81,16 @@ function App() {
81
81
  const [testCalcHidden, setTestCalcHidden] = useState(false);
82
82
  const [readonly, setReadonly] = useState(true);
83
83
 
84
+ const testdebounce = useCallback( debounce((param1,param2)=>{
85
+ console.log("testdebounce param1",param1)
86
+ console.log("testdebounce param2",param2)
87
+ },200))
88
+
89
+
84
90
  useEffect(() => {
91
+ testdebounce(1,2)
92
+ testdebounce(11,22)
93
+ testdebounce(111,222)
85
94
  // console.log("testRef //////", testRef.current)
86
95
  }, [testRef.current])
87
96
  const [cols, setCols] = React.useState(3);
@@ -105,7 +114,7 @@ function App() {
105
114
  }
106
115
  }
107
116
  const setFormFields = () => {
108
- formRef?.current?.setFieldsValue({ "__id": 1, "userselect": "1213131", "remark11": { "label": "选项1", "value": "1", "name": "1111", "table": "[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" }, "table2": [{}], "table": [{ "product_num1": "123", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "remark11": { "label": "选项2", "value": "2" }, "product_price12": "", "tianchong1": { "label": "选项1", "value": "1", "tianchong2": { "label": "选项2", "value": "2" }, "tcinput1": "1111" }, "tianchong2": { "label": "选项2", "value": "2", "tcinput1": "8989", "tcinput2": "2222" }, "tcinput1": "8989", "tcinput2": "2222", "tcinput3": "1111" }, { "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_price11": 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": JSON.stringify( [{ "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" }] )})
117
+ formRef?.current?.setFieldsValue({ "__id": 1, "userselect": "1213131", "remark11": { "label": "选项1", "value": "1", "name": "1111", "table": "[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" }, "table2": [{}], "table": [{ "product_num1": "123", "product_sum1": "", "node_oclxmzswzti": "", "select2": "", "switch_table": false, "remark11": { "label": "选项2", "value": "2" }, "product_price12": "", "tianchong1": { "label": "选项1", "value": "1", "tianchong2": { "label": "选项2", "value": "2" }, "tcinput1": "1111" }, "tianchong2": { "label": "选项2", "value": "2", "tcinput1": "8989", "tcinput2": "2222" }, "tcinput1": "8989", "tcinput2": "2222", "tcinput3": "2222" }, { "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_price11": 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": JSON.stringify([{ "label": "选项1", "value": "1" }, { "label": "选项2", "value": "2" }]) })
109
118
  // formRef?.current?.setFieldsValue({"tianchong1":{"label":"选项1","value":"1"}, })
110
119
  }
111
120
  const handleCols = () => {
@@ -186,6 +195,133 @@ function App() {
186
195
 
187
196
 
188
197
  <FormContainerWrapper cols={cols} className="" ref={formRef} >
198
+
199
+ <Field.WithSingleSelect
200
+ ref={testRef}
201
+ request={async (params) => {
202
+ console.log("request params", params)
203
+ return {
204
+ code: 0, data: {
205
+ list:
206
+ [
207
+ { label: '选项1', value: '1', table_fill: [{ fill_tianchong1:{ label: '选项1', value: '1'}, fill_tianchong2:{ label: '选项2', value: '2'} }] },
208
+ { label: '选项2', value: '2' },
209
+ { label: '选项3', value: '3' }
210
+ ]
211
+ }
212
+ }
213
+ }}
214
+ option_label="label"
215
+ option_value="value"
216
+ fillRules={[
217
+ {
218
+ "id": "636d3924-0298-4e9b-809a-26d4a10d7b19",
219
+ "type": 1,
220
+ "source": "table_fill",
221
+ "target": "table_fill",
222
+ "subRules": [
223
+ {
224
+ "id": "636d3924-0298-4e9b-809a-26d4a10d7b11",
225
+ "type": 0,
226
+ "source": "fill_tianchong1",
227
+ "target": "fill_tianchong1",
228
+ },
229
+ ]
230
+ },
231
+
232
+ ]} label="子表填充数据源" __id="fill_datasource1" />
233
+ <Layout.FormRow layout={'1'}>
234
+ <Field.Table label="测试主子表填充" __id="table_fill" isAllowAdd={true} isAllowCopy={false} >
235
+
236
+ <Field.WithSingleSelect
237
+ ref={testRef}
238
+ request={async (params) => {
239
+ console.log("request params", params)
240
+ return { code: 0, data: { list: [{ label: '选项1', value: '1', fill_tianchong2: { label: '选项2', value: '2' }, fill_tcinput1: "1111", }, { label: '选项2', value: '2' }, { label: '选项3', value: '3' }] } }
241
+ }}
242
+ option_label="label"
243
+ option_value="value"
244
+ fillRules={[
245
+ {
246
+ "id": "636d3924-0298-4e9b-809a-26d4a10d7b19",
247
+ "type": 0,
248
+ "source": "fill_tianchong2",
249
+ "target": "fill_tianchong2",
250
+ "subRules": [
251
+ ]
252
+ },
253
+ {
254
+ "id": "636d3924-0298-4e9b-809a-26d4a10d7b11",
255
+ "type": 0,
256
+ "source": "fill_tcinput1",
257
+ "target": "fill_tcinput1",
258
+ "subRules": [
259
+ ]
260
+ },
261
+
262
+ ]} label="测试填充1" __id="fill_tianchong1" />
263
+ <Field.WithSingleSelect
264
+ ref={testRef}
265
+ request={async (params) => {
266
+ if (!params?.value) return { code: 0, data: { list: [{ label: '选项1', value: '1', }] } }
267
+ await new Promise(resolve => setTimeout(resolve, 200))
268
+ return { code: 0, data: { list: [{ label: '选项1', value: '1', }, { label: '选项2', value: '2', fill_tcinput1: "8989", fill_tcinput2: "2222" }, { label: '选项3', value: '3' }] } }
269
+ }}
270
+ option_label="label"
271
+ option_value="value"
272
+ option_search="label"
273
+ fillRules={[
274
+ {
275
+ "id": "636d3924-0298-4e9b-809a-16d4a10d7b29",
276
+ "type": 0,
277
+ "source": "fill_tcinput1",
278
+ "target": "fill_tcinput1",
279
+ "subRules": [
280
+ ]
281
+ },
282
+ {
283
+ "id": "636d3924-0298-4e9b-809a-26d4a10d7b29",
284
+ "type": 0,
285
+ "source": "fill_tcinput2",
286
+ "target": "fill_tcinput2",
287
+ "subRules": [
288
+ ]
289
+ },
290
+
291
+ ]} label="测试填充2" __id="fill_tianchong2" />
292
+ <Field.Input label="测试被填充1" __id="fill_tcinput1" />
293
+ <Field.Input label="测试被填充2" __id="fill_tcinput2" />
294
+ <Field.Input label="测试被填充计算" __id="fill_tcinput3"
295
+ withIds={["table_fill.fill_tcinput2"]}
296
+ withFill={{
297
+ "value": [
298
+ {
299
+ "insert": {
300
+ "span": true
301
+ },
302
+ "attributes": {
303
+ "id": "table_fill.fill_tcinput2",
304
+ "color": "blue",
305
+ "tagKey": "fieldsValue",
306
+ "content": "当前表单.测试被填充2"
307
+ }
308
+ },
309
+ {
310
+ "insert": "* 0.5"
311
+ },
312
+ {
313
+ "insert": "\n\n"
314
+ }
315
+ ],
316
+ "version": 1719296886283,
317
+ "withData": [
318
+
319
+ ]
320
+ }}
321
+ />
322
+
323
+ </Field.Table>
324
+ </Layout.FormRow>
189
325
  <Field.MultipleSelect mode="multiple" option_label={"label"} option_value={"value"} label="测试过滤条件" __id="selecta1" request={async (params) => {
190
326
  return { code: 0, data: { list: [{ label: '选项1', value: '1' }, { label: '选项2', value: '2' }] } }
191
327
  }}></Field.MultipleSelect>
@@ -4,6 +4,8 @@ import { Input, Select as OriginalSelect, Spin } from 'antd';
4
4
  import React, { useEffect, useState, forwardRef, useCallback, useRef } from 'react';
5
5
  import { BaseWrapper } from "../base"
6
6
  import { debounce, isEqual } from 'lodash';
7
+ import { createPromiseWrapper } from "../../../utils"
8
+ import { useCreation } from 'ahooks';
7
9
 
8
10
 
9
11
  const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsValue, shouldUpdateKey, 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) => {
@@ -14,7 +16,9 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
14
16
  const currentPageSize = 10
15
17
  const isAllLoadedRef = useRef(false)
16
18
  const isLoadingRef = useRef(false);
17
-
19
+ const promiseRef = useCreation(() => {
20
+ return createPromiseWrapper();
21
+ }, []);
18
22
  useEffect(() => {
19
23
  // console.log("SearchSelect useEffect props", props)
20
24
  if (value) {
@@ -29,46 +33,46 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
29
33
  }
30
34
 
31
35
  // 没有找到与value相等的选项,说明该项数据可能尚未加载,此时需要重新加载数据
32
- if (!item) loadSelectOptions()
36
+ if (!item) loadSelectOptions(value)
33
37
  }
34
38
  }, [value])
35
39
 
36
- // useEffect(() => {
37
- // initData(requestParams)
38
- // }, [requestParams, fieldsValue])
40
+
39
41
 
40
42
  useEffect(() => {
41
- // console.log("SearchSelect useEffect shouldUpdateKey", shouldUpdateKey)
42
- // console.log("SearchSelect useEffect requestParams", requestParams)
43
43
  initData(requestParams)
44
44
  }, [shouldUpdateKey, requestParams])
45
- // }, [ requestParams])
46
-
47
- // useEffect(() => {
48
- // console.log("SearchSelect useEffect requestParams", requestParams)
49
- // initData(requestParams)
50
- // }, [requestParams])
51
- // useEffect(()=>{
52
- // console.log("SearchSelect useEffect []")
53
- // },[])
54
- // useEffect(() => {
55
- // console.log("WithSingleSelect useEffect fieldsValue",fieldsValue)
56
- // if(fieldsValue)
57
- // {
58
- // form.setFieldValue(fieldName,value )
59
- // console.log("onChange undefined")
60
- // onChange(undefined)
45
+
46
+
47
+ // const loadSelectOptions = useCallback(debounce( async (loadValue) => {
48
+ // if (request && option_value) {
49
+ // console.log("loadSelectOptions debounceFetchOptions params" + props?.__id,loadValue)
50
+ // await promiseRef.promise
51
+ // debounceFetchOptions({ ...requestParams, [option_value]: loadValue?.value }, null,(selectOptions) => {
52
+ // console.log("loadSelectOptions selectOptions", selectOptions)
53
+ // if (selectOptions && selectOptions.length > 0) {
54
+ // let item = selectOptions.find(item => item.value == loadValue?.value || item.value == loadValue)
55
+ // console.log("loadSelectOptions item", item)
56
+ // if (item && !isEqual(item, loadValue)) {
57
+ // console.log("new value /////", item)
58
+ // typeof onChange === 'function' && onChange(item)
59
+ // }
60
+ // }
61
+ // })
62
+
61
63
  // }
62
- // },[fieldsValue])
64
+ // },100), [])
63
65
 
64
- const loadSelectOptions = async () => {
66
+
67
+
68
+ const loadSelectOptions = async (loadValue) => {
65
69
  if (request && option_value) {
66
- debounceFetchOptions({ ...requestParams, [option_value]: value?.value }, null, (selectOptions) => {
67
- console.log("loadSelectOptions selectOptions", selectOptions)
70
+ // 等initData调用后,再调用loadSelectOptions,防止传入参数和回调被覆盖
71
+ await promiseRef.promise
72
+ debounceFetchOptions({ ...requestParams, [option_value]: loadValue?.value }, null, (selectOptions) => {
68
73
  if (selectOptions && selectOptions.length > 0) {
69
- let item = selectOptions.find(item => item.value == value?.value || item.value == value)
70
- console.log("loadSelectOptions item", item)
71
- if (item && !isEqual(item, value)) {
74
+ let item = selectOptions.find(item => item.value == loadValue?.value || item.value == loadValue)
75
+ if (item && !isEqual(item, loadValue)) {
72
76
  console.log("new value /////", item)
73
77
  typeof onChange === 'function' && onChange(item)
74
78
  }
@@ -77,6 +81,7 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
77
81
 
78
82
  }
79
83
  }
84
+
80
85
  const initData = async (params) => {
81
86
 
82
87
  let item = null
@@ -85,36 +90,13 @@ const SearchSelect = forwardRef(({ addWrapper = true, form, fieldName, fieldsVal
85
90
  isAllLoadedRef.current = false
86
91
  if (request && typeof request === 'function') {
87
92
  debounceFetchOptions(params, ruleParams)
93
+ promiseRef?.resolve(true);
88
94
  }
89
-
90
95
  if (options && options.length > 0) {
91
96
  setNOptions(options)
92
97
  }
93
-
94
-
95
-
96
98
  }
97
99
 
98
- // useEffect(() => {
99
- // console.log("useEffect SearchSelect value", value)
100
- // if (value && nOptions.length > 0) {
101
- // let item = value
102
- // if (Array.isArray(value)) {
103
- // item = nOptions.filter(item => {
104
- // return value.filter(v => item.value == v?.value || item.value == v).length > 0
105
- // })
106
- // }
107
- // else {
108
- // item = nOptions.find(item => item.value == value?.value || item.value == value)
109
- // }
110
-
111
- // if (item && !isEqual(item, value)) {
112
- // onChange(item)
113
- // console.log("SearchSelect onChange value", item)
114
- // }
115
-
116
- // }
117
- // }, [value, nOptions])
118
100
 
119
101
  const handleSearch = async (value) => {
120
102
  const params = { ...requestParams }
@@ -446,7 +446,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
446
446
  const delay = lockStatus.current === 1 ? 500 : 100;
447
447
 
448
448
  timeoutRef.current = setTimeout(() => {
449
- console.log("debounceHandleFieldsChange begin")
450
449
  const fieldValues = form.getFieldsValue();
451
450
  const lockStatus_ = lockStatus.current;
452
451
  lockStatus.current = 0
@@ -471,7 +470,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
471
470
  }, []);
472
471
 
473
472
  const handleFieldsChange = (changedFields) => {
474
- console.log("changedFields", changedFields)
475
473
  changedFields.filter(field => {
476
474
  if (field.name && field.name.length > 0) {
477
475
  // const fieldKey = field.name.filter(item => typeof item == "string").join(".")
@@ -201,3 +201,5 @@ export function debounce(func, wait, key = "default") {
201
201
  }
202
202
  return debouncers[key];
203
203
  }
204
+
205
+