zy-react-library 1.0.156 → 1.0.158
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.
|
@@ -208,7 +208,7 @@ const FormItemsRenderer = ({
|
|
|
208
208
|
|
|
209
209
|
// 列数
|
|
210
210
|
const getCol = (option) => {
|
|
211
|
-
const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : option.span ?? span;
|
|
211
|
+
const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : (option.span ?? span);
|
|
212
212
|
const itemLabelCol = option.labelCol ?? (itemSpan === 24 ? { span: labelCol.span / 2 } : labelCol);
|
|
213
213
|
const itemWrapperCol = option.wrapperCol ?? { span: 24 - itemLabelCol.span };
|
|
214
214
|
return { span: itemSpan, labelCol: itemLabelCol, wrapperCol: itemWrapperCol };
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { TreeSelect } from "antd";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { arrayObjectDeduplication, getDataType, getTreeNodePaths, processTreeDataByLevel, processTreeDataForOnlyLastLevel } from "../../../utils";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 基础下拉树组件(不建议直接使用此组件,二次继承使用)
|
|
7
|
-
*/
|
|
8
|
-
function BasicSelectTree(props) {
|
|
9
|
-
const {
|
|
10
|
-
onGetData,
|
|
11
|
-
onChange,
|
|
12
|
-
onGetLabel,
|
|
13
|
-
onGetNodePaths,
|
|
14
|
-
onGetNodePathsIsIncludeOneself = true,
|
|
15
|
-
placeholder = "",
|
|
16
|
-
treeData = [],
|
|
17
|
-
nameKey = "name",
|
|
18
|
-
idKey = "id",
|
|
19
|
-
childrenKey = "children",
|
|
20
|
-
level,
|
|
21
|
-
onlyLastLevel = false,
|
|
22
|
-
...restProps
|
|
23
|
-
} = props;
|
|
24
|
-
|
|
25
|
-
// 根据 level 处理树数据
|
|
26
|
-
let processedTreeData = level
|
|
27
|
-
? processTreeDataByLevel({
|
|
28
|
-
data: treeData,
|
|
29
|
-
level,
|
|
30
|
-
childrenKey,
|
|
31
|
-
currentLevel: 1,
|
|
32
|
-
})
|
|
33
|
-
: treeData;
|
|
34
|
-
|
|
35
|
-
// 根据 onlyLastLevel 处理树数据
|
|
36
|
-
processedTreeData = processTreeDataForOnlyLastLevel({ data: processedTreeData, childrenKey, onlyLastLevel });
|
|
37
|
-
|
|
38
|
-
const handleChange = (value, label, extra) => {
|
|
39
|
-
if (value) {
|
|
40
|
-
if (getDataType(value) === "Array") {
|
|
41
|
-
const parentNodes = [];
|
|
42
|
-
for (let i = 0; i < value.length; i++) {
|
|
43
|
-
const targetId = (restProps.labelInValue || restProps.treeCheckStrictly) ? value[i].value : value[i];
|
|
44
|
-
const currentParentNodes = getTreeNodePaths({
|
|
45
|
-
data: treeData,
|
|
46
|
-
targetId,
|
|
47
|
-
idKey,
|
|
48
|
-
childrenKey,
|
|
49
|
-
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
|
50
|
-
});
|
|
51
|
-
parentNodes.push(...currentParentNodes);
|
|
52
|
-
}
|
|
53
|
-
const deduplicationParentNodes = arrayObjectDeduplication(parentNodes, idKey);
|
|
54
|
-
onGetNodePaths?.(deduplicationParentNodes);
|
|
55
|
-
onGetLabel?.((restProps.labelInValue || restProps.treeCheckStrictly) ? value.map(item => item.label) : label);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const targetId = (restProps.labelInValue || restProps.treeCheckStrictly) ? value.value : value;
|
|
59
|
-
const parentNodes = getTreeNodePaths({
|
|
60
|
-
data: treeData,
|
|
61
|
-
targetId,
|
|
62
|
-
idKey,
|
|
63
|
-
childrenKey,
|
|
64
|
-
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
|
65
|
-
});
|
|
66
|
-
onGetNodePaths?.(parentNodes);
|
|
67
|
-
onGetLabel?.(parentNodes[parentNodes.length - 1][nameKey]);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
onGetNodePaths?.([]);
|
|
72
|
-
onGetLabel?.("");
|
|
73
|
-
}
|
|
74
|
-
onChange?.((restProps.labelInValue || restProps.treeCheckStrictly) ? value.map(item => item.value) : value, label, extra);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
onGetData?.(treeData, processedTreeData);
|
|
79
|
-
}, [treeData, processedTreeData]);
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<TreeSelect
|
|
83
|
-
showSearch
|
|
84
|
-
style={{ width: "100%" }}
|
|
85
|
-
styles={{
|
|
86
|
-
popup: { root: { maxHeight: 400, overflow: "auto" } },
|
|
87
|
-
}}
|
|
88
|
-
placeholder={`请选择${placeholder}`}
|
|
89
|
-
onChange={handleChange}
|
|
90
|
-
allowClear
|
|
91
|
-
treeData={processedTreeData}
|
|
92
|
-
fieldNames={{ label: nameKey, value: idKey, children: childrenKey }}
|
|
93
|
-
treeNodeFilterProp={nameKey}
|
|
94
|
-
showCheckedStrategy={TreeSelect.SHOW_ALL}
|
|
95
|
-
{...restProps}
|
|
96
|
-
/>
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
BasicSelectTree.displayName = "BasicSelectTree";
|
|
101
|
-
|
|
102
|
-
export default BasicSelectTree;
|
|
1
|
+
import { TreeSelect } from "antd";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { arrayObjectDeduplication, getDataType, getTreeNodePaths, processTreeDataByLevel, processTreeDataForOnlyLastLevel } from "../../../utils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 基础下拉树组件(不建议直接使用此组件,二次继承使用)
|
|
7
|
+
*/
|
|
8
|
+
function BasicSelectTree(props) {
|
|
9
|
+
const {
|
|
10
|
+
onGetData,
|
|
11
|
+
onChange,
|
|
12
|
+
onGetLabel,
|
|
13
|
+
onGetNodePaths,
|
|
14
|
+
onGetNodePathsIsIncludeOneself = true,
|
|
15
|
+
placeholder = "",
|
|
16
|
+
treeData = [],
|
|
17
|
+
nameKey = "name",
|
|
18
|
+
idKey = "id",
|
|
19
|
+
childrenKey = "children",
|
|
20
|
+
level,
|
|
21
|
+
onlyLastLevel = false,
|
|
22
|
+
...restProps
|
|
23
|
+
} = props;
|
|
24
|
+
|
|
25
|
+
// 根据 level 处理树数据
|
|
26
|
+
let processedTreeData = level
|
|
27
|
+
? processTreeDataByLevel({
|
|
28
|
+
data: treeData,
|
|
29
|
+
level,
|
|
30
|
+
childrenKey,
|
|
31
|
+
currentLevel: 1,
|
|
32
|
+
})
|
|
33
|
+
: treeData;
|
|
34
|
+
|
|
35
|
+
// 根据 onlyLastLevel 处理树数据
|
|
36
|
+
processedTreeData = processTreeDataForOnlyLastLevel({ data: processedTreeData, childrenKey, onlyLastLevel });
|
|
37
|
+
|
|
38
|
+
const handleChange = (value, label, extra) => {
|
|
39
|
+
if (value) {
|
|
40
|
+
if (getDataType(value) === "Array") {
|
|
41
|
+
const parentNodes = [];
|
|
42
|
+
for (let i = 0; i < value.length; i++) {
|
|
43
|
+
const targetId = (restProps.labelInValue || restProps.treeCheckStrictly) ? value[i].value : value[i];
|
|
44
|
+
const currentParentNodes = getTreeNodePaths({
|
|
45
|
+
data: treeData,
|
|
46
|
+
targetId,
|
|
47
|
+
idKey,
|
|
48
|
+
childrenKey,
|
|
49
|
+
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
|
50
|
+
});
|
|
51
|
+
parentNodes.push(...currentParentNodes);
|
|
52
|
+
}
|
|
53
|
+
const deduplicationParentNodes = arrayObjectDeduplication(parentNodes, idKey);
|
|
54
|
+
onGetNodePaths?.(deduplicationParentNodes);
|
|
55
|
+
onGetLabel?.((restProps.labelInValue || restProps.treeCheckStrictly) ? value.map(item => item.label) : label);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const targetId = (restProps.labelInValue || restProps.treeCheckStrictly) ? value.value : value;
|
|
59
|
+
const parentNodes = getTreeNodePaths({
|
|
60
|
+
data: treeData,
|
|
61
|
+
targetId,
|
|
62
|
+
idKey,
|
|
63
|
+
childrenKey,
|
|
64
|
+
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
|
65
|
+
});
|
|
66
|
+
onGetNodePaths?.(parentNodes);
|
|
67
|
+
onGetLabel?.(parentNodes[parentNodes.length - 1][nameKey]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
onGetNodePaths?.([]);
|
|
72
|
+
onGetLabel?.("");
|
|
73
|
+
}
|
|
74
|
+
onChange?.((restProps.labelInValue || restProps.treeCheckStrictly) ? value.map(item => item.value) : value, label, extra);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
onGetData?.(treeData, processedTreeData);
|
|
79
|
+
}, [treeData, processedTreeData]);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<TreeSelect
|
|
83
|
+
showSearch
|
|
84
|
+
style={{ width: "100%" }}
|
|
85
|
+
styles={{
|
|
86
|
+
popup: { root: { maxHeight: 400, overflow: "auto" } },
|
|
87
|
+
}}
|
|
88
|
+
placeholder={`请选择${placeholder}`}
|
|
89
|
+
onChange={handleChange}
|
|
90
|
+
allowClear
|
|
91
|
+
treeData={processedTreeData}
|
|
92
|
+
fieldNames={{ label: nameKey, value: idKey, children: childrenKey }}
|
|
93
|
+
treeNodeFilterProp={nameKey}
|
|
94
|
+
showCheckedStrategy={TreeSelect.SHOW_ALL}
|
|
95
|
+
{...restProps}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
BasicSelectTree.displayName = "BasicSelectTree";
|
|
101
|
+
|
|
102
|
+
export default BasicSelectTree;
|