/** * window.localStorage * @method set 设置 * @method get 获取 * @method remove 移除 * @method clear 移除全部(保留表格列配置、Pinia DevTools 设置) */ const LOCAL_STORAGE_PRESERVE_KEYS = [ 'VXE_CUSTOM_STORE', '__VUE_DEVTOOLS_NEXT_PLUGIN_SETTINGS__dev.esm.pinia__' ] export const Local = { set(key: string, val: any) { window.localStorage.setItem(key, JSON.stringify(val)) }, get(key: string) { const json: any = window.localStorage.getItem(key) return JSON.parse(json) }, remove(key: string) { window.localStorage.removeItem(key) }, clear() { const preserved: Record = {} for (const key of LOCAL_STORAGE_PRESERVE_KEYS) { const value = window.localStorage.getItem(key) if (value !== null) preserved[key] = value } window.localStorage.clear() for (const [key, value] of Object.entries(preserved)) { window.localStorage.setItem(key, value) } }, } /** * window.sessionStorage * @method set 设置会话缓存 * @method get 获取会话缓存 * @method remove 移除会话缓存 * @method clear 移除全部会话缓存 */ const DEFAULT_THEME_NAME = '电能质量监测系统' export function getStoredTheme(): { name?: string; logoUrl?: string; [key: string]: any } { try { const raw = window.localStorage.getItem('getTheme') return raw ? JSON.parse(raw) : {} } catch { return {} } } export function getStoredThemeName(): string { return getStoredTheme().name || DEFAULT_THEME_NAME } export const Session = { set(key: string, val: any) { window.sessionStorage.setItem(key, JSON.stringify(val)) }, get(key: string) { const json: any = window.sessionStorage.getItem(key) return JSON.parse(json) }, remove(key: string) { window.sessionStorage.removeItem(key) }, clear() { window.sessionStorage.clear() }, }