提交 | 用户 | 时间
|
314507
|
1 |
/** |
H |
2 |
* 配置浏览器本地存储的方式,可直接存储对象数组。 |
|
3 |
*/ |
|
4 |
|
|
5 |
import WebStorageCache from 'web-storage-cache' |
|
6 |
|
|
7 |
type CacheType = 'localStorage' | 'sessionStorage' |
|
8 |
|
|
9 |
export const CACHE_KEY = { |
|
10 |
// 用户相关 |
|
11 |
ROLE_ROUTERS: 'roleRouters', |
|
12 |
USER: 'user', |
|
13 |
// 系统设置 |
|
14 |
IS_DARK: 'isDark', |
|
15 |
LANG: 'lang', |
|
16 |
THEME: 'theme', |
|
17 |
LAYOUT: 'layout', |
|
18 |
DICT_CACHE: 'dictCache', |
|
19 |
// 登录表单 |
|
20 |
LoginForm: 'loginForm', |
|
21 |
TenantId: 'tenantId' |
|
22 |
} |
|
23 |
|
|
24 |
export const useCache = (type: CacheType = 'localStorage') => { |
|
25 |
const wsCache: WebStorageCache = new WebStorageCache({ |
|
26 |
storage: type |
|
27 |
}) |
|
28 |
|
|
29 |
return { |
|
30 |
wsCache |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
export const deleteUserCache = () => { |
|
35 |
const { wsCache } = useCache() |
|
36 |
wsCache.delete(CACHE_KEY.USER) |
|
37 |
wsCache.delete(CACHE_KEY.ROLE_ROUTERS) |
|
38 |
// 注意,不要清理 LoginForm 登录表单 |
|
39 |
} |
f5c803
|
40 |
|
H |
41 |
export const useSessionCache = (type: CacheType = 'sessionStorage') => { |
|
42 |
const wsSessionCache: WebStorageCache = new WebStorageCache({ |
|
43 |
storage: type |
|
44 |
}) |
|
45 |
|
|
46 |
return { |
|
47 |
wsSessionCache |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
export const deleteUserSessionCache = () => { |
|
52 |
const { wsSessionCache } = useSessionCache() |
|
53 |
wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS) |
|
54 |
// 注意,不要清理 用户和 LoginForm 登录表单 |
|
55 |
} |