diff --git a/components/CusdisComponent.js b/components/CusdisComponent.js
index ad780aea..a276eac6 100644
--- a/components/CusdisComponent.js
+++ b/components/CusdisComponent.js
@@ -5,7 +5,7 @@ import { useEffect } from 'react'
import { loadExternalResource } from '@/lib/utils'
const CusdisComponent = ({ frontMatter }) => {
- const { locale } = useGlobal()
+ const { lang } = useGlobal()
const router = useRouter()
const { isDarkMode } = useGlobal()
@@ -18,7 +18,7 @@ const CusdisComponent = ({ frontMatter }) => {
}, [isDarkMode])
return
{
const { cRef, className } = props
- const { isDarkMode, updateDarkMode } = useGlobal()
+ const { isDarkMode, toggleDarkMode } = useGlobal()
/**
* 对外暴露方法
@@ -16,22 +15,12 @@ const DarkModeButton = (props) => {
useImperativeHandle(cRef, () => {
return {
handleChangeDarkMode: () => {
- handleChangeDarkMode()
+ toggleDarkMode()
}
}
})
- // 用户手动设置主题
- const handleChangeDarkMode = () => {
- const newStatus = !isDarkMode
- saveDarkModeToCookies(newStatus)
- updateDarkMode(newStatus)
- const htmlElement = document.getElementsByTagName('html')[0]
- htmlElement.classList?.remove(newStatus ? 'light' : 'dark')
- htmlElement.classList?.add(newStatus ? 'dark' : 'light')
- }
-
- return
+ return
}
diff --git a/components/ThemeSwitch.js b/components/ThemeSwitch.js
index a4b13f31..0c74a63e 100644
--- a/components/ThemeSwitch.js
+++ b/components/ThemeSwitch.js
@@ -5,19 +5,21 @@ 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 } = useGlobal()
+ 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 onSelectChange = (e) => {
+ const onThemeSelectChange = (e) => {
setIsLoading(true)
const newTheme = e.target.value
const query = router.query
@@ -27,27 +29,52 @@ const ThemeSwitch = () => {
})
}
+ const onLangSelectChange = (e) => {
+ const newLang = e.target.value
+ changeLang(newLang)
+ }
+
return (<>
-
-
-
-
-