/** 每次系统加载的时候判断是否有发版 */ export function checkUpgrade() { if (wx.canIUse('getUpdateManager')) { const updateManager = wx.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { if (res.hasUpdate) { // 弹出提示框,提示用户更新并重启小程序 updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', showCancel: false, confirmText: '马上重启', content: '新版本已经上线,需要您重启小程序以应用新版本。', success: function (res) { if (res.confirm) { // 调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate(); } } }); }); // 新版本下载失败时弹出提示框 updateManager.onUpdateFailed(function () { wx.showModal({ title: '更新失败', content: '新版本下载失败,请删除当前小程序,重新搜索打开。', }); }); } }); } else { // 如果用户微信版本过低,则弹出提示框 wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。', }); } } /** 根据不同环境获取不同参数 */ export function getConfigByEnv() { const result = wx.getAccountInfoSync(); const { envVersion } = result.miniProgram; let api = "" switch (envVersion) { // 开发版 case 'develop': api = "http://localhost:8000" break; // 体验版 case 'trial': break; // 正式版 case 'release': break; } return { api, } } /** 获取app.js中的globalData数据 */ export function getGlobalData() { const app = getApp(); return app.globalData; }