lu-lowcode-package-form 0.9.8 → 0.9.18
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 +420 -172
- package/dist/index.es.js +59971 -29590
- package/dist/style.css +6 -1
- package/package.json +6 -1
- package/src/App.jsx +176 -34
- package/src/components/editor/add-with-param.jsx +13 -0
- package/src/components/editor/index.jsx +2 -0
- package/src/components/editor/quill.jsx +125 -0
- package/src/components/editor/wang.jsx +80 -0
- package/src/components/field/base.jsx +21 -6
- package/src/components/field/checkbox/index.jsx +2 -16
- package/src/components/field/date-picker/index.jsx +9 -2
- package/src/components/field/input/index.jsx +11 -1
- package/src/components/field/select/index.jsx +1 -1
- package/src/components/field/select/search-select.jsx +110 -0
- package/src/components/field/select/select.jsx +5 -5
- package/src/components/field/table/index.jsx +255 -24
- package/src/components/field/upload/upload-file.jsx +1 -2
- package/src/components/field/upload/upload-image.jsx +1 -4
- package/src/components/form-container/index.jsx +141 -29
- package/src/components/form-container/layout/form-group-title.jsx +1 -1
- package/src/components/index.jsx +15 -4
- package/src/utils/formula.js +12 -0
|
@@ -1,16 +1,30 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
const FieldLable = ({value,onChange})=>{
|
|
4
|
+
const [text, setText] = useState("");
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
setText(value);
|
|
7
|
+
console.log("value changed", value)
|
|
8
|
+
}, [value]);
|
|
9
|
+
return <>{text}</>
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
export const BaseWrapper = function BaseWrapper({
|
|
2
13
|
label,
|
|
3
14
|
children,
|
|
4
15
|
prompt,
|
|
5
16
|
subTable,
|
|
6
17
|
subTableIndex,
|
|
18
|
+
addWrapper = true,
|
|
7
19
|
...otherProps
|
|
8
20
|
}) {
|
|
21
|
+
if (!addWrapper) return children;
|
|
9
22
|
const formWarpper = (
|
|
10
23
|
<div className="frelative">
|
|
11
|
-
{label && <div className='fh-8 ftext-sm fflex fjustify-between fitems-center'>{label}</div>}
|
|
12
|
-
<div className="fw-full fflex fitems-stretch">
|
|
13
|
-
|
|
24
|
+
{label && <div className='fh-8 ftext-gray-500 ftext-sm fflex fjustify-between fitems-center'>{label}</div>}
|
|
25
|
+
<div className="fw-full fflex fitems-stretch ftext-gray-900">
|
|
26
|
+
{/* <FieldLable value={otherProps?.value} /> */}
|
|
27
|
+
{children}
|
|
14
28
|
</div>
|
|
15
29
|
{!subTable && <div className="ftext-xs ftext-gray-500 fmin-h-5 fflex fitems-center">{prompt}</div>}
|
|
16
30
|
</div>
|
|
@@ -18,9 +32,10 @@ export const BaseWrapper = function BaseWrapper({
|
|
|
18
32
|
|
|
19
33
|
const tableWarpper = (
|
|
20
34
|
<div className="frelative fw-full">
|
|
21
|
-
{label && subTableIndex === 0 && <div className='fh-12 ffont-semibold fbg-gray-100 ftext-sm fflex fjustify-between fitems-center fpx-2 fborder-b
|
|
22
|
-
<div className="fw-full fflex fitems-stretch fp-2
|
|
23
|
-
|
|
35
|
+
{label && subTableIndex === 0 && <div className='fh-12 ffont-semibold fbg-gray-100 ftext-sm fflex fjustify-between fitems-center fpx-2 fborder-b'>{label}</div>}
|
|
36
|
+
<div className="fw-full fflex fitems-stretch fp-2 ">
|
|
37
|
+
{/* <FieldLable value={otherProps?.value} /> */}
|
|
38
|
+
{children}
|
|
24
39
|
</div>
|
|
25
40
|
</div>
|
|
26
41
|
)
|
|
@@ -11,24 +11,10 @@ export const Checkbox = (props) => {
|
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const CheckboxGroup = (
|
|
15
|
-
const [nValue, setNValue] = useState([])
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (typeof value === "string") {
|
|
19
|
-
try {
|
|
20
|
-
value = JSON.parse(value)
|
|
21
|
-
onChange(value)
|
|
22
|
-
} catch (error) {
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
setNValue(value)
|
|
28
|
-
}, [value])
|
|
14
|
+
export const CheckboxGroup = (props) => {
|
|
29
15
|
return (
|
|
30
16
|
<BaseWrapper {...props}>
|
|
31
|
-
<OriginalCheckbox.Group {...props}
|
|
17
|
+
<OriginalCheckbox.Group {...props} />
|
|
32
18
|
</BaseWrapper>
|
|
33
19
|
);
|
|
34
20
|
}
|
|
@@ -3,7 +3,14 @@ import { DatePicker as OriginalDatePicker, Button } from 'antd';
|
|
|
3
3
|
import { BaseWrapper } from "../base.jsx"
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
5
|
import 'dayjs/locale/zh-cn';
|
|
6
|
-
|
|
6
|
+
import zh from 'antd/es/date-picker/locale/zh_CN';
|
|
7
|
+
|
|
8
|
+
import updateLocale from 'dayjs/plugin/updateLocale';
|
|
9
|
+
|
|
10
|
+
dayjs.extend(updateLocale);
|
|
11
|
+
dayjs.updateLocale('zh-cn', {
|
|
12
|
+
weekStart: 0,
|
|
13
|
+
});
|
|
7
14
|
|
|
8
15
|
const DatePicker = ({ datetype, value, onChange, ...props }) => {
|
|
9
16
|
datetype = datetype || "date"
|
|
@@ -58,7 +65,7 @@ const DatePicker = ({ datetype, value, onChange, ...props }) => {
|
|
|
58
65
|
}, [datetype])
|
|
59
66
|
return (
|
|
60
67
|
<BaseWrapper {...props}>
|
|
61
|
-
<OriginalDatePicker {...props} picker={picker} format={format} style={{ width: '100%' }} onChange={handleChange} value={nValue} showTime={showTime} needConfirm={needConfirm} />
|
|
68
|
+
<OriginalDatePicker locale={zh} {...props} picker={picker} format={format} style={{ width: '100%' }} onChange={handleChange} value={nValue} showTime={showTime} needConfirm={needConfirm} />
|
|
62
69
|
</BaseWrapper>
|
|
63
70
|
);
|
|
64
71
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Input as OriginalInput } from 'antd';
|
|
2
|
+
import { InputNumber } from 'antd';
|
|
2
3
|
import { BaseWrapper } from "../base.jsx"
|
|
3
4
|
import React from 'react';
|
|
4
5
|
const {
|
|
@@ -7,6 +8,8 @@ const {
|
|
|
7
8
|
Search: OriginalSearch,
|
|
8
9
|
} = OriginalInput;
|
|
9
10
|
|
|
11
|
+
|
|
12
|
+
|
|
10
13
|
const Input = (props) =>{
|
|
11
14
|
return (
|
|
12
15
|
<BaseWrapper {...props}>
|
|
@@ -48,4 +51,11 @@ const Search = (props) =>{
|
|
|
48
51
|
);
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
const Number = (props) =>{
|
|
55
|
+
return (
|
|
56
|
+
<BaseWrapper {...props}>
|
|
57
|
+
<InputNumber {...props} style={{width: '100%'}} />
|
|
58
|
+
</BaseWrapper>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
export {Input,TextArea,Password,Search,CodeMachine,Number};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { Input, Select as OriginalSelect, Spin } from 'antd';
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import { BaseWrapper } from "../base"
|
|
6
|
+
import { debounce } from 'lodash';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const SearchSelect = ({ addWrapper = true, value, type, defaultValue, onChange, option_label, option_value, option_search, options, request, requestParams, callError, ...props }) => {
|
|
10
|
+
const [nOptions, setNOptions] = React.useState([])
|
|
11
|
+
const [fetching, setFetching] = useState(false);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
initData(requestParams)
|
|
14
|
+
}, [requestParams])
|
|
15
|
+
|
|
16
|
+
const initData = async (params) => {
|
|
17
|
+
let item = null
|
|
18
|
+
if (request && typeof request === 'function') {
|
|
19
|
+
const list = await fetchOptions(params)
|
|
20
|
+
if (list && Array.isArray(list))
|
|
21
|
+
item = value ? list.find(item => item.value == value) : null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (options && options.length > 0) {
|
|
25
|
+
item = value ? options.find(item => item.value == value) : null
|
|
26
|
+
setNOptions(options)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (item) {
|
|
30
|
+
onChange(item)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const handleSearch = debounce(async (value) => {
|
|
36
|
+
const params = { ...requestParams }
|
|
37
|
+
params[option_search] = value
|
|
38
|
+
await fetchOptions(params)
|
|
39
|
+
}, 200)
|
|
40
|
+
|
|
41
|
+
const fetchOptions = async (params) => {
|
|
42
|
+
try {
|
|
43
|
+
setFetching(true)
|
|
44
|
+
const response = await request(params);
|
|
45
|
+
if (response.code > 0) {
|
|
46
|
+
callError && typeof callError === 'function' && callError(response.message);
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
let list = response.data?.list || response.data
|
|
50
|
+
if (Array.isArray(list)) {
|
|
51
|
+
list = list.map(item => ({ ...item, label: item[option_label], value: item[option_value] }))
|
|
52
|
+
setNOptions(list)
|
|
53
|
+
}
|
|
54
|
+
else setNOptions([])
|
|
55
|
+
return list
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error("fetchOptions", error)
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
setFetching(false)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const handleChange = (value) => {
|
|
65
|
+
const item = nOptions.find(item => item.value === value)
|
|
66
|
+
onChange(item)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
return addWrapper ? (
|
|
71
|
+
<BaseWrapper {...props}>
|
|
72
|
+
<OriginalSelect
|
|
73
|
+
notFoundContent={fetching ? <Spin size="small" /> : null}
|
|
74
|
+
value={value}
|
|
75
|
+
{...props}
|
|
76
|
+
disabled={false}
|
|
77
|
+
filterOption={false}
|
|
78
|
+
showSearch={request && option_search ? true : false}
|
|
79
|
+
onSearch={request && option_search ? handleSearch : null}
|
|
80
|
+
onChange={handleChange}
|
|
81
|
+
style={{ width: '100%' }}
|
|
82
|
+
mode="single" >
|
|
83
|
+
{nOptions.map((item, index) => (
|
|
84
|
+
<OriginalSelect.Option key={index} value={item.value} disabled={false}>
|
|
85
|
+
{item.label}
|
|
86
|
+
</OriginalSelect.Option>
|
|
87
|
+
))}
|
|
88
|
+
</OriginalSelect>
|
|
89
|
+
</BaseWrapper>
|
|
90
|
+
) : <OriginalSelect
|
|
91
|
+
notFoundContent={fetching ? <Spin size="small" /> : null}
|
|
92
|
+
value={value}
|
|
93
|
+
{...props}
|
|
94
|
+
disabled={false}
|
|
95
|
+
filterOption={false}
|
|
96
|
+
showSearch={request && option_search ? true : false}
|
|
97
|
+
onSearch={request && option_search ? handleSearch : null}
|
|
98
|
+
onChange={handleChange}
|
|
99
|
+
style={{ width: '100%' }}
|
|
100
|
+
mode="single" >
|
|
101
|
+
{nOptions.map((item, index) => (
|
|
102
|
+
<OriginalSelect.Option key={index} value={item.value} disabled={false}>
|
|
103
|
+
{item.label}
|
|
104
|
+
</OriginalSelect.Option>
|
|
105
|
+
))}
|
|
106
|
+
</OriginalSelect>
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {SearchSelect}
|
|
@@ -3,7 +3,7 @@ import { Select as OriginalSelect } from "antd";
|
|
|
3
3
|
import { BaseWrapper } from "../base"
|
|
4
4
|
import React, { useEffect, useState } from 'react';
|
|
5
5
|
|
|
6
|
-
const Select = ({ request, option_label = "label", option_value = "id", disabledValue, callError, options, ...props }) => {
|
|
6
|
+
const Select = ({ request, option_label = "label", option_value = "id", disabledValue, callError, options, addWrapper = true, ...props }) => {
|
|
7
7
|
// const [firstLoad, setFirstLoad] = React.useState(false)
|
|
8
8
|
const [nOptions, setNOptions] = React.useState([])
|
|
9
9
|
useEffect(() => {
|
|
@@ -29,11 +29,11 @@ const Select = ({ request, option_label = "label", option_value = "id", disabled
|
|
|
29
29
|
|
|
30
30
|
// setFirstLoad(true)
|
|
31
31
|
}
|
|
32
|
-
return (
|
|
32
|
+
return addWrapper ?(
|
|
33
33
|
<BaseWrapper {...props}>
|
|
34
34
|
<OriginalSelect {...props} options={nOptions} style={{ width: '100%' }} />
|
|
35
35
|
</BaseWrapper>
|
|
36
|
-
)
|
|
36
|
+
) : <OriginalSelect {...props} options={nOptions} style={{ width: '100%' }} />
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const SingleSelect = ({ ...props }) => {
|
|
@@ -46,7 +46,7 @@ const MultipleSelect = ({ onChange, value, ...props }) => {
|
|
|
46
46
|
const [nValue, setNValue] = React.useState([])
|
|
47
47
|
|
|
48
48
|
useEffect(()=>{
|
|
49
|
-
if (typeof value === "string") {
|
|
49
|
+
if (value && typeof value === "string") {
|
|
50
50
|
try {
|
|
51
51
|
value = JSON.parse(value)
|
|
52
52
|
onChange(value)
|
|
@@ -55,7 +55,7 @@ const MultipleSelect = ({ onChange, value, ...props }) => {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
setNValue(value)
|
|
58
|
+
if(value) setNValue(value)
|
|
59
59
|
},[value])
|
|
60
60
|
|
|
61
61
|
return (
|
|
@@ -1,36 +1,267 @@
|
|
|
1
|
-
import React, { useState } from "react"
|
|
2
|
-
import { Button
|
|
1
|
+
import React, { useEffect, useState, useRef, useCallback } from "react";
|
|
2
|
+
import { Button } from "antd";
|
|
3
|
+
import { DeleteOutlined } from "@ant-design/icons";
|
|
4
|
+
import { isEqual, debounce } from 'lodash';
|
|
5
|
+
import { evalFormula } from "../../../utils/formula";
|
|
3
6
|
|
|
4
7
|
const TableCol = ({ children, width, ...props }) => {
|
|
5
|
-
|
|
8
|
+
const [sWidth, setSWidth] = useState(0);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setSWidth(width);
|
|
11
|
+
}, [width]);
|
|
12
|
+
return <div className="fflex-1" style={{ minWidth: `${sWidth}px` }} {...props}>
|
|
6
13
|
{children}
|
|
7
14
|
</div>
|
|
8
15
|
}
|
|
9
16
|
|
|
10
|
-
const
|
|
11
|
-
|
|
17
|
+
const TableAction = ({ label, subTableIndex, children, ...props }) => {
|
|
18
|
+
return <div className="fw-16">
|
|
19
|
+
<div className="frelative fw-full fh-full fflex fflex-col">
|
|
20
|
+
{label && subTableIndex === 0 && <div className='fh-12 ffont-semibold fbg-gray-100 ftext-sm fflex fjustify-between fitems-center fpx-2 fborder-b'>{label}</div>}
|
|
21
|
+
<div className="fw-full fflex-1 fflex fitems-center fjustify-center fp-2 ">
|
|
22
|
+
{children}
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const Table = ({ children, value, onChange, ...props }) => {
|
|
29
|
+
const [rows, setRows] = useState([{}]);
|
|
30
|
+
const prevRowsRef = useRef(rows);
|
|
31
|
+
const dependencyMap = useRef(new Map());
|
|
32
|
+
const [updateField, setUpdateField] = useState({});
|
|
33
|
+
const tableId = props.componentId || props.__id;
|
|
34
|
+
const setPrevRows = (newValue) => {
|
|
35
|
+
setRows(newValue);
|
|
36
|
+
prevRowsRef.current = newValue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
console.log("value useEffect ", JSON.stringify(value));
|
|
41
|
+
if (value && typeof value === "string") {
|
|
42
|
+
try {
|
|
43
|
+
value = JSON.parse(value);
|
|
44
|
+
onChange(value);
|
|
45
|
+
} catch (error) { }
|
|
46
|
+
}
|
|
47
|
+
if (value && Array.isArray(value) && !isEqual(prevRowsRef.current, value)) {
|
|
48
|
+
console.log("useEffect setRows");
|
|
49
|
+
setPrevRows(value);
|
|
50
|
+
}
|
|
51
|
+
}, [value]);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
console.log("children useEffect ",children);
|
|
55
|
+
initializeDependencyMap();
|
|
56
|
+
}, [children]);
|
|
57
|
+
|
|
58
|
+
const initializeDependencyMap = useCallback(() => {
|
|
59
|
+
dependencyMap.current.clear();
|
|
60
|
+
const childrenArray = React.Children.toArray(children);
|
|
61
|
+
childrenArray.forEach(child => {
|
|
62
|
+
const { componentId, __id, ...props } = child.props;
|
|
63
|
+
const identifier = `${tableId}.${(componentId || __id)}`;
|
|
64
|
+
|
|
65
|
+
dependencyMap.current.set(identifier, {
|
|
66
|
+
children: childrenArray.filter(item => item.props.withId === identifier || item.props.withIds?.includes(identifier)),
|
|
67
|
+
show: true,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
initializeFieldVisibility();
|
|
71
|
+
}, [children, tableId]);
|
|
72
|
+
|
|
73
|
+
const handleRowValues = useCallback((rowValues) => {
|
|
74
|
+
const result = {};
|
|
75
|
+
for (let key in rowValues) {
|
|
76
|
+
result[`${tableId}.${key}`] = rowValues[key] || '';
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}, [tableId]);
|
|
80
|
+
|
|
81
|
+
const initializeFieldVisibility = useCallback(() => {
|
|
82
|
+
rows.forEach((row, rowIndex) => {
|
|
83
|
+
const fieldValues = handleRowValues(row);
|
|
84
|
+
for (let key of dependencyMap.current.keys()) {
|
|
85
|
+
handleFieldsWith(key, fieldValues, rowIndex);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}, [rows, handleRowValues]);
|
|
89
|
+
|
|
90
|
+
const handleFieldsWith = useCallback((identifier, fieldValues, rowIndex) => {
|
|
91
|
+
let needRefresh = false;
|
|
92
|
+
const fullIdentifier = `${tableId}.${identifier}`;
|
|
93
|
+
if (dependencyMap.current.has(fullIdentifier)) {
|
|
94
|
+
const dependentChildren = dependencyMap.current.get(fullIdentifier).children;
|
|
95
|
+
dependentChildren.forEach(child => {
|
|
96
|
+
if (child.props.withFunc && typeof child.props.withFunc === 'function') {
|
|
97
|
+
needRefresh = handleFieldsVisible(fieldValues, child);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (child.props.withFill) {
|
|
101
|
+
handleFieldsWithFill(fieldValues, child, rowIndex);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return needRefresh;
|
|
106
|
+
}, [tableId, rows]);
|
|
107
|
+
|
|
108
|
+
const handleFieldsVisible = useCallback((fieldValues, child) => {
|
|
109
|
+
let needRefresh = false;
|
|
110
|
+
const childShouldBeVisible = child.props.withFunc(fieldValues);
|
|
111
|
+
const childIdentifier = child.props.componentId || child.props.__id;
|
|
112
|
+
if (dependencyMap.current.has(childIdentifier)) {
|
|
113
|
+
const childData = dependencyMap.current.get(childIdentifier);
|
|
114
|
+
if (childData.show !== childShouldBeVisible) {
|
|
115
|
+
childData.show = childShouldBeVisible;
|
|
116
|
+
dependencyMap.current.set(childIdentifier, childData);
|
|
117
|
+
needRefresh = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return needRefresh;
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
const handleFieldsWithFill = useCallback(async (fieldValues, child, rowIndex) => {
|
|
124
|
+
const withFill = child.props.withFill;
|
|
125
|
+
const withDataFetch = child.props.withDataFetch;
|
|
126
|
+
|
|
127
|
+
let withDatas = [];
|
|
128
|
+
if (withFill?.withData && withFill?.withData.length > 0 && withDataFetch && typeof withDataFetch === 'function') {
|
|
129
|
+
for (let index = 0; index < withFill?.withData.length; index++) {
|
|
130
|
+
const element = withFill?.withData[index];
|
|
131
|
+
let params = {}
|
|
132
|
+
params.tableName = element.withTable.table_name;
|
|
133
|
+
params.filter = {};
|
|
134
|
+
for (let index = 0; index < element.withCondition.length; index++) {
|
|
135
|
+
const { value: condition_value, column: condition_column } = element.withCondition[index];
|
|
136
|
+
params.filter[condition_column.column_name] = getParamValue(condition_value.group_key, condition_value.field_key, fieldValues, withDatas);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const response = await withDataFetch(params);
|
|
140
|
+
if (response.code === 0 && response.data.list) {
|
|
141
|
+
withDatas.push({
|
|
142
|
+
id: element.id,
|
|
143
|
+
data: response.data.list
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let formula;
|
|
150
|
+
if (withFill.value && withFill.value.length > 0) {
|
|
151
|
+
formula = withFill.value.map(item => {
|
|
152
|
+
let result = "";
|
|
153
|
+
const { insert, attributes } = item;
|
|
154
|
+
if (typeof insert !== "string") {
|
|
155
|
+
if (insert?.span && attributes && attributes.tagKey && attributes.id) {
|
|
156
|
+
result = getParamValue(attributes.tagKey, attributes.id, fieldValues, withDatas);
|
|
157
|
+
if(result) result = `"${result}"`
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
result = insert;
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
console.log("formula", formula);
|
|
166
|
+
if (formula && formula.length > 0) {
|
|
167
|
+
const childIdentifier = child.props.componentId || child.props.__id;
|
|
168
|
+
const formulaResult = evalFormula(formula);
|
|
169
|
+
console.log("formulaResult", formulaResult);
|
|
170
|
+
console.log("handleFieldsWithFill setRows");
|
|
171
|
+
const newRows = [...rows]
|
|
172
|
+
newRows[rowIndex][childIdentifier] = formulaResult;
|
|
173
|
+
setPrevRows(newRows)
|
|
174
|
+
}
|
|
175
|
+
}, [rows])
|
|
176
|
+
|
|
177
|
+
const getParamValue = useCallback((tagKey, id, fieldValues, withDatas) => {
|
|
178
|
+
let result = "";
|
|
179
|
+
if (tagKey === "fieldsValue") result = fieldValues?.[id] || "";
|
|
180
|
+
else {
|
|
181
|
+
let withData = withDatas.find(item => item.id === tagKey);
|
|
182
|
+
if (withData && withData.data && withData.data.length > 0) {
|
|
183
|
+
result = withData.data[0]?.[id] || "";
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}, []);
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
const handleInputChange = useCallback((rowIndex, childIndex, e) => {
|
|
192
|
+
|
|
193
|
+
const newRows = [...rows];
|
|
194
|
+
newRows[rowIndex] = {
|
|
195
|
+
...newRows[rowIndex],
|
|
196
|
+
[childIndex]: e?.target?.value || '',
|
|
197
|
+
};
|
|
198
|
+
console.log("handleInputChange setRows")
|
|
199
|
+
setPrevRows(newRows);
|
|
200
|
+
|
|
201
|
+
setUpdateField({
|
|
202
|
+
rowIndex: rowIndex,
|
|
203
|
+
identifier: childIndex,
|
|
204
|
+
value: handleRowValues(newRows[rowIndex]),
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
}, [rows, handleFieldsWith, handleRowValues, onChange]);
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
const handleDeleteRow = (rowIndex) => {
|
|
211
|
+
const newRows = [...rows];
|
|
212
|
+
newRows.splice(rowIndex, 1);
|
|
213
|
+
console.log("handleDeleteRow setRows")
|
|
214
|
+
setPrevRows(newRows);
|
|
215
|
+
}
|
|
12
216
|
|
|
13
217
|
const addRow = () => {
|
|
14
|
-
|
|
15
|
-
|
|
218
|
+
console.log("addRow setRows")
|
|
219
|
+
setPrevRows([...rows, {}]);
|
|
220
|
+
}
|
|
16
221
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
}
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
console.log("rows changed rows", JSON.stringify(prevRowsRef.current));
|
|
224
|
+
console.log("rows changed value", JSON.stringify(value));
|
|
225
|
+
if (isEqual(prevRowsRef.current, value)) return;
|
|
226
|
+
console.log("noreq")
|
|
227
|
+
typeof onChange === "function" && onChange(prevRowsRef.current);
|
|
228
|
+
}, [rows]);
|
|
229
|
+
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
if (updateField && updateField.identifier) {
|
|
232
|
+
handleFieldsWith(updateField.identifier, updateField.value, updateField.rowIndex);
|
|
233
|
+
}
|
|
234
|
+
}, [updateField])
|
|
32
235
|
|
|
33
|
-
export default Table
|
|
34
236
|
|
|
35
|
-
|
|
237
|
+
return (
|
|
238
|
+
<>
|
|
239
|
+
<div className="fw-full fmin-h-20 foverflow-x-auto">
|
|
240
|
+
{rows.map((row, rowIndex) => (
|
|
241
|
+
<div className="fborder-b finline-flex fflex-wrap fmin-w-full" style={{ width: "max-content" }} key={rowIndex}>
|
|
242
|
+
{React.Children.map(children, (child, childIndex) => {
|
|
243
|
+
const col_id = child?.props?.__id || childIndex;
|
|
244
|
+
if (row?.[col_id] === undefined) row[col_id] = "";
|
|
245
|
+
return <TableCol width={100} key={`row_${rowIndex}_col_${childIndex}`}>
|
|
246
|
+
{React.cloneElement(child, {
|
|
247
|
+
key: `row_${rowIndex}_child_${childIndex}`,
|
|
248
|
+
subTable: true,
|
|
249
|
+
subTableIndex: rowIndex,
|
|
250
|
+
value: row[col_id] || '',
|
|
251
|
+
onChange: (e) => handleInputChange(rowIndex, col_id, e),
|
|
252
|
+
})}
|
|
253
|
+
</TableCol>
|
|
254
|
+
})}
|
|
255
|
+
<TableAction key={`row_${rowIndex}_action`} subTable={true} subTableIndex={rowIndex} label={"操作"}>
|
|
256
|
+
<DeleteOutlined className="fcursor-pointer" onClick={() => handleDeleteRow(rowIndex)} />
|
|
257
|
+
</TableAction>
|
|
258
|
+
</div>
|
|
259
|
+
))}
|
|
260
|
+
</div>
|
|
261
|
+
<Button onClick={addRow}>新增行</Button>
|
|
262
|
+
</>
|
|
263
|
+
);
|
|
264
|
+
};
|
|
36
265
|
|
|
266
|
+
export default Table;
|
|
267
|
+
export { TableCol, TableAction };
|
|
@@ -49,8 +49,7 @@ const UploadFile = ({ value, maxCount, onChange, ...props }) => {
|
|
|
49
49
|
maxCount={maxCount}
|
|
50
50
|
onChange={handleChange}
|
|
51
51
|
fileList={fileList}>
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
{ !props?.disabled && <div className=" fmin-w-36 fgap-1 frounded fborder-gray-300 fborder hover:fborder-[#3e92f8] hover:ftext-[#3e92f8] fcursor-pointer fh-8 fflex fitems-center fbg-white fjustify-center "><UploadOutlined />点击上传文件</div>}
|
|
54
53
|
</OriginalUpload>
|
|
55
54
|
</BaseWrapper>
|
|
56
55
|
);
|
|
@@ -72,7 +72,6 @@ const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
|
|
72
72
|
|
|
73
73
|
let handleFileList = []
|
|
74
74
|
|
|
75
|
-
console.log("fileMap.current", JSON.parse(JSON.stringify(fileMap.current)))
|
|
76
75
|
for (let i = 0; i < newFileList.length; i++) {
|
|
77
76
|
var file = newFileList[i];
|
|
78
77
|
file.version = new Date().getTime()
|
|
@@ -88,8 +87,6 @@ const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
|
|
88
87
|
handleFileList.push(file)
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
|
-
console.log("newFileList", JSON.parse(JSON.stringify(newFileList)))
|
|
92
|
-
console.log("handleFileList", JSON.parse(JSON.stringify(handleFileList)))
|
|
93
90
|
fileMap.current = handleFileList
|
|
94
91
|
setFileList(handleFileList);
|
|
95
92
|
onChange(handleFileList.map((file) => {
|
|
@@ -152,7 +149,7 @@ const UploadImage = ({ maxCount, value, onChange, ...props }) => {
|
|
|
152
149
|
onPreview={handlePreview}
|
|
153
150
|
onChange={handleChange}
|
|
154
151
|
>
|
|
155
|
-
{fileList.length >= maxCount ? null : uploadButton}
|
|
152
|
+
{fileList.length >= maxCount || props?.disabled ? null : uploadButton}
|
|
156
153
|
</OriginalUpload>
|
|
157
154
|
</div>
|
|
158
155
|
|