From 1d6532329a5632bbed207ad8aec57361b9f73851 Mon Sep 17 00:00:00 2001 From: lqq Date: Thu, 17 Oct 2019 14:14:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=AD=98=E5=82=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=99=A8=E4=B8=80=E4=B8=AA=E5=8D=95=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/store.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 utils/store.js diff --git a/utils/store.js b/utils/store.js new file mode 100644 index 0000000..e45dc10 --- /dev/null +++ b/utils/store.js @@ -0,0 +1,46 @@ +const StoreKey = { + UserStoreKey: 'UserInfoStoreKey', + TokenStoreKey: 'TokenStoreKey' +} +class Store { + constructor () { + + } + // public + + // Token的存取方法 + saveToken(data) { + this._save(StoreKey.TokenStoreKey, data) + } + readToken() { + return this._read(StoreKey.TokenStoreKey) || '' + } + // User的存取 + saveUserInfo(data) { + this._save(StoreKey.UserStoreKey, data) + } + readUserInfo(){ + return this._read(StoreKey.UserStoreKey) || '' + } + // 是否有手机号码 + hasPhone () { + const {phone} = this.readUserInfo() + return phone ? true : false + } + // 是否绑定微信和人才库 + hasBindUserInfo () { + const {avatarUrl, nickName} = this.readUserInfo() + console.log(avatarUrl, nickName) + return (avatarUrl && nickName) ? true : false + } + + // 私有存取方法 + _save(key, data) { + wx.setStorageSync(key, data) + } + _read(key) { + return wx.getStorageSync(key) + } +} +let store = new Store() // 唯一个对象实例 +export {store} \ No newline at end of file