forked from Gitlink/forgeplus-react
优化目录展开
This commit is contained in:
parent
b9efd5e6ce
commit
10b6d1f09c
|
@ -8,6 +8,7 @@ import { findFirstWiki, generateList, getParentKey, getWiki, parseSidebar, wikiP
|
|||
import RenderHtml from '../../../components/render-html';
|
||||
import { Base64 } from 'js-base64';
|
||||
import { getTocContent } from '../../../common/marked';
|
||||
import { splitAndCombine } from '../../Wiki/utils';
|
||||
|
||||
const { Search } = Input;
|
||||
const { DirectoryTree, TreeNode } = Tree;
|
||||
|
@ -47,7 +48,7 @@ function ProjectSource(props) {
|
|||
// 默认打开第一个wiki
|
||||
const firstWiki = findFirstWiki(menuList);
|
||||
if(firstWiki){
|
||||
setExpandedKeys([getParentKey(firstWiki.key, menuList)+"", firstWiki.key+""]);
|
||||
setExpandedKeys(splitAndCombine(firstWiki.key+""));
|
||||
setWiki(firstWiki);
|
||||
}
|
||||
setFlattenedMenuList(generateList(menuList));
|
||||
|
@ -164,7 +165,7 @@ function ProjectSource(props) {
|
|||
return null;
|
||||
}).filter((item, i, self) => item && self.indexOf(item) === i);
|
||||
setSearchValue(va);
|
||||
setExpandedKeys(expandedKeys);
|
||||
setExpandedKeys(splitAndCombine(expandedKeys[0]));
|
||||
} else {
|
||||
setSearchValue("");
|
||||
}
|
||||
|
|
|
@ -5,4 +5,20 @@ export function splicingTabs(count) {
|
|||
tabs += "\t";
|
||||
}
|
||||
return tabs;
|
||||
}
|
||||
|
||||
// 输入:'2-2-2-1' 返回:['2', '2-2', '2-2-2', '2-2-2-1']
|
||||
export function splitAndCombine(str) {
|
||||
if(!str) return []
|
||||
var parts = str.split('-');
|
||||
var result = parts.reduce(function(acc, curr) {
|
||||
if (acc.length === 0) {
|
||||
acc.push(curr);
|
||||
} else {
|
||||
var lastItem = acc[acc.length - 1];
|
||||
acc.push(lastItem + '-' + curr);
|
||||
}
|
||||
return acc;
|
||||
}, []);
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue