import log from './commons/js/utils/log' App({ onLaunch: function () { let that = this; this.updateVersion() wx.getSystemInfo({ success(res) { that.globalData.statusBarHeight = res.statusBarHeight; that.globalData.screenHeight = res.screenHeight; that.globalData.screenWidth = res.screenWidth; if (res.platform == "devtools") { that.globalData.platform = "android"; } else { that.globalData.platform = res.platform } } }) wx.onMemoryWarning(function () { let getPath = getCurrentPages() let currentPage = getPath[getPath.length - 1] wx.reportAnalytics('outofmemory', { pages: getPath, //获取所有页面 url: currentPage.route, //当前页面url options: currentPage.options //如果要获取url中所带的参数可以查看options }) that.printErrorClient('filteroutofmemory') wx.reportMonitor('0', 500) wx.reLaunch(currentPage.route) }) }, onHide: function () { if (wx.canIUse('offMemoryWarning')) { wx.offMemoryWarning() // this.printErrorClient('offmemory') } else { this.printErrorClient('offmemorylowversion') console.warn('当前微信版本' + wx.getSystemInfoSync().SDKVersion + '过低,无法使用该功能,请升级到最新微信版本后重试。') } }, onPageNotFound(res) { this.printErrorClient('404notfound',['错误信息:'+JSON.stringify(res)]) if (res.path == 'pages/detail/detail') { this.errorPageRedirect('/pages/index/index', '抱歉,该页面已迁移,请在搜索页查询...') } else if (res.path == 'pages/card/card' || res.path == 'pages/mine/mine') { console.log(1) this.errorPageRedirect('/pages/mine/index') } else { this.errorPageRedirect('/pages/index/index', '抱歉,该页面无法访问,正在回到首页...') } }, initNum: 0, globalData: { loginRuning: false, loginCollect: [], userInfo: '', location: '', ukey: "", statusBarHeight: 20, screenHeight: 0, screenWidth: 0, platform: '', }, setStorage: function (key, data, callback = function () {}, reject = function () {}) { try { wx.setStorageSync(key, data); this.globalData[key] = data; // console.log(`Method:setStorage(success)`); callback(data) } catch (e) { reject(e) } }, getStorageByKey: function (key) { var storage; if (!!this.globalData[key]) { return this.globalData[key]; } else { try { const value = wx.getStorageSync(key) if (value) { storage = value; return storage; } } catch (e) { console.warn("getStorageByKey-fail:" + key); } } return !!storage ? storage : ""; }, errorPageRedirect(URL, TITLE = '正在跳转,请稍候...') { wx.showToast({ title: TITLE, icon: 'none', duration: 2000, success: function () { setTimeout(function () { wx.reLaunch({ url: URL }) }, 2000) } }) }, /** * 打印客户端信息 */ printErrorClient(MSGNAME, ER = []) { log.setFilterMsg(MSGNAME) let pages = getCurrentPages() //获取加载的页面 if(pages.length>0){ let currentPage = pages[pages.length - 1] //获取当前页面的对象 log.warn('当前页面:' + currentPage.route) log.info('路径:' + JSON.stringify(pages)) }else{ log.warn('当前页面不在app.json列表里') } let systemInfo = wx.getSystemInfoSync() log.info('设备型号:' + systemInfo.model) log.info('微信版本号:' + systemInfo.version) log.info('操作系统及版本:' + systemInfo.system) log.info('客户端平台:' + systemInfo.platform) log.info('客户端基础库版本:' + systemInfo.SDKVersion) log.info('地理位置的系统开关:' + systemInfo.locationEnabled) log.info('客户端Ukey:' + wx.getStorageSync('ukey')) log.info('客户端Userinfo:' + JSON.stringify(wx.getStorageSync('userInfo'))) for(let i =0;i