7 changed files with 87 additions and 25 deletions
@ -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} |
Loading…
Reference in new issue