1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| module.exports = { test: function() { try { wx.setStorageSync("JDC_TEST", "1"); wx.removeStorageSync("JDC_TEST"); return true; } catch (e) { wx.showModal({ title: "提示", content: "小程序缓存出现问题,请稍后使用", showCancel: !1, success: function(e) { if(e.confirm){ console.log("用户点击确定"); } } }) return false; } }, set: function(name, value, expire) { if (typeof expire == "number") { expire = expire * 1e3; } else { expire = 2592e5 } wx.removeStorageSync(name); var time = new Date().getTime(); try { wx.setStorageSync(name, { _value: value, _time: time, _age: time + expire }); return true; } catch (e) { return false; } }, get: function(name) { var data = this._isExpire(name); if (data !== true) { return data._value } else { return null } }, del: function(name) { try { wx.removeStorageSync(name); return !0; } catch (e) { return !1; } }, _isExpire: function(name) { var data = wx.getStorageSync(name); var time = new Date().getTime(); if (data && time < data._age) { return data; } else { return true; } }, }
|