提交 | 用户 | age
|
b7ce74
|
1 |
import { Persistent, BasicKeys } from '/@/utils/cache/persistent'; |
V |
2 |
import { CacheTypeEnum } from '/@/enums/cacheEnum'; |
|
3 |
import projectSetting from '/@/settings/projectSetting'; |
|
4 |
import { TOKEN_KEY } from '/@/enums/cacheEnum'; |
|
5 |
|
|
6 |
const { permissionCacheType } = projectSetting; |
|
7 |
const isLocal = permissionCacheType === CacheTypeEnum.LOCAL; |
|
8 |
|
|
9 |
export function getToken() { |
|
10 |
return getAuthCache(TOKEN_KEY); |
|
11 |
} |
|
12 |
|
|
13 |
export function getAuthCache<T>(key: BasicKeys) { |
|
14 |
const fn = isLocal ? Persistent.getLocal : Persistent.getSession; |
|
15 |
return fn(key) as T; |
|
16 |
} |
|
17 |
|
|
18 |
export function setAuthCache(key: BasicKeys, value) { |
|
19 |
const fn = isLocal ? Persistent.setLocal : Persistent.setSession; |
fedd9c
|
20 |
return fn(key, value, true); |
b7ce74
|
21 |
} |