mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 07:26:47 +00:00
主题初始化
This commit is contained in:
@@ -17,9 +17,7 @@ export function GlobalContextProvider ({ children }) {
|
|||||||
const [locale, updateLocale] = useState(generateLocaleDict('en-US'))
|
const [locale, updateLocale] = useState(generateLocaleDict('en-US'))
|
||||||
const [isDarkMode, updateDarkMode] = useState(false)
|
const [isDarkMode, updateDarkMode] = useState(false)
|
||||||
const [onLoading, changeLoadingState] = useState(false)
|
const [onLoading, changeLoadingState] = useState(false)
|
||||||
// 会优先读取浏览器中的主题参数
|
const [theme, setTheme] = useState(BLOG.THEME)
|
||||||
const [theme, setTheme] = useState(Router?.router?.query?.theme || BLOG.THEME)
|
|
||||||
|
|
||||||
Router.events.on('routeChangeStart', (...args) => {
|
Router.events.on('routeChangeStart', (...args) => {
|
||||||
changeLoadingState(true)
|
changeLoadingState(true)
|
||||||
})
|
})
|
||||||
@@ -30,6 +28,11 @@ export function GlobalContextProvider ({ children }) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasInit) {
|
if (!hasInit) {
|
||||||
|
const userTheme = getQueryVariable('theme')
|
||||||
|
console.log('用户主题', userTheme)
|
||||||
|
if (userTheme && ALL_THEME.indexOf(userTheme) > -1) {
|
||||||
|
setTheme(userTheme)
|
||||||
|
}
|
||||||
initLocale(locale, updateLocale)
|
initLocale(locale, updateLocale)
|
||||||
initDarkMode(isDarkMode, updateDarkMode)
|
initDarkMode(isDarkMode, updateDarkMode)
|
||||||
hasInit = true
|
hasInit = true
|
||||||
@@ -43,6 +46,16 @@ export function GlobalContextProvider ({ children }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getQueryVariable (variable) {
|
||||||
|
const query = window.location.search.substring(1)
|
||||||
|
const vars = query.split('&')
|
||||||
|
for (let i = 0; i < vars.length; i++) {
|
||||||
|
const pair = vars[i].split('=')
|
||||||
|
if (pair[0] == variable) { return pair[1] }
|
||||||
|
}
|
||||||
|
return (false)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 深度合并两个对象
|
* 深度合并两个对象
|
||||||
* @param target
|
* @param target
|
||||||
|
|||||||
Reference in New Issue
Block a user