From ddddcf83e7deb9d0a674d2bbead300089530d87e Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期三, 21 五月 2025 13:24:07 +0800
Subject: [PATCH] feat: UI

---
 apps/h5/src/utils/storage/storage.ts |   51 +++++++++++++++++++++++++++++----------------------
 1 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/apps/h5/src/utils/storage/storage.ts b/apps/h5/src/utils/storage/storage.ts
index f15fbd6..50f5804 100644
--- a/apps/h5/src/utils/storage/storage.ts
+++ b/apps/h5/src/utils/storage/storage.ts
@@ -1,39 +1,46 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-import Taro from '@tarojs/taro';
+interface ProxyStorage {
+  getItem(key: string): any;
+  setItem(Key: string, value: string): void;
+  removeItem(key: string): void;
+  clear(): void;
+}
 
 //sessionStorage operate
-class localStorageProxy {
-  constructor() {}
+class sessionStorageProxy implements ProxyStorage {
+  protected storage: ProxyStorage;
+
+  constructor(storageModel: ProxyStorage) {
+    this.storage = storageModel;
+  }
 
   // 瀛�
   public setItem(key: string, value: any): void {
-    return Taro.setStorageSync(key, JSON.stringify(value));
+    this.storage.setItem(key, JSON.stringify(value));
   }
 
   // 鍙�
-  public getItem<T = any>(key: string): Nullable<T> {
-    try {
-      const value = Taro.getStorageSync(key);
-      if (value) {
-        // Do something with return value
-        return JSON.parse(value);
-      }
-      return null;
-    } catch (e) {
-      // Do something when catch error
-      return null;
-    }
+  public getItem<T = any>(key: string): null | T {
+    return JSON.parse(this.storage.getItem(key));
   }
 
   // 鍒�
-  public removeItem(key: string) {
-    return Taro.removeStorageSync(key);
+  public removeItem(key: string): void {
+    this.storage.removeItem(key);
   }
 
   // 娓呯┖
-  public clear() {
-    return Taro.clearStorage();
+  public clear(): void {
+    this.storage.clear();
   }
 }
 
-export const storageLocal = new localStorageProxy();
+//localStorage operate
+class localStorageProxy extends sessionStorageProxy implements ProxyStorage {
+  constructor(localStorage: ProxyStorage) {
+    super(localStorage);
+  }
+}
+
+export const storageSession = new sessionStorageProxy(sessionStorage);
+
+export const storageLocal = new localStorageProxy(localStorage);

--
Gitblit v1.9.1