//app.js
const AUTH = require('utils/auth')
App({
  initUiGlobal() {
    wx.getSystemInfo({
      success: e => {
        const { statusBarHeight: StatusBar, screenHeight, windowWidth } = e
        this.globalData.StatusBar = StatusBar
        this.globalData.screenHeight = screenHeight
        this.globalData.windowWidth = windowWidth
        const capsule = wx.getMenuButtonBoundingClientRect()
        if (capsule) {
          this.globalData.Custom = capsule
          this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
        } else {
          this.globalData.CustomBar = StatusBar + 50
        }
        // console.log(capsule,"hah",this.globalData.StatusBar,"18")
      }
    })
  },
  checkUpdate(){
    const updateManager = wx.getUpdateManager()
    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
      console.log(res.hasUpdate)
    })
    updateManager.onUpdateReady(function () {
      wx.showModal({
        title: '更新提示',
        content: '新版本已经准备好,是否重启应用?',
        success(res) {
          if (res.confirm) {
            // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate()
          }
        }
      })
    })
    updateManager.onUpdateFailed(function () {
      // 新版本下载失败
    })
  },
  onLaunch:async function () {
    this.initUiGlobal();
    this.checkUpdate();
  },
  globalData: {
    autoRefreshTime:5000,
    specialProject:["VOTn11010802592ab7d57ca79b47ee95a0b9eb1cd6a902"],
    StatusBar: null,
    Custom: null,
    CustomBar: null,
    screenHeight: null,
    windowWidth: null,
    userInfo: null,
    hasUserInfo:false,
    openId:null,
    userId:null,
    projectId:"",
    tenantId:"",
    remote:false,
    tenants:[],
    projectName:null,
    topSpace:null,
    changeTenantId:false,
    goHome:false,
    picInitUrl:"../../static/images/initpic.png",
    imgbaseUrl:"http://api.sagacloud.cn/dp-auxiliary/image-service/common/image_get?systemId=dataPlatform&key=",
    envNamelist:{
      // temperature:{
      //   name:"温度",
      //   unit:"°C",
      //   funcid:"Tdb"
      //   imgSrc:"../../static/images/Temp.png"
      // },
      humidity:{
        name:"湿度",
        localName:"湿度",
        unit:"%",
        funcid:"RH",
        imgSrc:"../../static/images/RH.png"
      },
      co2:{
        name:"CO₂",
        unit:"ppm",
        localName:"CO₂",
        funcid:"CO2",
        imgSrc:"../../static/images/CO2.png"
      },
      pm25:{
        name:"PM2.5",
        localName:"PM2.5",
        unit:"μg/m³",
        funcid:"PM2d5",
        baseNumer:1000,
        imgSrc:"../../static/images/PM2.5.png"
      },
      hcho:{
        name:"甲醛",
        localName:"甲醛",
        unit:"mg/m³",
        funcid:"HCHO",
        imgSrc:"../../static/images/HCHO.png"
      },
    },
  }
})