usePlatformInfo.ts 693 Bytes
import type { PlatformInfo } from '#/store'
import { PLATFORM_INFO_CACHE_KEY } from '@/enums/cacheEnum'
import { createStorage } from '@/utils/cache'
import { getPlatformInfo as getPlatform } from '@/api/sys'

const storage = createStorage()
export const getPlatformInfo = () => storage.get(PLATFORM_INFO_CACHE_KEY) as PlatformInfo
export const setPlatformInfo = (info: Recordable) => storage.set(PLATFORM_INFO_CACHE_KEY, info)

export const usePlatform = async () => {
  const platformInfo = (await getPlatform()) || {}
  setPlatformInfo(platformInfo)
  return platformInfo
}

window.getPlatformInfo = getPlatformInfo
window.setPlatformInfo = setPlatformInfo
window.usePlatform = usePlatform