| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- //app.js
- const utils = require('/utils/util.js').Utils; //载入模块
- const MyWatch = require('./utils/watch.js').MyWatch;
- App({
- /**
- * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
- */
- onLaunch: function() {
- new MyWatch(wx, this.watchData);
- },
- /**
- * 当小程序启动,或从后台进入前台显示,会触发 onShow
- */
- onShow: function(options) {
- if (wx.getUpdateManager) {
- const updateManager = wx.getUpdateManager();
- updateManager.onCheckForUpdate(res => {
- if (res.hasUpdate) {
- updateManager.onUpdateReady(res => {
- wx.showModal({
- title: '更新提示',
- content: '新版本上线了,请点击确定按钮更新!',
- showCancel: false,
- success: res => {
- if (res.confirm) {
- updateManager.applyUpdate()
- }
- }
- })
- })
- updateManager.onUpdateFailed(res => {
- wx.showModal({
- title: '更新提示',
- content: '新版本已上线,请删除当前小程序,重新搜索进入',
- showCancel: false,
- })
- })
- }
- })
- }
- },
- /**
- * 当小程序从前台进入后台,会触发 onHide
- */
- onHide: function() {
- if (wx.getStorageSync('userinfo').registerFrom === 2) {
- } else {
- wx.clearStorage();
- }
- },
- /**
- * 当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
- */
- onError: function(msg) {
- },
- /**
- * 工具类
- */
- utils: new utils(wx),
- /**
- * 全局变量集合
- */
- globalData: {
- userInfo: null,
- phone_zz: /1[0-9]{10}/,
- webview:null
- },
- /**
- * 需要监测的全局变量
- */
- watchData: {
- offline: false
- },
- })
|