app.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //app.js
  2. const utils = require('/utils/util.js').Utils; //载入模块
  3. const MyWatch = require('./utils/watch.js').MyWatch;
  4. App({
  5. /**
  6. * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
  7. */
  8. onLaunch: function() {
  9. new MyWatch(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. webview:null
  67. },
  68. /**
  69. * 需要监测的全局变量
  70. */
  71. watchData: {
  72. offline: false
  73. },
  74. })