目录树优化,解决点击根目录不收起的问题

dev_newshixunModel
hjm 6 years ago
parent 762f4a93c1
commit 6c8e86c8c8

@ -40,8 +40,9 @@ class CodeRepositoryView extends Component {
constructor(props) {
super(props);
this.treeExpanded = false;
this.state = {
autoExpandParent: true,
autoExpandParent: false,
expandedKeys: [],
addtionalSSHArray: [],
@ -52,24 +53,28 @@ class CodeRepositoryView extends Component {
const { game, challenge, hide_code, tabIndex, } = this.props
if ( // 初始化 或者 game切换
challenge.path && challenge.path.length && this.state.expandedKeys.length === 0 ||
!this.treeExpanded && challenge.path && challenge.path.length && this.state.expandedKeys.length === 0 ||
game && (!prevProps.game
|| prevProps.game.identifier !== this.props.game.identifier) ) {
const _path = challenge.multiPath ? challenge.path[0] : challenge.path;
let _ar = [];
const expandedKeys = [];
if (_path) {
_ar = _path.split('/')
_ar.length = _ar.length - 1
_ar.forEach( (item, index) => {
expandedKeys.push( index === 0 ? item : expandedKeys[index - 1] + '/' + item)
if (!this.treeExpanded) {
this.treeExpanded = true
const _path = challenge.multiPath ? challenge.path[0] : challenge.path;
let _ar = [];
const expandedKeys = [];
if (_path) {
_ar = _path.split('/')
_ar.length = _ar.length - 1
_ar.forEach( (item, index) => {
expandedKeys.push( index === 0 ? item : expandedKeys[index - 1] + '/' + item)
})
}
expandedKeys.length = 1 // 没办法做到多级初始化,而且会引起点击其他子目录,加载当前文件目录的问题
// 初始化时无法展开到根节点 https://github.com/fis-components/rc-tree/issues/3
expandedKeys.length && this.setState({
expandedKeys,
})
}
expandedKeys.length = 1 // 没办法做到多级初始化
// 初始化时无法展开到根节点 https://github.com/fis-components/rc-tree/issues/3
expandedKeys.length && this.setState({
expandedKeys,
})
if (game && (!prevProps.game
|| prevProps.game.identifier !== this.props.game.identifier)) {

@ -191,6 +191,10 @@ class CodeRepositoryViewContainer extends Component {
// withCredentials: true,
})
.then((response) => {
// if (!response) {
// resolve && resolve();
// return;
// }
const repoFilesData = this.map2OldData(response.data.trees)
if (!this.state.fileTreeData || this.state.fileTreeData.length === 0) { // 还没树节点,没加载过

Loading…
Cancel
Save