// 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)
    wx.setStorageSync('extraData', JSON.stringify({}))
    wx.setStorageSync('fenggu', '')

    // options.referrerInfo.extraData =  {
    //     "uid": "\"gAAAAABl3YfhldYhFyvH_EHb-_CPvbWIffRsxPwS1d_4lC_CxCq-CiLQtqGPEbLmXR--ZPjcIYp5mttnRTpppD6DghuymUheuw==\"",
    //     "uuid": "F1C0DF8F",
    //     "os": "davis",
    //     "cpid": "EH013527418551201",
    //     "company": "fenggu"
    //   }

    if (options.referrerInfo.extraData) {
      console.log('进来了')
      let extraData = options.referrerInfo.extraData;
      console.log('extraData', extraData)
    
      // console.log('到这里extraData',extraData)
      wx.setStorageSync('extraData', JSON.stringify(options.referrerInfo.extraData))
    wx.getStorageSync('fenggu', options?.referrerInfo?.extraData?.company || '')

      // 启动摄像头预览
      // this.ctx.startPreview();
      // console.log('labelInfoUrl.success', labelInfoUrl.success)
      // {
      //   "uid": "\"gAAAAABl3YfhldYhFyvH_EHb-_CPvbWIffRsxPwS1d_4lC_CxCq-CiLQtqGPEbLmXR--ZPjcIYp5mttnRTpppD6DghuymUheuw==\"",
      //   "uuid": "F1C0DF8F",
      //   "os": "davis",
      //   "cpid": "EH013527418551201",
      //   "company": "fenggu"
      // }
    } else {
      console.log('options.referrerInfo.extraData', options.referrerInfo.extraData)
      console.log('options.extraData', options.extraData)
      console.log('没有获取到数据')
      wx.setStorage({
        key: 'extraData',
        data: extraData,
      })
    }
  },
})