设备管理
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.

39 lines
909 B

/**
*
*/
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)
}