// app.ts
App({
  globalDate: {
    global: 1,
    userLocationAuth: false,
    cameraAuth: false,
    extraData:null
  },
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    this.ctx = wx.createCameraContext();

    // 登录
    wx.login({
      success(res) {
        var openid = res.code
        console.log('openid', openid)
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        wx.setStorage({
          key: 'openid',
          data: openid
        })
        wx.navigateTo({
          url: '../miniprogram/pages/upload/upload'
        })
      }
    })
  },

  onShow(options) {
    // wx.clearStorageSync(); // 清空本地缓存数据
    // console.log('options', options)
    if (options.referrerInfo.extraData) {
      console.log('进来了')
      let extraData = options.referrerInfo.extraData;
      console.log('extraData', extraData)
      if (typeof (extraData) === 'string') {
        extraData = JSON.parse(options.referrerInfo.extraData)
      }
      // console.log('到这里extraData',extraData)
      wx.setStorage({
        key: 'extraData',
        data: extraData,
      })
      // 启动摄像头预览
      // this.ctx.startPreview();
      // console.log('labelInfoUrl.success', labelInfoUrl.success)
    }else{
      console.log('options.referrerInfo.extraData',options.referrerInfo.extraData)
      console.log('options.extraData',options.extraData)
      console.log('没有获取到数据')
      wx.setStorage({
        key: 'extraData',
        data: extraData,
      })
    }
  },
})