lu-lowcode-package-form 0.9.70 → 0.9.72
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 +4 -4
- package/dist/index.es.js +295 -292
- package/package.json +1 -1
- package/src/App.jsx +91 -45
- package/src/components/editor/quill.jsx +1 -1
- package/src/components/field/base.jsx +4 -1
- package/src/components/field/date-picker/index.jsx +6 -6
- package/src/components/field/select/select.jsx +1 -1
- package/src/components/field/upload/upload-image.jsx +1 -1
- package/src/components/form-container/index.jsx +24 -9
- package/src/utils/formula.js +2 -2
package/package.json
CHANGED
package/src/App.jsx
CHANGED
@@ -16,7 +16,7 @@ const searchSelectOptions = [
|
|
16
16
|
{ id: 9, name: "9999" },
|
17
17
|
]
|
18
18
|
const searchSelectRequest = async (params) => {
|
19
|
-
console.log("params", params)
|
19
|
+
// console.log("params", params)
|
20
20
|
return await new Promise((resolve) => {
|
21
21
|
setTimeout(() => {
|
22
22
|
if (params && params?.name) {
|
@@ -76,7 +76,7 @@ function App() {
|
|
76
76
|
const formRef = React.createRef();
|
77
77
|
const testRef = React.useRef()
|
78
78
|
useEffect(() => {
|
79
|
-
console.log("testRef //////", testRef.current)
|
79
|
+
// console.log("testRef //////", testRef.current)
|
80
80
|
}, [testRef.current])
|
81
81
|
const [cols, setCols] = React.useState(3);
|
82
82
|
|
@@ -138,9 +138,43 @@ function App() {
|
|
138
138
|
<FormContainerWrapper cols={cols} className="" ref={formRef} >
|
139
139
|
<Field.UserSelect label="选择用户" __id="userselect" defaultValue={[{ id: 1, username: "十天" }]} />
|
140
140
|
<Layout.FormGroupTitle title={"基本信息"} />
|
141
|
+
<Field.Number label="税率(%)" __id="shuilv" />
|
142
|
+
|
143
|
+
<Field.WithSingleSelect ref={testRef} fillRules={[
|
144
|
+
{
|
145
|
+
"id": "636d3924-0298-4e9b-809a-26d4a10d7b89",
|
146
|
+
"type": 0,
|
147
|
+
"source": "name",
|
148
|
+
"target": "name",
|
149
|
+
"subRules": [
|
150
|
+
|
151
|
+
]
|
152
|
+
},
|
153
|
+
{
|
154
|
+
"id": "93401e38-60a4-4acf-84a6-8958785a4a30",
|
155
|
+
"type": 1,
|
156
|
+
"source": "table",
|
157
|
+
"target": "table",
|
158
|
+
"subRules": [
|
159
|
+
{
|
160
|
+
"id": "c4a65ae5-58ff-4d7f-8738-a04de1acab61",
|
161
|
+
"type": 0,
|
162
|
+
"source": "price",
|
163
|
+
"target": "product_price1"
|
164
|
+
},
|
165
|
+
|
166
|
+
{
|
167
|
+
"id": "c4a65ae5-58ff-4d7f-8738-a04de1acab61",
|
168
|
+
"type": 0,
|
169
|
+
"source": "num",
|
170
|
+
"target": "product_num1"
|
171
|
+
},
|
172
|
+
]
|
173
|
+
}
|
174
|
+
]} label="测试关联单选" options={[{ label: '选项1', value: '1', name: "1111", table: "[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2},{\"price\":3,\"num\":3},{\"price\":3,\"num\":3}]" }, { label: '选项2', value: '2' }]} __id="remark11" />
|
141
175
|
<Layout.FormRow layout={'1'}>
|
142
176
|
<Field.Table label="子表格" __id="table" >
|
143
|
-
<Field.DatePicker defaultNow={true}
|
177
|
+
<Field.DatePicker defaultNow={true} label="日期时间" prompt="" datetype="date" __id="datetime2" />
|
144
178
|
<Field.WithSingleSelect ref={testRef} fillRules={[
|
145
179
|
{
|
146
180
|
"id": "636d3924-0298-4e9b-809a-26d4a10d7b89",
|
@@ -170,13 +204,57 @@ function App() {
|
|
170
204
|
]
|
171
205
|
},
|
172
206
|
|
173
|
-
]} label="测试关联单选" options={[{ label: '选项1', value: '1', product_price11: "1111", product_price12: "2222", product_price1: 111 }, { label: '选项2', value: '2' }]} __id="remark11" />
|
207
|
+
]} label="测试关联单选" options={[{ label: '选项1', value: '1', product_price11: "1111", product_price12: "2222", product_price1: 111 }, { label: '选项2', value: '2' }, { label: '选项2', value: '2' }]} __id="remark11" />
|
174
208
|
|
175
209
|
<Field.Switch label="开关" __id="switch_table"></Field.Switch>
|
176
|
-
<Field.Input defaultValue={3} isRequired={true} label="
|
177
|
-
<Field.Input isRequired={true} label="
|
178
|
-
|
179
|
-
|
210
|
+
<Field.Input defaultValue={3} isRequired={true} label="含税单价" __id="product_price11" />
|
211
|
+
<Field.Input isRequired={true} label="未税单价" __id="product_price12"
|
212
|
+
withIds={[
|
213
|
+
"table.product_price11",
|
214
|
+
"shuilv"
|
215
|
+
]}
|
216
|
+
withFill={{
|
217
|
+
"value": [
|
218
|
+
{
|
219
|
+
"insert": "("
|
220
|
+
},
|
221
|
+
{
|
222
|
+
"insert": {
|
223
|
+
"span": true
|
224
|
+
},
|
225
|
+
"attributes": {
|
226
|
+
"id": "table.product_price11",
|
227
|
+
"color": "blue",
|
228
|
+
"tagKey": "fieldsValue",
|
229
|
+
"content": "当前表单.产品列表.含税单价"
|
230
|
+
}
|
231
|
+
},
|
232
|
+
{
|
233
|
+
"insert": "/(1+"
|
234
|
+
},
|
235
|
+
{
|
236
|
+
"insert": {
|
237
|
+
"span": true
|
238
|
+
},
|
239
|
+
"attributes": {
|
240
|
+
"id": "shuilv",
|
241
|
+
"color": "blue",
|
242
|
+
"tagKey": "fieldsValue",
|
243
|
+
"content": "当前表单.税率(%)"
|
244
|
+
}
|
245
|
+
},
|
246
|
+
{
|
247
|
+
"insert": "/ 100)).toFixed(2)\n\n\n"
|
248
|
+
}
|
249
|
+
],
|
250
|
+
"version": 1723016911807,
|
251
|
+
"withData": [
|
252
|
+
|
253
|
+
]
|
254
|
+
}}
|
255
|
+
/>
|
256
|
+
<Field.Input isRequired={true} defaultValue={1} label="商品价格" __id="product_price13" />
|
257
|
+
<Field.Input isRequired={true} defaultValue={2} label="商品价格" __id="product_price14" />
|
180
258
|
<Field.Input isRequired={true} label="商品价格" __id="product_price1" />
|
181
259
|
<Field.Input isRequired={true} label="商品个数" __id="product_num1" />
|
182
260
|
<Field.Input label="商品总价" __id="product_sum1"
|
@@ -325,10 +403,10 @@ function App() {
|
|
325
403
|
return fieldsValue?.switch ? true : false
|
326
404
|
}}
|
327
405
|
/>
|
328
|
-
<Field.DatePicker defaultNow={true} label="
|
329
|
-
<Field.DatePicker label="
|
330
|
-
<Field.DatePicker disabled={true} defaultNow={true} label="
|
331
|
-
<Field.DatePicker defaultNow={true} label="
|
406
|
+
<Field.DatePicker defaultNow={true} label="datetime" prompt="" datetype="month" value='2022-10-22' __id="datetime" />
|
407
|
+
<Field.DatePicker label="datetime2" prompt="" datetype="date" __id="datetime2" />
|
408
|
+
<Field.DatePicker isRequired={true} disabled={true} defaultNow={true} label="datetime3" prompt="" datetype="datetime" value={'2022-10-22'} __id="datetime3" />
|
409
|
+
<Field.DatePicker defaultNow={true} label="datetime4" prompt="" datetype="year" value={'2022-10-22'} __id="datetime4" />
|
332
410
|
<Field.Input label="角色名称" __id="name" />
|
333
411
|
<Layout.FormRow layout={'1,1'}>
|
334
412
|
<Field.Input label="角色名称布局" __id="name1" />
|
@@ -336,39 +414,7 @@ function App() {
|
|
336
414
|
</Layout.FormRow>
|
337
415
|
<Field.CheckboxTree label="角色权限" __id="permissions" addRoot={false} treeData={treeData} />
|
338
416
|
<Layout.FormGroupTitle title={"关联信息"} />
|
339
|
-
<Field.
|
340
|
-
{
|
341
|
-
"id": "636d3924-0298-4e9b-809a-26d4a10d7b89",
|
342
|
-
"type": 0,
|
343
|
-
"source": "name",
|
344
|
-
"target": "name",
|
345
|
-
"subRules": [
|
346
|
-
|
347
|
-
]
|
348
|
-
},
|
349
|
-
{
|
350
|
-
"id": "93401e38-60a4-4acf-84a6-8958785a4a30",
|
351
|
-
"type": 1,
|
352
|
-
"source": "table",
|
353
|
-
"target": "table",
|
354
|
-
"subRules": [
|
355
|
-
{
|
356
|
-
"id": "c4a65ae5-58ff-4d7f-8738-a04de1acab61",
|
357
|
-
"type": 0,
|
358
|
-
"source": "price",
|
359
|
-
"target": "product_price1"
|
360
|
-
},
|
361
|
-
|
362
|
-
{
|
363
|
-
"id": "c4a65ae5-58ff-4d7f-8738-a04de1acab61",
|
364
|
-
"type": 0,
|
365
|
-
"source": "num",
|
366
|
-
"target": "product_num1"
|
367
|
-
},
|
368
|
-
]
|
369
|
-
}
|
370
|
-
]} label="测试关联单选" options={[{ label: '选项1', value: '1', name: "1111", table: "[{\"price\":1,\"num\":2},{\"price\":2,\"num\":2}]" }, { label: '选项2', value: '2' }]} __id="remark11" />
|
371
|
-
<Field.WithMultipleSelect disabled={true} label="测试关联多选" options={[{ label: '选项1', value: '1' }, { label: '选项2', value: '2' }]} __id="remark12" />
|
417
|
+
<Field.WithMultipleSelect disabled={true} label="测试关联多选" options={[{ label: '选项1', value: '1' }, { label: '选项2', value: '2' }]} __id="remark12" />
|
372
418
|
<Layout.FormRow > <Field.TextArea label="备注" __id="remark" /></Layout.FormRow>
|
373
419
|
|
374
420
|
<Layout.FormRow layout={'1'}>
|
@@ -31,7 +31,10 @@ export const BaseWrapper = ({
|
|
31
31
|
...otherProps
|
32
32
|
}) => {
|
33
33
|
useEffect(()=>{
|
34
|
-
if (defaultValue && typeof onChange === "function")
|
34
|
+
if (defaultValue && typeof onChange === "function") {
|
35
|
+
console.log("defaultValue changed", defaultValue)
|
36
|
+
onChange(defaultValue)
|
37
|
+
}
|
35
38
|
},[defaultValue])
|
36
39
|
if (!addWrapper) return children;
|
37
40
|
// 不接管只读属性的组件
|
@@ -21,12 +21,12 @@ const DatePicker = ({ datetype, value, defaultNow, onChange, ...props }) => {
|
|
21
21
|
const [needConfirm, setNeedConfirm] = useState(false)
|
22
22
|
const isChanged = useRef(false)
|
23
23
|
useEffect(() => {
|
24
|
-
console.log(
|
25
|
-
console.log(
|
24
|
+
// console.log(`${props?.__id} defaultNow `, defaultNow)
|
25
|
+
// console.log(`${props?.__id} value `, value)
|
26
|
+
// console.log(`${props?.__id} value type `, typeof value)
|
26
27
|
if (defaultNow && !value && !isChanged.current) {
|
27
|
-
const now =dayjs().format("YYYY-MM-DD HH:mm:ss")
|
28
|
-
|
29
|
-
typeof onChange === "function" && onChange(now)
|
28
|
+
const now = dayjs().format("YYYY-MM-DD HH:mm:ss")
|
29
|
+
typeof onChange == "function" && onChange(now)
|
30
30
|
return
|
31
31
|
}
|
32
32
|
// if (value && typeof value === "string" && dayjs(value).isValid()) {
|
@@ -75,7 +75,7 @@ const DatePicker = ({ datetype, value, defaultNow, onChange, ...props }) => {
|
|
75
75
|
}, [datetype])
|
76
76
|
return (
|
77
77
|
<BaseWrapper {...props}>
|
78
|
-
<OriginalDatePicker locale={zh} {...props} picker={picker} format={format} style={{ width: '100%' }} onChange={handleChange} value={dayjs(value).isValid() ? dayjs(value) : undefined} showTime={showTime} needConfirm={needConfirm} />
|
78
|
+
<OriginalDatePicker locale={zh} {...props} picker={picker} format={format} style={{ width: '100%' }} onChange={handleChange} value={value && dayjs(value).isValid() ? dayjs(value) : undefined} showTime={showTime} needConfirm={needConfirm} />
|
79
79
|
</BaseWrapper>
|
80
80
|
);
|
81
81
|
}
|
@@ -124,7 +124,7 @@ const WithMultipleSelect = ({ readItemRender, readonly, onChange, value, ...prop
|
|
124
124
|
|
125
125
|
// 选择用户组件
|
126
126
|
const UserSelect = ({ customComponent: CustomComponent, ...props }) => {
|
127
|
-
console.log("UserSelect ////// props",props)
|
127
|
+
// console.log("UserSelect ////// props",props)
|
128
128
|
if (!CustomComponent) return <BaseWrapper {...props}><Input {...props} /></BaseWrapper>
|
129
129
|
else return <BaseWrapper {...props}><CustomComponent {...props} /></BaseWrapper>
|
130
130
|
}
|
@@ -5,7 +5,7 @@ import { DeleteOutlined, EyeOutlined, PlusOutlined } from "@ant-design/icons";
|
|
5
5
|
import React, { useEffect, useRef, useState, version } from "react";
|
6
6
|
|
7
7
|
const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
8
|
-
console.log("uploadimage props", props)
|
8
|
+
// console.log("uploadimage props", props)
|
9
9
|
useEffect(() => {
|
10
10
|
if (value) {
|
11
11
|
console.log("value", value)
|
@@ -122,6 +122,8 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
122
122
|
if (dependencyMap.current.has(identifier)) {
|
123
123
|
const dependent = dependencyMap.current.get(identifier)
|
124
124
|
const dependentChildren = dependent.children;
|
125
|
+
// console.log("identifier", identifier)
|
126
|
+
// console.log("dependentChildren", dependentChildren)
|
125
127
|
if (!init && dependent?.fillRules && Array.isArray(dependent?.fillRules) && dependent?.fillRules.length > 0) {
|
126
128
|
handleFillRules(identifier, parentIdentifier, fieldValues, dependent?.fillRules)
|
127
129
|
}
|
@@ -140,8 +142,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
140
142
|
|
141
143
|
// 处理填充规则
|
142
144
|
const handleFillRules = (current_identifier, parentIdentifier, fieldValues, fillRules) => {
|
143
|
-
|
144
|
-
|
145
145
|
// 获取当前变更的字段数据
|
146
146
|
let current_value = getParamValue("fieldsValue", current_identifier, fieldValues, null)
|
147
147
|
for (let index = 0; index < fillRules.length; index++) {
|
@@ -161,13 +161,13 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
161
161
|
|
162
162
|
if (!Array.isArray(source_value)) return
|
163
163
|
let target_value = source_value.map(item => {
|
164
|
-
let
|
164
|
+
let target_item_value = {}
|
165
165
|
if (rule?.subRules && Array.isArray(rule?.subRules) && rule?.subRules.length > 0)
|
166
166
|
for (let index = 0; index < rule?.subRules.length; index++) {
|
167
167
|
const { source: subSource, target: subTarget } = rule?.subRules[index];
|
168
|
-
|
168
|
+
target_item_value[subTarget] = item?.[subSource]
|
169
169
|
}
|
170
|
-
return
|
170
|
+
return target_item_value
|
171
171
|
})
|
172
172
|
setValue = target_value
|
173
173
|
}
|
@@ -187,7 +187,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
187
187
|
form.setFieldValue(target, setValue)
|
188
188
|
handleFieldsWith(target, form.getFieldsValue())
|
189
189
|
}
|
190
|
-
console.log("current value", current_value)
|
190
|
+
// console.log("current value", current_value)
|
191
191
|
}
|
192
192
|
// 处理级联显示隐藏 @return {boolean} 是否需要重新渲染表单的字段
|
193
193
|
const handleFieldsVisible = (fieldValues, child, parentIdentifier) => {
|
@@ -207,6 +207,10 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
207
207
|
// 处理级联数据源
|
208
208
|
// 处理级联填充
|
209
209
|
const handleFieldsWithFill = async (fieldValues, child, parentIdentifier, componentName) => {
|
210
|
+
// console.log("handleFieldsWithFill fieldValues", fieldValues)
|
211
|
+
// console.log("handleFieldsWithFill child", child)
|
212
|
+
// console.log("handleFieldsWithFill parentIdentifier", parentIdentifier)
|
213
|
+
// console.log("handleFieldsWithFill componentName", componentName)
|
210
214
|
const withFill = child?.component?.props.withFill;
|
211
215
|
const withDataFetch = child?.component?.props.withDataFetch;
|
212
216
|
let withFillIndex = 0
|
@@ -219,8 +223,19 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
219
223
|
childIdentifier = [...parentIdentifier, childIdentifier.replace(`${withFillGroup}.`, "")]
|
220
224
|
}
|
221
225
|
}
|
226
|
+
// 被依赖字段不是子表字段,依赖字段是子表字段的情况
|
227
|
+
else if (childIdentifier.indexOf(".") >= 0) {
|
228
|
+
childIdentifier = childIdentifier.split(".")
|
229
|
+
let table_values = getParamValue("fieldsValue", childIdentifier[0], fieldValues, [])
|
230
|
+
// console.log("table_values", table_values)
|
231
|
+
if (Array.isArray(table_values) && table_values.length > 0)
|
232
|
+
for (let index = 0; index < table_values.length; index++) {
|
233
|
+
await handleFieldsWithFill(fieldValues, child, [childIdentifier[0], index], componentName)
|
234
|
+
}
|
235
|
+
return
|
236
|
+
|
237
|
+
}
|
222
238
|
let withDatas = [];
|
223
|
-
console.log("componentName", componentName)
|
224
239
|
// 先处理依赖数据
|
225
240
|
if (withFill?.withData && withFill?.withData.length > 0 && withDataFetch && typeof withDataFetch === 'function') {
|
226
241
|
for (let index = 0; index < withFill?.withData.length; index++) {
|
@@ -259,7 +274,6 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
259
274
|
const { insert, attributes } = item
|
260
275
|
if (typeof insert !== "string") {
|
261
276
|
if (insert?.span && attributes && attributes.tagKey && attributes.id) {
|
262
|
-
|
263
277
|
result = getParamValue(attributes.tagKey, attributes.id, fieldValues, withDatas)
|
264
278
|
if (Array.isArray(result)) {
|
265
279
|
if (Array.isArray(childIdentifier) && result.length > withFillIndex) {
|
@@ -278,6 +292,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
278
292
|
if (formula && formula.length > 0) {
|
279
293
|
const formulaResult = evalFormula(formula);
|
280
294
|
// console.log("formulaResult", formulaResult)
|
295
|
+
// console.log("setFieldValue setFieldValue", childIdentifier)
|
281
296
|
form.setFieldValue(childIdentifier, formulaResult)
|
282
297
|
handleFieldsWith(childIdentifier, form.getFieldsValue())
|
283
298
|
}
|
@@ -312,7 +327,7 @@ const FormContainer = forwardRef(({ cols = 1, children, mode = "view" }, ref) =>
|
|
312
327
|
const handleFieldsChange = debounce((changedFields, allFields) => {
|
313
328
|
const fieldValues = form.getFieldsValue();
|
314
329
|
let needRefresh = false;
|
315
|
-
console.log("changedFields", changedFields)
|
330
|
+
// console.log("changedFields", changedFields)
|
316
331
|
changedFields.forEach(field => {
|
317
332
|
if (field.name && field.name.length > 0) {
|
318
333
|
needRefresh = handleFieldsWith(field.name, fieldValues);
|
package/src/utils/formula.js
CHANGED
@@ -4,9 +4,9 @@ const evalFormula =(formula) => {
|
|
4
4
|
try {
|
5
5
|
result = eval(formula.join(""));
|
6
6
|
} catch (error) {
|
7
|
-
console.error("formula error", error);
|
7
|
+
// console.error("formula error", error);
|
8
8
|
}
|
9
|
-
console.log("formula result", result);
|
9
|
+
// console.log("formula result", result);
|
10
10
|
return result.toString();
|
11
11
|
};
|
12
12
|
|