// app.js const $api = require('./utils/api').API; App({ onLaunch() { // 监听更新版本 if (wx.canIUse('getUpdateManager')) { const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 if (res.hasUpdate) { console.log('res.hasUpdate====') updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function (res) { console.log('success====', res) // res: {errMsg: "showModal: ok", cancel: false, confirm: true} if (res.confirm) { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { // 新的版本下载失败 wx.showModal({ title: '已经有新版本了哟~', content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' }) }) } }) } }, queryUsreInfo() { $api.getUserInfo().then(res => { if (res.code === 0) { wx.setStorageSync('userInfo', res.data.sysUser) } }) }, globalData: { userInfo: null } }) ! function () { //获取页面配置并进行页面分享配置 var PageTmp = Page Page = function (pageConfig) { //1. 获取当前页面路由 let routerUrl = "" wx.onAppRoute(function (res) { //app.js中需要在隐式路由中才能用getCurrentPages()获取到页面路由 let pages = getCurrentPages(), view = pages[pages.length - 1]; routerUrl = view.route }) //2. 全局开启分享配置 pageConfig = Object.assign({ onShareAppMessage: function () { //根据不同路由设置不同分享内容(微信小程序分享自带参数,如非特例,不需配置分享路径) return {} }, onShareTimeline() { return {} } }, pageConfig); // 配置页面模板 PageTmp(pageConfig); } }();