/** * 通用的本地存储管理类 * 提供对 localStorage 和 sessionStorage 的封装操作,支持单例模式 */ type TStoreType = "local" | "session"; type TRecord = Record; export declare class WebStore { private readonly storageKey; private readonly storeType; private store?; private static instances; private constructor(); private static getInstanceKey; /** * 获取单例实例 */ private static getInstance; /** * 便捷方法:创建本地存储实例 */ static local(storageKey: string): WebStore; /** * 便捷方法:创建会话存储实例 */ static session(storageKey: string): WebStore; /** * 清理指定实例 */ static clearInstance(storageKey: string, storeType?: TStoreType): void; /** * 清理所有实例 */ static clearAllInstances(): void; private getStore; /** * 设置数据到 localStorage 或 sessionStorage */ set(prop: K, value: T[K]): void; /** * 获取数据从 localStorage 或 sessionStorage */ get(prop: K): T[K] | undefined; /** * 获取所有数据 */ getAll(): T; /** * 删除指定的数据 */ remove(prop: K): void; /** * 清空所有数据 */ clear(): void; /** * 批量设置多个数据 */ setMultiple(data: Partial): void; private listeners; private static isGlobalListenerInitialized; private static setupGlobalListener; private dispatchChange; /** * 监听存储变化 (支持单属性监听或全量变化监听) */ onChanged(prop: K, callback: (newValue?: T[K], oldValue?: T[K]) => void): void; onChanged(callback: (changes: { [K in keyof T]?: { newValue?: T[K]; oldValue?: T[K]; }; }) => void): void; /** * 移除监听器 */ offChanged(prop: K, callback: (newValue?: T[K], oldValue?: T[K]) => void): void; offChanged(callback: (changes: { [K in keyof T]?: { newValue?: T[K]; oldValue?: T[K]; }; }) => void): void; /** * 检查是否存在指定的数据 */ has(prop: K): boolean; /** * 获取存储大小(字节数) */ getSize(): number; /** * 获取当前存储键名 */ getStoreKey(): string; } export {};