/** * 配置浏览器本地存储的方式,可直接存储对象数组。 */ import Keys from '@/api/Keys' 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, } } export const deleteUserCache = () => { 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) }