app.js 669 B

1234567891011121314151617181920212223242526272829
  1. //app.js
  2. App({
  3. onLaunch: function() {
  4. //调用API从本地缓存中获取数据
  5. var logs = wx.getStorageSync('logs') || []
  6. logs.unshift(Date.now())
  7. wx.setStorageSync('logs', logs)
  8. },
  9. getUserInfo: function(cb) {
  10. var that = this
  11. if (this.globalData.userInfo) {
  12. typeof cb == "function" && cb(this.globalData.userInfo)
  13. } else {
  14. //调用登录接口
  15. wx.getUserInfo({
  16. withCredentials: false,
  17. success: function(res) {
  18. that.globalData.userInfo = res.userInfo
  19. typeof cb == "function" && cb(that.globalData.userInfo)
  20. }
  21. })
  22. }
  23. },
  24. globalData: {
  25. userInfo: null
  26. }
  27. })