app.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //app.js
  2. const utils = require('/utils/util.js').Utils; //载入模块
  3. const MyProxy = require('./utils/proxy.js').MyProxy;
  4. App({
  5. /**
  6. * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
  7. */
  8. onLaunch: function() {
  9. new MyProxy(wx, this.watchData)
  10. },
  11. /**
  12. * 当小程序启动,或从后台进入前台显示,会触发 onShow
  13. */
  14. onShow: function(options) {
  15. if (wx.getUpdateManager) {
  16. const updateManager = wx.getUpdateManager();
  17. updateManager.onCheckForUpdate(res => {
  18. if (res.hasUpdate) {
  19. updateManager.onUpdateReady(res => {
  20. wx.showModal({
  21. title: '更新提示',
  22. content: '新版本上线了,请点击确定按钮更新!',
  23. showCancel: false,
  24. success: res => {
  25. if (res.confirm) {
  26. updateManager.applyUpdate()
  27. }
  28. }
  29. })
  30. })
  31. updateManager.onUpdateFailed(res => {
  32. wx.showModal({
  33. title: '更新提示',
  34. content: '新版本已上线,请删除当前小程序,重新搜索进入',
  35. showCancel: false,
  36. })
  37. })
  38. }
  39. })
  40. }
  41. },
  42. /**
  43. * 当小程序从前台进入后台,会触发 onHide
  44. */
  45. onHide: function() {
  46. if (wx.getStorageSync('userinfo').registerFrom === 2) {
  47. } else {
  48. wx.clearStorage();
  49. }
  50. },
  51. /**
  52. * 当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
  53. */
  54. onError: function(msg) {
  55. },
  56. /**
  57. * 工具类
  58. */
  59. utils: new utils(wx),
  60. /**
  61. * 全局变量集合
  62. */
  63. globalData: {
  64. userInfo: null,
  65. phone_zz: /1[0-9]{10}/,
  66. },
  67. /**
  68. * 需要监测的全局变量
  69. */
  70. watchData: {
  71. offline: false
  72. },
  73. })