From 8c1c96a03da69b980a8822a02603123d78d8b4e1 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期一, 30 六月 2025 21:28:47 +0800 Subject: [PATCH] feat: v2.2 --- src/utils/storage/storage.ts | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utils/storage/storage.ts b/src/utils/storage/storage.ts index 50f5804..f60ec37 100644 --- a/src/utils/storage/storage.ts +++ b/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)); } // 娓呯┖ -- Gitblit v1.9.1