mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 23:16:53 +00:00
优化初始化主题
This commit is contained in:
@@ -45,10 +45,6 @@ export function GlobalContextProvider ({ children }) {
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasInit) {
|
||||
const userTheme = getQueryVariable('theme')
|
||||
if (userTheme && ALL_THEME.indexOf(userTheme) > -1) {
|
||||
setTheme(userTheme)
|
||||
}
|
||||
initLocale(locale, updateLocale)
|
||||
initDarkMode(isDarkMode, updateDarkMode)
|
||||
initTheme(theme, changeTheme)
|
||||
@@ -63,50 +59,4 @@ export function GlobalContextProvider ({ children }) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询url中的query参数
|
||||
* @param {}} variable
|
||||
* @returns
|
||||
*/
|
||||
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 sources
|
||||
*/
|
||||
export function mergeDeep (target, ...sources) {
|
||||
if (!sources.length) return target
|
||||
const source = sources.shift()
|
||||
|
||||
if (isObject(target) && isObject(source)) {
|
||||
for (const key in source) {
|
||||
if (isObject(source[key])) {
|
||||
if (!target[key]) Object.assign(target, { [key]: {} })
|
||||
mergeDeep(target[key], source[key])
|
||||
} else {
|
||||
Object.assign(target, { [key]: source[key] })
|
||||
}
|
||||
}
|
||||
}
|
||||
return mergeDeep(target, ...sources)
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象检查
|
||||
* @param item
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isObject (item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item))
|
||||
}
|
||||
|
||||
export const useGlobal = () => useContext(GlobalContext)
|
||||
|
||||
Reference in New Issue
Block a user