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