将 Cascader、LeftTree 和 SelectTree 组件中的onGetNodePathsIsIncludeOneself 属性弃用,使用 getNodePathsIsIncludeOneself 属性替代
parent
2b86f53e95
commit
413ebf8489
|
|
@ -11,8 +11,10 @@ export interface BasicCascaderProps extends Omit<CascaderProps, "fieldNames"> {
|
|||
idKey?: string;
|
||||
/** 树形数据 children 字段,默认 children */
|
||||
childrenKey?: string;
|
||||
/** 决定 onGetNodePaths 是否包含自身节点,默认 true */
|
||||
/** @deprecated 已弃用,请使用 getNodePathsIsIncludeOneself */
|
||||
onGetNodePathsIsIncludeOneself?: boolean;
|
||||
/** 决定 onGetNodePaths 是否包含自身节点,默认 true */
|
||||
getNodePathsIsIncludeOneself?: boolean;
|
||||
/** 获取父级节点 */
|
||||
onGetNodePaths?: (nodes: Record<string, any>[]) => void;
|
||||
/** 占位符 */
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ function BasicCascader(props) {
|
|||
onGetData,
|
||||
onChange,
|
||||
onGetNodePaths,
|
||||
onGetNodePathsIsIncludeOneself = true,
|
||||
onGetNodePathsIsIncludeOneself,
|
||||
getNodePathsIsIncludeOneself = true,
|
||||
placeholder = "",
|
||||
data = [],
|
||||
nameKey = "name",
|
||||
|
|
@ -20,6 +21,14 @@ function BasicCascader(props) {
|
|||
...restProps
|
||||
} = props;
|
||||
|
||||
// 如果使用了已弃用的参数给出警告
|
||||
if (onGetNodePathsIsIncludeOneself !== undefined) {
|
||||
console.warn("【BasicCascader】 onGetNodePathsIsIncludeOneself 已弃用,请使用 getNodePathsIsIncludeOneself");
|
||||
}
|
||||
|
||||
// 向后兼容,如果传入了旧参数,使用旧参数
|
||||
const finalGetNodePathsIsIncludeOneself = onGetNodePathsIsIncludeOneself !== undefined ? onGetNodePathsIsIncludeOneself : getNodePathsIsIncludeOneself;
|
||||
|
||||
// 根据 level 处理树数据
|
||||
const processedData = useMemo(() => {
|
||||
return level
|
||||
|
|
@ -34,7 +43,7 @@ function BasicCascader(props) {
|
|||
|
||||
const getNodePaths = (selectedOptions) => {
|
||||
let nodePaths = selectedOptions;
|
||||
if (!onGetNodePathsIsIncludeOneself && selectedOptions) {
|
||||
if (!finalGetNodePathsIsIncludeOneself && selectedOptions) {
|
||||
nodePaths = selectedOptions.slice(0, -1);
|
||||
}
|
||||
return nodePaths || [];
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ export interface BasicLeftTreeProps extends Omit<TreeProps, "fieldNames"> {
|
|||
idKey?: string;
|
||||
/** 树形数据 children 字段,默认 children */
|
||||
childrenKey?: string;
|
||||
/** 决定 onGetNodePaths 是否包含自身节点,默认 true */
|
||||
/** @deprecated 已弃用,请使用 getNodePathsIsIncludeOneself */
|
||||
onGetNodePathsIsIncludeOneself?: boolean;
|
||||
/** 决定 onGetNodePaths 是否包含自身节点,默认 true */
|
||||
getNodePathsIsIncludeOneself?: boolean;
|
||||
/** 获取父级节点 */
|
||||
onGetNodePaths?: () => Record<string, any>[];
|
||||
/** 获取数据 */
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ const BasicLeftTree = (props) => {
|
|||
onGetData,
|
||||
onSelect,
|
||||
onGetNodePaths,
|
||||
onGetNodePathsIsIncludeOneself = true,
|
||||
onGetNodePathsIsIncludeOneself,
|
||||
getNodePathsIsIncludeOneself = true,
|
||||
expandedKeys: externalExpandedKeys,
|
||||
treeData = [],
|
||||
nameKey = "name",
|
||||
|
|
@ -21,6 +22,14 @@ const BasicLeftTree = (props) => {
|
|||
...restProps
|
||||
} = props;
|
||||
|
||||
// 如果使用了已弃用的参数给出警告
|
||||
if (onGetNodePathsIsIncludeOneself !== undefined) {
|
||||
console.warn("【BasicLeftTree】 onGetNodePathsIsIncludeOneself 已弃用,请使用 getNodePathsIsIncludeOneself");
|
||||
}
|
||||
|
||||
// 向后兼容,如果传入了旧参数,使用旧参数
|
||||
const finalGetNodePathsIsIncludeOneself = onGetNodePathsIsIncludeOneself !== undefined ? onGetNodePathsIsIncludeOneself : getNodePathsIsIncludeOneself;
|
||||
|
||||
const [expandedKeys, setExpandedKeys] = useState([]);
|
||||
const [searchValue, setSearchValue] = useState("");
|
||||
const [autoExpandParent, setAutoExpandParent] = useState(true);
|
||||
|
|
@ -81,7 +90,7 @@ const BasicLeftTree = (props) => {
|
|||
targetId: selectedNodeId,
|
||||
idKey,
|
||||
childrenKey,
|
||||
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
||||
isIncludeOneself: finalGetNodePathsIsIncludeOneself,
|
||||
});
|
||||
onGetNodePaths?.(parentNodes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ export interface BasicSelectTreeProps extends Omit<TreeSelectProps, "fieldNames"
|
|||
idKey?: string;
|
||||
/** 树形数据 children 字段,默认 children */
|
||||
childrenKey?: string;
|
||||
/** 决定 onGetNodePaths 是否包含自身节点,默认 true */
|
||||
/** @deprecated 已弃用,请使用 getNodePathsIsIncludeOneself */
|
||||
onGetNodePathsIsIncludeOneself?: boolean;
|
||||
/** 决定 onGetNodePaths 是否包含自身节点,默认 true */
|
||||
getNodePathsIsIncludeOneself?: boolean;
|
||||
/** 获取父级节点 */
|
||||
onGetNodePaths?: (nodes: Record<string, any>[]) => void;
|
||||
/** 占位符 */
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ function BasicSelectTree(props) {
|
|||
onChange,
|
||||
onGetLabel,
|
||||
onGetNodePaths,
|
||||
onGetNodePathsIsIncludeOneself = true,
|
||||
onGetNodePathsIsIncludeOneself,
|
||||
getNodePathsIsIncludeOneself = true,
|
||||
placeholder = "",
|
||||
treeData = [],
|
||||
nameKey = "name",
|
||||
|
|
@ -22,6 +23,14 @@ function BasicSelectTree(props) {
|
|||
...restProps
|
||||
} = props;
|
||||
|
||||
// 如果使用了已弃用的参数给出警告
|
||||
if (onGetNodePathsIsIncludeOneself !== undefined) {
|
||||
console.warn("【BasicSelectTree】 onGetNodePathsIsIncludeOneself 已弃用,请使用 getNodePathsIsIncludeOneself");
|
||||
}
|
||||
|
||||
// 向后兼容,如果传入了旧参数,使用旧参数
|
||||
const finalGetNodePathsIsIncludeOneself = onGetNodePathsIsIncludeOneself !== undefined ? onGetNodePathsIsIncludeOneself : getNodePathsIsIncludeOneself;
|
||||
|
||||
const processedTreeData = useMemo(() => {
|
||||
// 根据 level 处理树数据
|
||||
let result = level
|
||||
|
|
@ -55,7 +64,7 @@ function BasicSelectTree(props) {
|
|||
targetId,
|
||||
idKey,
|
||||
childrenKey,
|
||||
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
||||
isIncludeOneself: finalGetNodePathsIsIncludeOneself,
|
||||
});
|
||||
parentNodes.push(...currentParentNodes);
|
||||
}
|
||||
|
|
@ -72,7 +81,7 @@ function BasicSelectTree(props) {
|
|||
targetId,
|
||||
idKey,
|
||||
childrenKey,
|
||||
isIncludeOneself: onGetNodePathsIsIncludeOneself,
|
||||
isIncludeOneself: finalGetNodePathsIsIncludeOneself,
|
||||
});
|
||||
onGetNodePaths?.(parentNodes);
|
||||
onGetLabel?.(parentNodes[parentNodes.length - 1][nameKey]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue