diff --git a/components/tree/DirectoryTree.tsx b/components/tree/DirectoryTree.tsx index 13c0d758cc07..4f6064b3c477 100644 --- a/components/tree/DirectoryTree.tsx +++ b/components/tree/DirectoryTree.tsx @@ -3,7 +3,7 @@ import classNames from 'classnames'; import omit from 'omit.js'; import debounce from 'lodash/debounce'; import { conductExpandParent } from 'rc-tree/lib/util'; -import { EventDataNode, DataNode } from 'rc-tree/lib/interface'; +import { EventDataNode, DataNode, Key } from 'rc-tree/lib/interface'; import { convertDataToEntities, convertTreeToData } from 'rc-tree/lib/utils/treeUtil'; import FileOutlined from '@ant-design/icons/FileOutlined'; import FolderOpenOutlined from '@ant-design/icons/FolderOpenOutlined'; @@ -20,8 +20,8 @@ export interface DirectoryTreeProps extends TreeProps { } export interface DirectoryTreeState { - expandedKeys?: string[]; - selectedKeys?: string[]; + expandedKeys?: Key[]; + selectedKeys?: Key[]; } function getIcon(props: AntdTreeNodeAttribute): React.ReactNode { @@ -60,9 +60,9 @@ class DirectoryTree extends React.Component, node: EventDataNode) => void; // Shift click usage - lastSelectedKey?: string; + lastSelectedKey?: Key; - cachedSelectedKeys?: string[]; + cachedSelectedKeys?: Key[]; constructor(props: DirectoryTreeProps) { super(props); @@ -93,7 +93,7 @@ class DirectoryTree extends React.Component; @@ -109,21 +109,21 @@ export interface TreeProps extends Omit { /** 默认展开对应树节点 */ defaultExpandParent?: boolean; /** 默认展开指定的树节点 */ - defaultExpandedKeys?: string[]; + defaultExpandedKeys?: Key[]; /** (受控)展开指定的树节点 */ - expandedKeys?: string[]; + expandedKeys?: Key[]; /** (受控)选中复选框的树节点 */ - checkedKeys?: string[] | { checked: string[]; halfChecked: string[] }; + checkedKeys?: Key[] | { checked: Key[]; halfChecked: Key[] }; /** 默认选中复选框的树节点 */ - defaultCheckedKeys?: string[]; + defaultCheckedKeys?: Key[]; /** (受控)设置选中的树节点 */ - selectedKeys?: string[]; + selectedKeys?: Key[]; /** 默认选中的树节点 */ - defaultSelectedKeys?: string[]; + defaultSelectedKeys?: Key[]; selectable?: boolean; /** 点击树节点触发 */ filterAntTreeNode?: (node: AntTreeNode) => boolean; - loadedKeys?: string[]; + loadedKeys?: Key[]; /** 设置节点可拖拽(IE>8) */ draggable?: boolean; style?: React.CSSProperties; diff --git a/components/tree/utils/dictUtil.ts b/components/tree/utils/dictUtil.ts index d8a587bc87bb..2922b30af0bf 100644 --- a/components/tree/utils/dictUtil.ts +++ b/components/tree/utils/dictUtil.ts @@ -1,4 +1,4 @@ -import { DataNode } from 'rc-tree/lib/interface'; +import { DataNode, Key } from 'rc-tree/lib/interface'; enum Record { None, @@ -8,7 +8,7 @@ enum Record { function traverseNodesKey( treeData: DataNode[], - callback: (key: string | number | null, node: DataNode) => boolean, + callback: (key: Key | number | null, node: DataNode) => boolean, ) { function processNode(dataNode: DataNode) { const { key, children } = dataNode; @@ -23,11 +23,11 @@ function traverseNodesKey( /** 计算选中范围,只考虑expanded情况以优化性能 */ export function calcRangeKeys( treeData: DataNode[], - expandedKeys: string[], - startKey?: string, - endKey?: string, -): string[] { - const keys: string[] = []; + expandedKeys: Key[], + startKey?: Key, + endKey?: Key, +): Key[] { + const keys: Key[] = []; let record: Record = Record.None; if (startKey && startKey === endKey) { @@ -37,11 +37,11 @@ export function calcRangeKeys( return []; } - function matchKey(key: string) { + function matchKey(key: Key) { return key === startKey || key === endKey; } - traverseNodesKey(treeData, (key: string) => { + traverseNodesKey(treeData, (key: Key) => { if (record === Record.End) { return false; } @@ -71,10 +71,10 @@ export function calcRangeKeys( return keys; } -export function convertDirectoryKeysToNodes(treeData: DataNode[], keys: string[]) { - const restKeys: string[] = [...keys]; +export function convertDirectoryKeysToNodes(treeData: DataNode[], keys: Key[]) { + const restKeys: Key[] = [...keys]; const nodes: DataNode[] = []; - traverseNodesKey(treeData, (key: string, node: DataNode) => { + traverseNodesKey(treeData, (key: Key, node: DataNode) => { const index = restKeys.indexOf(key); if (index !== -1) { nodes.push(node);