import CommonHead from '@/components/CommonHead' import { useCallback, useEffect, useState } from 'react' import throttle from 'lodash.throttle' import Footer from './components/Footer' import JumpToTopButton from './components/JumpToTopButton' import SideRight from './components/SideRight' import TopNav from './components/TopNav' import FloatDarkModeButton from './components/FloatDarkModeButton' import Live2D from '@/components/Live2D' import LoadingCover from './components/LoadingCover' import { useGlobal } from '@/lib/global' import BLOG from '@/blog.config' import dynamic from 'next/dynamic' const FacebookPage = dynamic( () => { let facebook = <> try { facebook = import('@/components/FacebookPage') } catch (err) { console.error(err) } return facebook }, { ssr: false } ) /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 * @param props * @returns {JSX.Element} * @constructor */ const LayoutBase = props => { const { children, headerSlot, floatSlot, meta, siteInfo } = props const [showFloatButton, switchShow] = useState(false) // const [percent, changePercent] = useState(0) // 页面阅读百分比 const rightAreaSlot = ( <> ) const { onLoading } = useGlobal() const throttleMs = 200 const scrollListener = useCallback(throttle(() => { const targetRef = document.getElementById('wrapper') const clientHeight = targetRef?.clientHeight const scrollY = window.pageYOffset const fullHeight = clientHeight - window.outerHeight let per = parseFloat(((scrollY / fullHeight) * 100).toFixed(0)) if (per > 100) per = 100 const shouldShow = scrollY > 100 && per > 0 if (shouldShow !== showFloatButton) { switchShow(shouldShow) } }, throttleMs)) useEffect(() => { document.addEventListener('scroll', scrollListener) return () => document.removeEventListener('scroll', scrollListener) }, []) return (
{headerSlot}
{onLoading ? : children}
{/* 右下角悬浮 */}
{floatSlot}
) } export default LayoutBase