mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-08 23:16:54 +00:00
切换主题
This commit is contained in:
@@ -5,7 +5,7 @@ import BLOG from '@/blog.config'
|
||||
import { ALL_THEME, initDarkMode } from '@/lib/theme'
|
||||
import NProgress from 'nprogress'
|
||||
import LoadingCover from '@/components/LoadingCover'
|
||||
import { getQueryParam, isBrowser } from './utils'
|
||||
import { getQueryParam, getQueryVariable, isBrowser } from './utils'
|
||||
|
||||
const GlobalContext = createContext()
|
||||
|
||||
@@ -46,18 +46,20 @@ export function GlobalContextProvider({ children }) {
|
||||
NProgress.start()
|
||||
const { theme } = router.query
|
||||
if (theme && !url.includes(`theme=${theme}`)) {
|
||||
// TODO
|
||||
const newUrl = `${url}${url.includes('?') ? '&' : '?'}theme=${theme}`
|
||||
console.log('检查newUrl', newUrl)
|
||||
router.push(newUrl)
|
||||
}
|
||||
setOnLoading(true)
|
||||
}
|
||||
const handleStop = () => {
|
||||
NProgress.done()
|
||||
setTheme(getQueryParam(router.asPath, 'theme') || BLOG.THEME)
|
||||
setOnLoading(false)
|
||||
}
|
||||
|
||||
const queryTheme = getQueryVariable('theme')
|
||||
setTheme(queryTheme)
|
||||
|
||||
router.events.on('routeChangeStart', handleStart)
|
||||
router.events.on('routeChangeError', handleStop)
|
||||
router.events.on('routeChangeComplete', handleStop)
|
||||
|
||||
Reference in New Issue
Block a user