import { useGlobal } from '@/lib/global' import { useState } from 'react' import { Draggable } from './Draggable' import { THEMES } from '@/themes/theme' import { useRouter } from 'next/router' import DarkModeButton from './DarkModeButton' import { getQueryParam } from '@/lib/utils' import LANGS from '@/lib/lang' /** * * @returns 主题切换 */ const ThemeSwitch = () => { const { theme, lang, changeLang, locale, isDarkMode, toggleDarkMode } = useGlobal() const router = useRouter() const currentTheme = getQueryParam(router.asPath, 'theme') || theme // const currentLang = getQueryParam(router.asPath, 'lang') || lang const [isLoading, setIsLoading] = useState(false) // 修改当前路径url中的 theme 参数 // 例如 http://localhost?theme=hexo 跳转到 http://localhost?theme=newTheme const onThemeSelectChange = (e) => { document.ontouchmove = document.ontouchend = document.onmousemove = document.onmouseup = null setIsLoading(true) const newTheme = e.target.value const query = router.query query.theme = newTheme router.push({ pathname: router.pathname, query }).then(() => { setTimeout(() => { setIsLoading(false) }, 500); }) } const onLangSelectChange = (e) => { document.ontouchmove = document.ontouchend = document.onmousemove = document.onmouseup = null const newLang = e.target.value changeLang(newLang) } return (<>
{/* 深色按钮 */}
{isDarkMode ? locale.MENU.DARK_MODE : locale.MENU.LIGHT_MODE}
{/* 翻译按钮 */}
{/* 主题切换按钮 */}
{/* 切换主题加载时的全屏遮罩 */}
) } export default ThemeSwitch