|
@@ -0,0 +1,44 @@
|
|
|
+module.exports = {
|
|
|
+ setStore: setStore,
|
|
|
+ getStore: getStore,
|
|
|
+ clearAll: clearAll,
|
|
|
+ remove: remove,
|
|
|
+}
|
|
|
+
|
|
|
+//同步储存缓存数据
|
|
|
+function setStore(key, value) {
|
|
|
+ try {
|
|
|
+ wx.setStorageSync(key, value);
|
|
|
+ } catch (e) {}
|
|
|
+};
|
|
|
+
|
|
|
+//同步取出缓存数据
|
|
|
+function getStore(key) {
|
|
|
+ try {
|
|
|
+ // 使用同步方法获取数据
|
|
|
+ const list = wx.getStorageSync(key);
|
|
|
+ if (list) {
|
|
|
+ return list;
|
|
|
+ } else {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+///不清除的有
|
|
|
+// {token,chatRecord,freeTimes}
|
|
|
+
|
|
|
+//清空数据
|
|
|
+function clearAll() {
|
|
|
+ const constant = require('./constant.js');
|
|
|
+ removeByKey(constant.param.userInfo);
|
|
|
+}
|
|
|
+
|
|
|
+//移除指定key
|
|
|
+function remove(key) {
|
|
|
+ try {
|
|
|
+ wx.removeStorageSync(key)
|
|
|
+ } catch (e) {}
|
|
|
+}
|