Skip to content

Commit

Permalink
feat: theme cache
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jul 29, 2024
1 parent fd6191f commit 079e029
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/hooks/useTheme.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { computed, ref, unref } from 'vue'
import { theme as antTheme } from 'ant-design-vue'
import { localCache, THEME__LOCAL } from '@/utils/storage'

const defaultValues = {
theme: 'dark',
primary: 'blue',
compact: false
}

function useTheme () {
const themeCache = localCache.getObj(THEME__LOCAL)
const { darkAlgorithm, compactAlgorithm } = antTheme
const { token } = antTheme.useToken()

// @todo 添加缓存
const themeConfig = ref({
theme: 'dark',
primary: 'blue',
compact: false
})
const themeConfig = ref(themeCache || defaultValues)

const themeProvider = computed(() => {
const { theme, primary, compact } = unref(themeConfig)
Expand All @@ -26,6 +29,7 @@ function useTheme () {

function setThemeConfig (value) {
themeConfig.value = value
localCache.setObj(THEME__LOCAL, value)
}

return { themeConfig, themeProvider, setThemeConfig }
Expand Down
1 change: 1 addition & 0 deletions src/utils/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const sessionCache = new GalleryCache(sessionStorage)

export const TAGS__LOCAL = 'tags'
export const LOCALE__LOCAL = 'locale'
export const THEME__LOCAL = 'theme'

// 用户账号
export const USERNAME__LOCAL = 'username'
Expand Down

0 comments on commit 079e029

Please sign in to comment.