diff --git a/public/react/src/modules/page/VNCContainer.js b/public/react/src/modules/page/VNCContainer.js index 3a85976bb..6ef10888a 100644 --- a/public/react/src/modules/page/VNCContainer.js +++ b/public/react/src/modules/page/VNCContainer.js @@ -85,7 +85,7 @@ class VNCContainer extends Component { }) } onTreeSelect = (selectedKeys, info) => { - const isLeaf = info.node.props.isLeaf; + const isLeaf = info.node.isLeaf(); if (isLeaf) { // 叶子节点 selectedKeys.length && this.setState({ fileTreeSelectedKeys: selectedKeys diff --git a/public/react/src/modules/page/component/repo/RepoTree.js b/public/react/src/modules/page/component/repo/RepoTree.js index fbf1286c3..102f797ef 100644 --- a/public/react/src/modules/page/component/repo/RepoTree.js +++ b/public/react/src/modules/page/component/repo/RepoTree.js @@ -7,7 +7,7 @@ import 'rc-tree/assets/index.css'; const $ = window.$; export default function RepoTree(props) { - const { fileTreeData, onLoadData, onTreeSelect, fileTreeSelectedKeys, loadRepoFiles } = props; + const { fileTreeData, onLoadData, fileTreeSelectedKeys, loadRepoFiles } = props; const [expandedKeys, setExpandedKeys] = useState([]) useEffect(() => { loadRepoFiles() @@ -36,7 +36,19 @@ export default function RepoTree(props) { }; const treeNodes = loop(fileTreeData); - + function onTreeSelect(selectedKeys, info) { + if (!info.node.isLeaf()) { + const _expandedKeys = expandedKeys.slice(0) + const _index = _expandedKeys.indexOf(selectedKeys[0]); + if (_index == -1) { + _expandedKeys.push(selectedKeys[0]) + } else { + _expandedKeys.splice( _index, 1) + } + setExpandedKeys( _expandedKeys ) + } + props.onTreeSelect(selectedKeys, info) + } // selectable={false} return ( { + if (!info.node.isLeaf()) { + const expandedKeys = this.state.expandedKeys.slice(0) + const _index = expandedKeys.indexOf(selectedKeys[0]); + if (_index == -1) { + expandedKeys.push(selectedKeys[0]) + } else { + expandedKeys.splice( _index, 1) + } + this.setState({ expandedKeys }) + } + + this.props.onTreeSelect(selectedKeys, info) + } buildTree() { // TODO http://localhost:3007/tasks/xgffnuomytpj 这个实训没有文件树 - const { fileTreeData, onLoadData, onTreeSelect, fileTreeSelectedKeys } = this.props; + const { fileTreeData, onLoadData, fileTreeSelectedKeys } = this.props; if (!fileTreeData || fileTreeData.length === 0) { return "" } @@ -136,7 +150,7 @@ class CodeRepositoryView extends Component { return ( { - const isLeaf = info.node.props.isLeaf; + const isLeaf = info.node.isLeaf(); if (isLeaf) { // 叶子节点 selectedKeys.length && this.setState({ fileTreeSelectedKeys: selectedKeys