app.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //app.js
  2. const utils = require('/utils/util.js').Utils; //载入模块
  3. App({
  4. /**
  5. * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
  6. */
  7. onLaunch: function() {
  8. },
  9. /**
  10. * 当小程序启动,或从后台进入前台显示,会触发 onShow
  11. */
  12. onShow: function(options) {
  13. if (wx.getUpdateManager) {
  14. const updateManager = wx.getUpdateManager();
  15. updateManager.onCheckForUpdate(res => {
  16. if (res.hasUpdate) {
  17. updateManager.onUpdateReady(res => {
  18. wx.showModal({
  19. title: '更新提示',
  20. content: '新版本上线了,重启应用更新!',
  21. showCancel: false,
  22. success: res => {
  23. if (res.confirm) {
  24. updateManager.applyUpdate()
  25. }
  26. }
  27. })
  28. })
  29. updateManager.onUpdateFailed(res => {
  30. wx.showModal({
  31. title: '更新提示',
  32. content: '新版本已上线,请删除当前小程序,重新搜索进入',
  33. showCancel: false,
  34. })
  35. })
  36. }
  37. })
  38. }
  39. },
  40. /**
  41. * 当小程序从前台进入后台,会触发 onHide
  42. */
  43. onHide: function() {
  44. },
  45. /**
  46. * 当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息
  47. */
  48. onError: function(msg) {
  49. },
  50. utils: new utils(wx),
  51. globalData: {
  52. userInfo: null,
  53. phone_zz: /1[0-9]{10}/
  54. },
  55. })