UNPKG

bixi

Version:

企业级中后台前端解决方案

23 lines (19 loc) 582 B
import { NzSafeAny } from 'ng-zorro-antd/core/types'; import { log } from './logger'; function formatKey(key: string) { return `BIXI_${key.toUpperCase()}`; } export function setLocalItem(key: string, value: NzSafeAny) { localStorage.setItem(formatKey(key), JSON.stringify(value)); } export function getLocalItem(key: string, dft?: NzSafeAny) { const _key = formatKey(key); const str = localStorage.getItem(_key); if (!str) return dft || null; try { return JSON.parse(str); } catch (e) { log('storage', 'json parse failed', e); return dft || null; } }