zy-react-library/components/SelectTree/Basic/index.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

import { TreeSelect } from "antd";
import { getTreeNodePaths } from "../../../utils";
function BasicSelectTree(props) {
const {
onSelect,
onGetNodePaths,
onGetNodePathsIsIncludeOneself = true,
placeholder = "",
treeData = [],
nameKey = "name",
idKey = "id",
childrenKey = "childrenList",
2025-11-05 11:25:05 +08:00
formValues,
...restProps
} = props;
const handleSelect = (value, node, extra) => {
if (value.length > 0) {
const parentNodes = getTreeNodePaths({
data: treeData,
targetId: value,
idKey,
childrenKey,
isIncludeOneself: onGetNodePathsIsIncludeOneself
});
onGetNodePaths?.(parentNodes);
}
onSelect?.(value, node, extra);
};
return (
<TreeSelect
showSearch
style={{ width: "100%" }}
styles={{
popup: { root: { maxHeight: 400, overflow: "auto" } },
}}
placeholder={`请选择${placeholder}`}
onSelect={handleSelect}
allowClear
treeData={treeData}
fieldNames={{ label: nameKey, value: idKey, children: childrenKey }}
{...restProps}
/>
);
}
BasicSelectTree.displayName = "BasicSelectTree";
export default BasicSelectTree;