lu-lowcode-package-form 0.9.60 → 0.9.63

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.9.60",
3
+ "version": "0.9.63",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^4.8.1",
6
6
  "@testing-library/jest-dom": "^5.17.0",
package/src/App.jsx CHANGED
@@ -139,6 +139,28 @@ function App() {
139
139
  <Layout.FormGroupTitle title={"基本信息"} />
140
140
  <Layout.FormRow layout={'1'}>
141
141
  <Field.Table label="子表格" __id="table" >
142
+ <Field.WithSingleSelect ref={testRef} fillRules={[
143
+ {
144
+ "id": "636d3924-0298-4e9b-809a-26d4a10d7b89",
145
+ "type": 0,
146
+ "source": "product_price11",
147
+ "target": "product_price11",
148
+ "subRules": [
149
+
150
+ ]
151
+ },
152
+ {
153
+ "id": "636d3924-0298-4e9b-809a-26d4a10d7b89",
154
+ "type": 0,
155
+ "source": "product_price12",
156
+ "target": "product_price12",
157
+ "subRules": [
158
+
159
+ ]
160
+ },
161
+
162
+ ]} label="测试关联单选" options={[{ label: '选项1', value: '1', product_price11:"1111", product_price12:"2222"}, { label: '选项2', value: '2' }]} __id="remark11" />
163
+
142
164
  <Field.Switch label="开关" __id="switch_table"></Field.Switch>
143
165
  <Field.Input isRequired={true} label="商品价格" __id="product_price11" />
144
166
  <Field.Input isRequired={true} label="商品价格" __id="product_price12" />
@@ -303,7 +325,7 @@ function App() {
303
325
  </Layout.FormRow>
304
326
  <Field.CheckboxTree label="角色权限" __id="permissions" addRoot={false} treeData={treeData} />
305
327
  <Layout.FormGroupTitle title={"关联信息"} />
306
- <Field.WithSingleSelect fillRules={[
328
+ <Field.WithSingleSelect ref={testRef} fillRules={[
307
329
  {
308
330
  "id": "636d3924-0298-4e9b-809a-26d4a10d7b89",
309
331
  "type": 0,
@@ -375,6 +397,10 @@ function App() {
375
397
  <Button type="primary" onClick={validateFields}>validateFields</Button>
376
398
  <Button type="primary" onClick={getFormFields}>GetValues</Button>
377
399
  <Button type="primary" onClick={setFormFields}>SetValues</Button>
400
+ <Button type="primary" onClick={()=>{
401
+ console.log("testRef.current",testRef.current)
402
+ testRef.current?.handleChange({ label: '选项1', value: '1', name:"1111",table:"[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2}]"})
403
+ }}>testwithref</Button>
378
404
  <Button type="primary" onClick={handleCols}>UpdateCol</Button>
379
405
  </div>
380
406
 
@@ -62,7 +62,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
62
62
  function traverse(currentNode, parentNode = null) {
63
63
  var componentName = currentNode.type?.displayName || currentNode.props?._componentName;
64
64
  const { props } = currentNode;
65
- console.log("props ///////////", props)
66
65
  if (componentName && (componentName.startsWith('Field.') || componentName.startsWith('Layout.'))) {
67
66
  let identifier = props?.componentId || props?.__id;
68
67
  let withIds = []
@@ -74,7 +73,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
74
73
  if (props?.withIds)
75
74
  withIds = [...withIds, ...props?.withIds]
76
75
 
77
- fields.push({ identifier, withIds, component: currentNode,componentName, fillRules:props?.fillRules });
76
+ fields.push({ identifier, withIds, component: currentNode, componentName, fillRules: props?.fillRules });
78
77
  }
79
78
 
80
79
  if (props?.children) {
@@ -107,13 +106,13 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
107
106
  const initializeFieldVisibility = (reloadFields = false) => {
108
107
  const fieldValues = form.getFieldsValue();
109
108
  for (let key of dependencyMap.current.keys()) {
110
- handleFieldsWith(key, fieldValues);
109
+ handleFieldsWith(key, fieldValues, true);
111
110
  }
112
111
  if (reloadFields) setFormContent(renderChildren());
113
112
  };
114
113
 
115
114
  // 计算字段级联关系
116
- const handleFieldsWith = (identifier, fieldValues) => {
115
+ const handleFieldsWith = (identifier, fieldValues, init = false) => {
117
116
  let needRefresh = false;
118
117
  let parentIdentifier = [];
119
118
  if (Array.isArray(identifier)) {
@@ -121,12 +120,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
121
120
  identifier = identifier.filter(item => typeof item == "string").join(".")
122
121
  }
123
122
  if (dependencyMap.current.has(identifier)) {
124
- const dependent = dependencyMap.current.get(identifier)
125
- console.log("dependent",dependent)
123
+ const dependent = dependencyMap.current.get(identifier)
126
124
  const dependentChildren = dependent.children;
127
- // console.log("dependentChildren", dependentChildren)
128
- if (dependent?.fillRules && Array.isArray(dependent?.fillRules) && dependent?.fillRules.length > 0) {
129
- handleFillRules(identifier,parentIdentifier, fieldValues, dependent?.fillRules)
125
+ if (!init && dependent?.fillRules && Array.isArray(dependent?.fillRules) && dependent?.fillRules.length > 0) {
126
+ handleFillRules(identifier, parentIdentifier, fieldValues, dependent?.fillRules)
130
127
  }
131
128
  dependentChildren.forEach(child => {
132
129
  if (child.component.props.withFunc && typeof child.component.props.withFunc === 'function') {
@@ -134,7 +131,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
134
131
  }
135
132
 
136
133
  if (child.component.props.withFill)
137
- handleFieldsWithFill(fieldValues, child, parentIdentifier,dependent?.componentName)
134
+ handleFieldsWithFill(fieldValues, child, parentIdentifier, dependent?.componentName)
138
135
 
139
136
  });
140
137
  }
@@ -142,40 +139,54 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
142
139
  };
143
140
 
144
141
  // 处理填充规则
145
- const handleFillRules = (current_identifier,parentIdentifier, fieldValues, fillRules) => {
142
+ const handleFillRules = (current_identifier, parentIdentifier, fieldValues, fillRules) => {
143
+
144
+
146
145
  // 获取当前变更的字段数据
147
- let current_value = getParamValue("fieldsValue", current_identifier, fieldValues, null)
146
+ let current_value = getParamValue("fieldsValue", current_identifier, fieldValues, null)
148
147
  for (let index = 0; index < fillRules.length; index++) {
149
148
  const rule = fillRules[index];
150
- const { source , target } = rule
151
- let source_value = current_value?.[source]
149
+ let { source, target } = rule
150
+ let source_value = current_value?.[source]
151
+ let setValue = source_value
152
152
  // 子表
153
153
  if (rule?.type == 1) {
154
- console.log("source_value",source_value)
155
154
  if (source_value && typeof source_value == "string") {
156
- try {
157
- source_value = JSON.parse(source_value)
158
- } catch (error) {
159
- console.log("error end",error)}
155
+ try {
156
+ source_value = JSON.parse(source_value)
157
+ } catch (error) {
158
+ console.log("error end", error)
159
+ }
160
160
  }
161
- console.log("source_value end",source_value)
162
161
 
163
- if (!Array.isArray(source_value)) return
162
+ if (!Array.isArray(source_value)) return
164
163
  let target_value = source_value.map(item => {
165
164
  let target_value = {}
166
165
  if (rule?.subRules && Array.isArray(rule?.subRules) && rule?.subRules.length > 0)
167
166
  for (let index = 0; index < rule?.subRules.length; index++) {
168
- const { source:subSource, target:subTarget } = rule?.subRules[index];
167
+ const { source: subSource, target: subTarget } = rule?.subRules[index];
169
168
  target_value[subTarget] = item?.[subSource]
170
169
  }
171
170
  return target_value
172
171
  })
173
- form.setFieldValue(target,target_value)
172
+ setValue = target_value
174
173
  }
175
174
  // 同级字段
176
- else form.setFieldValue(target,source_value)
175
+ else {
176
+ let withFillIndex = 0
177
+ let withFillGroup = ""
178
+ if (parentIdentifier && Array.isArray(parentIdentifier) && parentIdentifier.length > 1) {
179
+ withFillGroup = parentIdentifier.filter(item => typeof item == "string").join(".")
180
+ withFillIndex = parentIdentifier[parentIdentifier.length - 1]
181
+ target = [...parentIdentifier, target]
182
+ if (Array.isArray(current_value) && current_value.length > withFillIndex) {
183
+ setValue = current_value[withFillIndex]?.[source]
184
+ }
185
+ }
186
+ }
187
+ form.setFieldValue(target, setValue)
177
188
  }
178
- console.log("current value",current_value )
189
+ console.log("current value", current_value)
179
190
  }
180
191
  // 处理级联显示隐藏 @return {boolean} 是否需要重新渲染表单的字段
181
192
  const handleFieldsVisible = (fieldValues, child, parentIdentifier) => {
@@ -194,7 +205,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
194
205
  }
195
206
  // 处理级联数据源
196
207
  // 处理级联填充
197
- const handleFieldsWithFill = async (fieldValues, child, parentIdentifier,componentName) => {
208
+ const handleFieldsWithFill = async (fieldValues, child, parentIdentifier, componentName) => {
198
209
  const withFill = child?.component?.props.withFill;
199
210
  const withDataFetch = child?.component?.props.withDataFetch;
200
211
  let withFillIndex = 0
@@ -205,10 +216,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
205
216
  withFillIndex = parentIdentifier[parentIdentifier.length - 1]
206
217
  if (childIdentifier.startsWith(`${withFillGroup}.`)) {
207
218
  childIdentifier = [...parentIdentifier, childIdentifier.replace(`${withFillGroup}.`, "")]
208
- }
219
+ }
209
220
  }
210
221
  let withDatas = [];
211
- console.log("componentName",componentName)
222
+ console.log("componentName", componentName)
212
223
  // 先处理依赖数据
213
224
  if (withFill?.withData && withFill?.withData.length > 0 && withDataFetch && typeof withDataFetch === 'function') {
214
225
  for (let index = 0; index < withFill?.withData.length; index++) {