useThemeStore.ts
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {defineStore} from "pinia";
import {computed, ref} from "vue";
import {theme} from "ant-design-vue";
import type {ThemeConfig} from "ant-design-vue/lib/config-provider/context";
import type {MappingAlgorithm} from "ant-design-vue/lib/config-provider/context";
export const useThemeStore = defineStore('theme', () => {
const isDarkTheme = window.matchMedia("(prefers-color-scheme: dark)"); // 是深色
const isDark = ref(isDarkTheme.matches)
const isCompact = ref(false)
const {token} = theme.useToken()
const themeConfig = computed<ThemeConfig>(() => {
let algorithm: MappingAlgorithm[] = [theme.defaultAlgorithm]
if (isDark.value) {
algorithm.push(theme.darkAlgorithm)
}
if (isCompact.value) {
algorithm.push(theme.compactAlgorithm)
}
return {
token: {
borderRadius: 0,
colorPrimary: "#009dff",
colorInfo: '#009dff',
fontSize: 14,
},
algorithm: algorithm,
components: {
Layout: {
colorBgHeader: isDark.value ? '#141414' : '#ffffff'
},
Button: {}
}
}
})
return {
themeConfig: themeConfig,
isDark: isDark,
isCompact: isCompact,
token
}
})