File tree 3 files changed +17
-6
lines changed
3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { AppConfig } from '../utils/config/app';
21
21
import { MonacoEditor } from '../utils/config/editor' ;
22
22
23
23
import { menu } from '../utils/menu' ;
24
+ import { storageStringifyParseValue } from '../utils/storage/menu' ;
24
25
25
26
// console.log('menu', menu);
26
27
@@ -30,8 +31,9 @@ export default function Template({
30
31
// @ts -ignore
31
32
children,
32
33
} ) {
34
+ const cacheMenuStatus = storageStringifyParseValue ( ) ;
33
35
const pathname = usePathname ( ) ;
34
- const [ collapsed , setCollapsed ] = useState ( false ) ;
36
+ const [ collapsed , setCollapsed ] = useState ( cacheMenuStatus . getItem ( ) ) ;
35
37
const [ appConfig , setAppConfig ] = useState <
36
38
Partial < AppConfigParams > | undefined
37
39
> ( {
@@ -134,7 +136,11 @@ export default function Template({
134
136
icon = {
135
137
collapsed ? < MenuUnfoldOutlined /> : < MenuFoldOutlined />
136
138
}
137
- onClick = { ( ) => setCollapsed ( ! collapsed ) }
139
+ onClick = { ( ) => {
140
+ const status = ! collapsed ;
141
+ cacheMenuStatus . setItem ( status ) ;
142
+ setCollapsed ( status ) ;
143
+ } }
138
144
style = { {
139
145
fontSize : '16px' ,
140
146
} }
Original file line number Diff line number Diff line change
1
+ import { getStorageKey , storageTools } from './tools' ;
2
+
3
+ export const storageStringifyParseValue = ( key : string = '' ) => {
4
+ return storageTools ( getStorageKey ( `menu_status_${ key } ` ) ) ;
5
+ } ;
Original file line number Diff line number Diff line change @@ -9,21 +9,21 @@ export const storageTools = (key: string) => {
9
9
return getStorageKey ( key ) ;
10
10
} ,
11
11
getItem ( ) {
12
- const value = localStorage . getItem ( key ) ;
12
+ const value = window ?. localStorage ? .getItem ?. ( key ) ;
13
13
if ( value ) {
14
14
return JSON . parse ( value ) ;
15
15
}
16
16
17
17
return null ;
18
18
} ,
19
19
setItem ( value : any ) {
20
- localStorage . setItem ( key , JSON . stringify ( value ) ) ;
20
+ window ?. localStorage ? .setItem ?. ( key , JSON . stringify ( value ) ) ;
21
21
} ,
22
22
removeItem ( ) {
23
- localStorage . removeItem ( key ) ;
23
+ window ?. localStorage ? .removeItem ?. ( key ) ;
24
24
} ,
25
25
clear ( ) {
26
- localStorage . clear ( ) ;
26
+ window ?. localStorage ? .clear ?. ( ) ;
27
27
} ,
28
28
} ;
29
29
} ;
You can’t perform that action at this time.
0 commit comments