zhengyiming
5 天以前 8c1c96a03da69b980a8822a02603123d78d8b4e1
src/utils/storage/storage.ts
@@ -1,9 +1,13 @@
import { loadEnv } from '@build/index';
interface ProxyStorage {
  getItem(key: string): any;
  setItem(Key: string, value: string): void;
  removeItem(key: string): void;
  clear(): void;
}
const { VITE_PUBLIC_PATH } = loadEnv();
//sessionStorage operate
class sessionStorageProxy implements ProxyStorage {
@@ -13,19 +17,23 @@
    this.storage = storageModel;
  }
  getKey(key: string): string {
    return `${VITE_PUBLIC_PATH}_${key}`;
  }
  // 存
  public setItem(key: string, value: any): void {
    this.storage.setItem(key, JSON.stringify(value));
    this.storage.setItem(this.getKey(key), JSON.stringify(value));
  }
  // 取
  public getItem<T = any>(key: string): null | T {
    return JSON.parse(this.storage.getItem(key));
    return JSON.parse(this.storage.getItem(this.getKey(key)));
  }
  // 删
  public removeItem(key: string): void {
    this.storage.removeItem(key);
    this.storage.removeItem(this.getKey(key));
  }
  // 清空