//app.js
const util = require('./utils/util.js')
App({
  onLaunch: function () {
    wx.setStorageSync('openId', '')

    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // // 登录
    // wx.login({
    //   success: res => {
    //     wx.showLoading({
    //       title: '正在加载',
    //       mask: true
    //     })
    //     util.doPost(
    //       'getOpenId', {
    //         appId: app.globalData.appId,
    //         code: res.code
    //       },
    //     ).then(res => {
    //       console.log(res)
    //       if (res.success > 0) {
    //         this.globalData.openId = res.data.openId;
    //         wx.setStorage({
    //           key: 'openId',
    //           data: res.data.openId,
    //           success: (res) => {
    //             wx.hideLoading({
    //               complete: (res) => {},
    //             })
    //           },
    //         })
    //       }
    //     })
    //   }
    // })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
          wx.getUserInfo({
            success: res => {
              this.globalData.userInfo = res.userInfo;
              // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        } else {
          console.log('未获取用户信息 ... ')
        }
      }
    })

    //获取手机状态栏高度
    // wx.getSystemInfo({
    //   success: res => {
    //     this.globalData.statusBarHeight = res.statusBarHeight
    //   }
    // })
  },

  globalData: {
    userInfo: null,
    openId: '',
    imageUrl: 'https://app.schoolwisdoms.com/static/wx/images/',
    orgTitle: '艾克斯朗学生端',
    appId: 'wx5e6122b0a733ad22',
  }
})