File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { computed , ref , unref } from 'vue'
2
2
import { theme as antTheme } from 'ant-design-vue'
3
+ import { localCache , THEME__LOCAL } from '@/utils/storage'
4
+
5
+ const defaultValues = {
6
+ theme : 'dark' ,
7
+ primary : 'blue' ,
8
+ compact : false
9
+ }
3
10
4
11
function useTheme ( ) {
12
+ const themeCache = localCache . getObj ( THEME__LOCAL )
5
13
const { darkAlgorithm, compactAlgorithm } = antTheme
6
14
const { token } = antTheme . useToken ( )
7
15
8
- // @todo 添加缓存
9
- const themeConfig = ref ( {
10
- theme : 'dark' ,
11
- primary : 'blue' ,
12
- compact : false
13
- } )
16
+ const themeConfig = ref ( themeCache || defaultValues )
14
17
15
18
const themeProvider = computed ( ( ) => {
16
19
const { theme, primary, compact } = unref ( themeConfig )
@@ -26,6 +29,7 @@ function useTheme () {
26
29
27
30
function setThemeConfig ( value ) {
28
31
themeConfig . value = value
32
+ localCache . setObj ( THEME__LOCAL , value )
29
33
}
30
34
31
35
return { themeConfig, themeProvider, setThemeConfig }
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ export const sessionCache = new GalleryCache(sessionStorage)
59
59
60
60
export const TAGS__LOCAL = 'tags'
61
61
export const LOCALE__LOCAL = 'locale'
62
+ export const THEME__LOCAL = 'theme'
62
63
63
64
// 用户账号
64
65
export const USERNAME__LOCAL = 'username'
You can’t perform that action at this time.
0 commit comments