Compare commits

...

2 Commits

Author SHA1 Message Date
LiuJiaNan 80f4528a88 优化Select、SelectTree、Cascader 2025-11-06 16:28:49 +08:00
LiuJiaNan 25626ef1c0 1.0.55 2025-11-06 16:02:56 +08:00
6 changed files with 20 additions and 19 deletions

View File

@ -33,7 +33,7 @@ function BasicCascader(props) {
if (!onGetNodePathsIsIncludeOneself && selectedOptions) { if (!onGetNodePathsIsIncludeOneself && selectedOptions) {
nodePaths = selectedOptions.slice(0, -1); nodePaths = selectedOptions.slice(0, -1);
} }
return nodePaths; return nodePaths || [];
}; };
const handleChange = (value, selectedOptions) => { const handleChange = (value, selectedOptions) => {

View File

@ -13,6 +13,8 @@ export interface BasicSelectProps extends SelectProps {
idKey?: string; idKey?: string;
/** 占位符 */ /** 占位符 */
placeholder?: string; placeholder?: string;
/** 获取 label */
onGetLabel?: (label: string) => void;
} }
/** /**

View File

@ -14,23 +14,14 @@ function BasicSelect(props) {
...restProps ...restProps
} = props; } = props;
// const handleSelect = (event) => {
// onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
// };
//
// const handleClear = () => {
// onGetLabel?.(undefined);
// };
const handleChange = (event) => { const handleChange = (event) => {
if (event) if (event)
onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey })); onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey }));
else else
onGetLabel?.(undefined); onGetLabel?.("");
} };
return ( return (
// <Select placeholder={`请选择${placeholder}`} showSearch allowClear onClear={handleClear} onSelect={handleSelect} {...restProps}>
<Select placeholder={`请选择${placeholder}`} showSearch allowClear onChange={handleChange} {...restProps}> <Select placeholder={`请选择${placeholder}`} showSearch allowClear onChange={handleChange} {...restProps}>
{data.map((item) => { {data.map((item) => {
const value = item[idKey]; const value = item[idKey];

View File

@ -19,6 +19,8 @@ export interface BasicSelectTreeProps extends TreeSelectProps {
placeholder?: string; placeholder?: string;
/** 控制只能选择到第几级 */ /** 控制只能选择到第几级 */
level?: number; level?: number;
/** 获取 label */
onGetLabel?: (label: string) => void;
} }
/** /**
@ -26,4 +28,4 @@ export interface BasicSelectTreeProps extends TreeSelectProps {
*/ */
declare const BasicSelectTree: FC<BasicSelectTreeProps>; declare const BasicSelectTree: FC<BasicSelectTreeProps>;
export default BasicSelectTree; export default BasicSelectTree;

View File

@ -6,7 +6,8 @@ import { getTreeNodePaths, processTreeDataByLevel } from "../../../utils";
*/ */
function BasicSelectTree(props) { function BasicSelectTree(props) {
const { const {
onSelect, onChange,
onGetLabel,
onGetNodePaths, onGetNodePaths,
onGetNodePathsIsIncludeOneself = true, onGetNodePathsIsIncludeOneself = true,
placeholder = "", placeholder = "",
@ -28,8 +29,8 @@ function BasicSelectTree(props) {
}) })
: treeData; : treeData;
const handleSelect = (value, node, extra) => { const handleChange = (value, label, extra) => {
if (value.length > 0) { if (value) {
const parentNodes = getTreeNodePaths({ const parentNodes = getTreeNodePaths({
data: treeData, data: treeData,
targetId: value, targetId: value,
@ -38,8 +39,13 @@ function BasicSelectTree(props) {
isIncludeOneself: onGetNodePathsIsIncludeOneself, isIncludeOneself: onGetNodePathsIsIncludeOneself,
}); });
onGetNodePaths?.(parentNodes); onGetNodePaths?.(parentNodes);
onGetLabel?.(parentNodes[parentNodes.length - 1][nameKey]);
} }
onSelect?.(value, node, extra); else {
onGetNodePaths?.([]);
onGetLabel?.("");
}
onChange?.(value, label, extra);
}; };
return ( return (
@ -50,7 +56,7 @@ function BasicSelectTree(props) {
popup: { root: { maxHeight: 400, overflow: "auto" } }, popup: { root: { maxHeight: 400, overflow: "auto" } },
}} }}
placeholder={`请选择${placeholder}`} placeholder={`请选择${placeholder}`}
onSelect={handleSelect} onChange={handleChange}
allowClear allowClear
treeData={processedTreeData} treeData={processedTreeData}
fieldNames={{ label: nameKey, value: idKey, children: childrenKey }} fieldNames={{ label: nameKey, value: idKey, children: childrenKey }}

View File

@ -1,7 +1,7 @@
{ {
"name": "zy-react-library", "name": "zy-react-library",
"private": false, "private": false,
"version": "1.0.54", "version": "1.0.55",
"type": "module", "type": "module",
"description": "", "description": "",
"author": "LiuJiaNan", "author": "LiuJiaNan",