You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1005 B
41 lines
1005 B
/** |
|
* 配置浏览器本地存储的方式,可直接存储对象数组。 |
|
*/ |
|
|
|
import Keys from '@/api/Keys' |
|
import { useTheme } from '@/utils/useTheme' |
|
import WebStorageCache from 'web-storage-cache' |
|
|
|
type CacheType = 'localStorage' | 'sessionStorage' |
|
|
|
export const useCache = (type: CacheType = 'localStorage') => { |
|
const wsCache: WebStorageCache = new WebStorageCache({ |
|
storage: type, |
|
}) |
|
|
|
return { |
|
wsCache, |
|
} |
|
} |
|
|
|
const { setTheme } = useTheme() |
|
export const deleteUserCache = () => { |
|
setTheme('light') |
|
const { wsCache } = useCache() |
|
wsCache.delete(Keys.STORAGE_USER_INFO) |
|
wsCache.delete(Keys.STORAGE_ROLE_ROUTERS) |
|
wsCache.delete(Keys.STORAGE_STATIONID) |
|
} |
|
|
|
export function getCacheStationId( |
|
stationId: number | string, |
|
type: 'get' | 'set' = 'get' |
|
) { |
|
const { wsCache } = useCache() |
|
const id = wsCache.get(Keys.STORAGE_STATIONID) |
|
if (!id || type === 'set') { |
|
wsCache.set(Keys.STORAGE_STATIONID, stationId) |
|
return Number(stationId) |
|
} |
|
return Number(id) |
|
}
|
|
|