小程序 app.js 持续添加...

App({
    onLaunch(e){
        // narbar 自定义
        const { statusBarHeight } = wx.getSystemInfoSync();
        const { top, height } = wx.getMenuButtonBoundingClientRect();
        this.globalData.statusBarHeight = statusBarHeight;
        this.globalData.headHeight = (top - statusBarHeight) * 2 + height + statusBarHeight;
        // 版本更新
        if (wx.canIUse("getUpdateManager")){
            const updateManager = wx.getUpdateManager()
            updateManager.onCheckForUpdate(function (res) {
                if(res.hasUpdate){
                    updateManager.onUpdateReady(function () {
                        wx.showModal({
                            title: '更新提示',
                            content: '当前小程序已更新版本,请重启后使用',
                            showCancel:false,
                            success: function (res) {
                                if (res.confirm) {
                                    updateManager.applyUpdate()
                                }
                            }
                        })
                    })
                    updateManager.onUpdateFailed(function () {
                        wx.showModal({
                            title: "新版本提醒",
                            content: "检测到新版本,请您删除当前小程序重新打开!",
                        });
                    })
                }
            })
        }
        //环境
    let env = wx.getAccountInfoSync().miniProgram.envVersion
        if (env === 'develop' || env === 'trial') {
            console.log('开发模式')
            this.globalData.api = ''
        } else {
            console.log('生产模式')
            this.globalData.api = ''
        }
        //监听路由 分享菜单
        wx.onAppRoute(function(res) {
            let pages = getCurrentPages()
            let view = pages[pages.length - 1]
            if(view) {
              wx.showShareMenu({
                withShareTicket:true,
                menus:['shareAppMessage','shareTimeline']
              })
            }
          })
          // 保存当前页
        if (Object.keys(e.query).length > 0) {
            let urlWithArgs = e.path + '?'
            for (let key in e.query) {
                let value = e.query[key]
                urlWithArgs += key + '=' + value + '&'
            }
            urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1)
            wx.setStorage({
                key: "PATH",
                data: urlWithArgs
            })
        } else {
            wx.setStorage({
                key: "PATH",
                data: e.path
            })
        }
        // 跳转过渡页面
        wx.redirectTo({
            url: '/pages/transition/transition',
        })

    },
    globalData: {
        headerHeight: 0,
        statusBarHeight: 0,
        userInfo:{} || {},
        api:null,    
}
})

你可能感兴趣的:(小程序 app.js 持续添加...)