var http = require("/utils/config.js"); App({ onLaunch: function () { // 登录 console.log(http) var that = this; wx.getSystemInfo({ success: res => { console.log(res) var system = res.system.trim().split(/\s+/)[1]; var intNumber = system.substring(0, system.indexOf(".")); if (res.platform == 'ios' && intNumber < 13 || res.SDKVersion<'2.1.0') { console.log('低版本') that.globalData.compatible = true; wx.reLaunch({ url: '/pages/compatible/index/index', }) } else { console.log('高版本') that.globalData.compatible = false; wx.reLaunch({ url: '/pages/index/index', }) } that.globalData.platform = res.platform that.globalData.version = res.version console.log(res.safeArea.bottom) console.log('手机信息res' + res.model) if (res.model == 'iPhone X' || res.model == 'iPhone XR' || res.model == 'iPhone XS Max') { that.globalData.screenHeight = 'xSeries' } else if (res.safeArea.bottom >= 780) { that.globalData.screenHeight = 'xSeries' } } }) if (wx.getStorageSync('midTimes') != '') { var time = wx.getStorageSync('midTimes'); var timestamp = Date.parse(new Date()) / 1000; if (time <= timestamp) { console.log('midtimes过期') wx.setStorageSync('midTimes', '') } } var imgArr = wx.getStorageSync('imgUrl'); if (imgArr == undefined || imgArr == '') { var imgUrl = ['weilaibike.com/xiaobanma/mineBg.png', 'weilaibike.com/xiaobanma/walletBg.png', 'weilaibike.com/xiaobanma/moneyBg.png']; wx.setStorageSync('imgUrl', imgUrl) } var time = wx.getStorageSync('token_time'); var timestamp = Date.parse(new Date()); if (time <= timestamp / 1000) { console.log('token过期') wx.removeStorageSync('token_time') } if (wx.canIUse('getUpdateManager')) { const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { if (res.hasUpdate) { updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function (res) { if (res.confirm) { updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { wx.showModal({ title: '已经有新版本了哟~', content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' }) }) } }) } else { wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' }) } }, globalData: { statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'], windowHeight: wx.getSystemInfoSync()['windowHeight'], localUrl: http.url, screenHeight: '', login: false, platform: '', version: '', req: true, id: 0, times: 60, invalid: false, compatible: '' }, request(api, params, method, req1) { var that = this; // console.log(req1) if (req1 == false) return; if (req1) { that.globalData.req = false; } if (wx.getStorageSync('token') != '' || wx.getStorageSync('token') != undefined) { if (req1 == true || req1 == undefined) { return new Promise((resolve, reject) => { wx.request({ url: this.globalData.localUrl + api, data: params, header: { 'content-type': 'application/x-www-form-urlencoded', 'Authorization': wx.getStorageSync('token'), }, method: method, success: (res) => { resolve(res) if (res.statusCode == 450) { return; } if (res.data.statusCode != 200) { if (res.data.message == '订单不存在或订单已结算') { if (this.globalData.compatible) { wx.reLaunch({ url: '/pages/compatible/index/index', }) } else { wx.reLaunch({ url: '/pages/index/index', }) } return false; } else if (res.data.message == '运动中不能关锁') { return false; } if (res.message != undefined) { wx.showToast({ title: res.message, icon: 'none', duration: 3000, mask: true }) } else if (res.data.message != undefined) { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000, mask: true }) } } else if (res.statusCode != 200) { if (res.data.message == '订单不存在或订单已结算') { if (this.globalData.compatible) { wx.reLaunch({ url: '/pages/compatible/index/index', }) } else { wx.reLaunch({ url: '/pages/index/index', }) } return false; } else if (res.data.message == '运动中不能关锁') { return false; } if (res.message != undefined) { wx.showToast({ title: res.message, icon: 'none', duration: 3000, mask: true }) } else if (res.data.message != undefined) { wx.showToast({ title: res.data.message, icon: 'none', duration: 3000, mask: true }) } } if (res.statusCode == 401) { var timeout; wx.removeStorageSync('token') wx.removeStorageSync('token_time') that.globalData.invalid = true console.log(that.globalData.login) if (that.globalData.login) { return false; } if (that.globalData.login == false) { that.globalData.login = true wx.showToast({ title: '登陆过期请重新登陆~', icon: 'none', duration: 1000, mask: true, success: function () { wx.reLaunch({ url: '/pages/authentication/authentication', }) } }) timeout = setTimeout(function () { that.globalData.login = false if (that.globalData.login == false) { clearTimeout(timeout) } }, 3000) } } else if (res.statusCode == 404) { wx.navigateTo({ url: '/pages/undefind/undefind', }) } }, fail: (err) => { wx.showToast({ title: err, icon: 'none', mask: true }); reject("请求失败") }, complete: () => { that.globalData.req = true } }) }) } } }, })