From 81a735caa69952bc24e0fa3e08549974dc11ff21 Mon Sep 17 00:00:00 2001
From: Tevin <tingquanren@163.com>
Date: Mon, 18 Mar 2024 20:02:36 +0800
Subject: [PATCH] 修复签名组件,小程序中,上传图片报错的问题

---
 common/LocalStorage.js |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/common/LocalStorage.js b/common/LocalStorage.js
index b1eb5a0..e299a5e 100644
--- a/common/LocalStorage.js
+++ b/common/LocalStorage.js
@@ -9,7 +9,7 @@
 export class LocalStorage {
     constructor() {
         this._data = {
-            prefixType: '',
+            prefixType: process.env.TARO_ENV === 'h5' ? 'h5' : 'wx',
         };
     }
 
@@ -18,9 +18,22 @@
         this._data.prefixType = prefixType;
     }
 
-    load(key) {
+    load(key, defaultType = 'obj') {
         const name = 'AiSim.' + this._data.prefixType + '@' + key;
-        return JSON.parse(Taro.getStorageSync(name) || '{}');
+        const data = Taro.getStorageSync(name);
+        if (data) {
+            return JSON.parse(data);
+        } else {
+            if (defaultType === 'obj') {
+                return {};
+            } else if (defaultType === 'arr') {
+                return [];
+            }
+        }
+    }
+
+    loadArr(key) {
+        return this.load(key, 'arr');
     }
 
     save(key, value) {
@@ -59,6 +72,17 @@
         return matches;
     }
 
+    // 清除本地存储工具保存的所有数据
+    cleanAll() {
+        const info = Taro.getStorageInfoSync();
+        const prefixReg = /^AiSim\.[a-zA-Z]+@/;
+        info.keys.forEach(storageKey => {
+            if (prefixReg.test(storageKey)) {
+                Taro.removeStorageSync(storageKey);
+            }
+        });
+    }
+
 }
 
 export const $localStorage = new LocalStorage();
\ No newline at end of file

--
Gitblit v1.9.1