From b26c02f9f1be4bf7e5c6fbb64ba3a2a13428c78f Mon Sep 17 00:00:00 2001 From: chensiAb <chenchenco03@163.com> Date: Wed, 17 Apr 2024 15:37:16 +0800 Subject: [PATCH] fix:'删除小程序echarts文件,使用封装过得组件' --- common/LocalStorage.js | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/common/LocalStorage.js b/common/LocalStorage.js index aacd37e..e299a5e 100644 --- a/common/LocalStorage.js +++ b/common/LocalStorage.js @@ -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