app.js 3.12 KB
// app.js
require('./extends/page-extend')
import {ajaxUrl,picUrl} from './config.js';
App({
  onLaunch() {
    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 () {
      // 新版本下载失败
    })

    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    wx.getSystemInfo({
      success: res => {
        let statusBarHeight = res.statusBarHeight,
          navTop = menuButtonObject.top,//胶囊按钮与顶部的距离
          navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight)*2;//导航高度
        this.globalData.navHeight = navHeight;
        this.globalData.navTop = navTop;
        this.globalData.windowHeight = res.windowHeight;
        this.globalData.windowWidth = res.windowWidth; 
        let { screenWidth, screenHeight } = res
        // iphoneX 、11、Xr、 Max等设备分辨率
        let _screen = [
            {w: 375, h: 812 },
            {w: 414, h: 896 },
            {w: 390, h: 844 },
            {w: 428, h: 926 },
        ]
        this.globalData.isIphoneX  = _screen.some(item => item.w === screenWidth && item.h === screenHeight)
      },
      fail(err) {
        console.log(err);
      }
    })

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

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
  },
  globalData: {
    mallList:[],
    picUrl:picUrl,
    ajaxUrl:ajaxUrl,
    userInfo: null,
    pageType: 'mall',
    deploymentType: 'private',
    url: '',
    openTest:false
  }
})
/*
,{
            "root": "pages/tour",
            "name": "tour",
            "pages":[
                "list/index",
                "titem/index",
                "webview/index",
                "video/index"
            ]
        }



*/