import CommonHead from '@/components/CommonHead' import FloatDarkModeButton from './components/FloatDarkModeButton' import Footer from './components/Footer' import JumpToBottomButton from './components/JumpToBottomButton' import JumpToTopButton from './components/JumpToTopButton' import LoadingCover from './components/LoadingCover' import SideAreaLeft from './components/SideAreaLeft' import SideAreaRight from './components/SideAreaRight' import TopNav from './components/TopNav' import { useGlobal } from '@/lib/global' import PropTypes from 'prop-types' import React from 'react' import smoothscroll from 'smoothscroll-polyfill' import CONFIG_NEXT from './config_next' import Live2D from '@/components/Live2D' /** * 基础布局 采用左右两侧布局,移动端使用顶部导航栏 * @returns {JSX.Element} * @constructor */ const LayoutBase = (props) => { const { children, headerSlot, meta, sideBarSlot, floatSlot, rightAreaSlot, siteInfo } = props const { onLoading } = useGlobal() const targetRef = React.useRef(null) const floatButtonGroup = React.useRef(null) const leftAreaSlot = const [show, switchShow] = React.useState(false) const [percent, changePercent] = React.useState(0) // 页面阅读百分比 const scrollListener = () => { 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 !== show) { switchShow(shouldShow) } changePercent(per) } React.useEffect(() => { smoothscroll.polyfill() // facebook messenger 插件需要调整右下角悬浮按钮的高度 const fb = document.getElementsByClassName('fb-customerchat') if (fb.length === 0) { floatButtonGroup?.current?.classList.replace('bottom-24', 'bottom-12') } else { floatButtonGroup?.current?.classList.replace('bottom-12', 'bottom-24') } document.addEventListener('scroll', scrollListener) return () => document.removeEventListener('scroll', scrollListener) }, [show]) return (<> <>{headerSlot}
{/* 左侧栏样式 */}
{onLoading ? : <> {children} }
{/* 右侧栏样式 */} { CONFIG_NEXT.RIGHT_BAR && }
{/* 右下角悬浮 */}
{floatSlot}