优化右侧导航显示

This commit is contained in:
谢思 2023-07-20 10:35:55 +08:00
parent 108fc75a76
commit 9452296dea
1 changed files with 24 additions and 5 deletions

View File

@ -23,7 +23,6 @@ function ProjectSource(props) {
const [autoExpandParent, setAutoExpandParent] = useState(false);
const [searchValue, setSearchValue] = useState("");
const [wikiContMenu, setWikiContMenu] = useState(undefined);
const [container, setContainer] = useState(undefined);
const { temp, history, data, adminUrl } = props;
let scroller = undefined;
@ -112,6 +111,7 @@ function ProjectSource(props) {
}, [wikiDetail])
useEffect(() =>{
//
const handleClick = (event) => {
let target = event.target;
if (target.tagName.toUpperCase() === 'A') {
@ -127,9 +127,29 @@ function ProjectSource(props) {
}
}
};
//
const scroll = () =>{
var element = document.getElementById('wikiContMenuBox');
var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
var scrollHeight = document.documentElement.scrollHeight||document.body.scrollHeight;
if(scrollHeight-scrollTop <= windowHeight*1.2){
const maxElementHeight = (scrollHeight-scrollTop)/2-200;
element && (element.style.maxHeight = maxElementHeight + 'px');
}else if(scrollHeight-scrollTop <= windowHeight*1.5){
const maxElementHeight = (scrollHeight-scrollTop)/2-100;
element && (element.style.maxHeight = maxElementHeight + 'px');
}else{
element && (element.style.maxHeight = '80vh');
}
}
document.addEventListener("click", handleClick);
document.addEventListener("scroll", scroll);
return () => {
document.removeEventListener("click", handleClick);
document.removeEventListener("scroll", scroll);
};
}, [])
@ -191,7 +211,7 @@ function ProjectSource(props) {
<p className="in_title mb30">{data && data.helperTitle}</p>
<Spin spinning={loading}>
{
wikiList && (wikiList.length > 0 ? <Box className='zoneHelpBox' ref={node =>{setContainer(node)}}>
wikiList && (wikiList.length > 0 ? <Box className='zoneHelpBox'>
{/* wiki目录导航 */}
<div className='leftMenuHC mr20'>
<Search
@ -217,9 +237,8 @@ function ProjectSource(props) {
</FlexAJ>
{wikiDetail.md_content && <RenderHtml className="wikiContentHC editor-content-panel mt20" value={ Base64.decode(wikiDetail.md_content) } url={history.location}/>}
</LongWidth>
{/* target={() => container} */}
{wikiContMenu && wikiContMenu !== "<ul></ul>" && <Affix offsetTop={0}>
<div className='wikiContMenuBox font-15' dangerouslySetInnerHTML={{ __html: wikiContMenu }}></div>
{wikiContMenu && wikiContMenu !== "<ul></ul>" && <Affix offsetTop={80}>
<div id="wikiContMenuBox" className='wikiContMenuBox font-15' dangerouslySetInnerHTML={{ __html: wikiContMenu }}></div>
</Affix>}
</Box>
</LongWidth>}