封装theme,用cookie保存主题

This commit is contained in:
tangly1024
2022-03-22 12:38:47 +08:00
parent e98db24cb7
commit 09101daaab
4 changed files with 54 additions and 45 deletions

View File

@@ -1,19 +1,17 @@
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
import * as ThemeMap from '@/themes'
import { useState } from 'react'
import { useRouter } from 'next/router'
import Select from './Select'
import { ALL_THEME } from '@/lib/theme'
import { useGlobal } from '@/lib/global'
/**
*
* @returns 调试面板
*/
export function DebugPanel () {
const [show, setShow] = useState(false)
const GlobalConfig = useGlobal()
const router = useRouter()
const { theme, setTheme } = GlobalConfig
const { theme, changeTheme, switchTheme } = useGlobal()
const themeOptions = []
ALL_THEME.forEach(t => {
themeOptions.push({ value: t, text: t })
@@ -23,19 +21,6 @@ export function DebugPanel () {
setShow(!show)
}
function switchTheme () {
const currentIndex = ALL_THEME.indexOf(theme)
const newIndex = currentIndex < ALL_THEME.length - 1 ? currentIndex + 1 : 0
changeTheme(ALL_THEME[newIndex])
}
/**
* 切换主题
*/
function changeTheme (theme) {
router.query.theme = ''
setTheme(theme)
}
function filterResult (text) {
switch (text) {
case 'true':