@@ -2,15 +2,16 @@ import keys from 'lodash/keys';
2
2
import { defineStore } from 'pinia' ;
3
3
import { Color } from 'tvision-color' ;
4
4
5
- import { DARK_CHART_COLORS , LIGHT_CHART_COLORS } from '@/config/color' ;
5
+ import { DARK_CHART_COLORS , LIGHT_CHART_COLORS , TColorSeries } from '@/config/color' ;
6
6
import STYLE_CONFIG from '@/config/style' ;
7
7
import { store } from '@/store' ;
8
+ import { ModeType } from '@/types/interface' ;
8
9
import { generateColorMap , insertThemeStylesheet } from '@/utils/color' ;
9
10
10
- const state = {
11
+ const state : Record < string , any > = {
11
12
...STYLE_CONFIG ,
12
13
showSettingPanel : false ,
13
- colorList : { } ,
14
+ colorList : { } as TColorSeries ,
14
15
chartColors : LIGHT_CHART_COLORS ,
15
16
} ;
16
17
@@ -23,22 +24,22 @@ export const useSettingStore = defineStore('setting', {
23
24
showSidebar : ( state ) => state . layout !== 'top' ,
24
25
showSidebarLogo : ( state ) => state . layout === 'side' ,
25
26
showHeaderLogo : ( state ) => state . layout !== 'side' ,
26
- displayMode : ( state ) : 'dark' | 'light' => {
27
+ displayMode : ( state ) : ModeType => {
27
28
if ( state . mode === 'auto' ) {
28
29
const media = window . matchMedia ( '(prefers-color-scheme:dark)' ) ;
29
30
if ( media . matches ) {
30
31
return 'dark' ;
31
32
}
32
33
return 'light' ;
33
34
}
34
- return state . mode as 'dark' | 'light' ;
35
+ return state . mode as ModeType ;
35
36
} ,
36
- displaySideMode : ( state ) : 'dark' | 'light' => {
37
- return state . sideMode as 'dark' | 'light' ;
37
+ displaySideMode : ( state ) : ModeType => {
38
+ return state . sideMode as ModeType ;
38
39
} ,
39
40
} ,
40
41
actions : {
41
- async changeMode ( mode : 'dark' | 'light' | 'auto' ) {
42
+ async changeMode ( mode : ModeType | 'auto' ) {
42
43
let theme = mode ;
43
44
44
45
if ( mode === 'auto' ) {
@@ -50,7 +51,7 @@ export const useSettingStore = defineStore('setting', {
50
51
51
52
this . chartColors = isDarkMode ? DARK_CHART_COLORS : LIGHT_CHART_COLORS ;
52
53
} ,
53
- async changeSideMode ( mode : 'dark' | 'light' ) {
54
+ async changeSideMode ( mode : ModeType ) {
54
55
const isDarkMode = mode === 'dark' ;
55
56
56
57
document . documentElement . setAttribute ( 'side-mode' , isDarkMode ? 'dark' : '' ) ;
@@ -75,23 +76,23 @@ export const useSettingStore = defineStore('setting', {
75
76
step : 10 ,
76
77
remainInput : false , // 是否保留输入 不保留会矫正不合适的主题色
77
78
} ) ;
78
- colorMap = generateColorMap ( brandTheme , newPalette , mode as 'light' | 'dark' , brandColorIndex ) ;
79
+ colorMap = generateColorMap ( brandTheme , newPalette , mode , brandColorIndex ) ;
79
80
this . colorList [ colorKey ] = colorMap ;
80
81
}
81
82
// TODO 需要解决不停切换时有反复插入 style 的问题
82
- insertThemeStylesheet ( brandTheme , colorMap , mode as 'light' | 'dark' ) ;
83
+ insertThemeStylesheet ( brandTheme , colorMap , mode ) ;
83
84
document . documentElement . setAttribute ( 'theme-color' , brandTheme ) ;
84
85
} ,
85
86
updateConfig ( payload : Partial < TState > ) {
86
87
for ( const key in payload ) {
87
88
if ( payload [ key as TStateKey ] !== undefined ) {
88
- this [ key ] = payload [ key as TStateKey ] ;
89
+ this [ key as TStateKey ] = payload [ key as TStateKey ] ;
89
90
}
90
91
if ( key === 'mode' ) {
91
- this . changeMode ( payload [ key ] ) ;
92
+ this . changeMode ( payload [ key ] as ModeType ) ;
92
93
}
93
94
if ( key === 'sideMode' ) {
94
- this . changeSideMode ( payload [ key ] ) ;
95
+ this . changeSideMode ( payload [ key ] as ModeType ) ;
95
96
}
96
97
if ( key === 'brandTheme' ) {
97
98
this . changeBrandTheme ( payload [ key ] ) ;
0 commit comments