app.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. App({
  2. onLaunch: function () {
  3. //获取小程序更新机制兼容
  4. if (wx.canIUse('getUpdateManager')) {
  5. const updateManager = wx.getUpdateManager()
  6. updateManager.onCheckForUpdate(function (res) {
  7. // 请求完新版本信息的回调
  8. if (res.hasUpdate) {
  9. updateManager.onUpdateReady(function () {
  10. wx.showModal({
  11. title: '更新提示',
  12. content: '新版本已经准备好,是否重启应用?',
  13. success: function (res) {
  14. if (res.confirm) {
  15. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  16. updateManager.applyUpdate()
  17. }
  18. }
  19. })
  20. })
  21. updateManager.onUpdateFailed(function () {
  22. // 新的版本下载失败
  23. wx.showModal({
  24. title: '已经有新版本了哟~',
  25. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
  26. })
  27. })
  28. }
  29. })
  30. } else {
  31. // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
  32. wx.showModal({
  33. title: '提示',
  34. content: '当前微信版本过低,无法更好体验程序,请升级到最新微信版本后重试。'
  35. })
  36. }
  37. },
  38. globalData: {
  39. userInfo: {
  40. nickName: 'Hi,游客',
  41. userName: '点击去登录',
  42. avatarUrl: 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
  43. },
  44. token: '',
  45. userCoupon: 'NO_USE_COUPON',//默认不适用优惠券
  46. courseCouponCode: {},//购买课程的时候优惠券信息
  47. },
  48. // 下拉刷新
  49. onPullDownRefresh: function () {
  50. // 显示顶部刷新图标
  51. wx.showNavigationBarLoading();
  52. var that = this;
  53. // 隐藏导航栏加载框
  54. wx.hideNavigationBarLoading();
  55. // 停止下拉动作
  56. wx.stopPullDownRefresh();
  57. },
  58. // 更新小程序
  59. updateManager: function () {
  60. //获取系统信息 客户端基础库
  61. wx.getSystemInfo({
  62. success: function (res) {
  63. //基础库版本比较,版本更新必须是1.9.90以上
  64. const v = util.compareVersion(res.SDKVersion, '1.9.90');
  65. if (v > 0) {
  66. const manager = wx.getUpdateManager();
  67. manager.onCheckForUpdate(function (res) {
  68. // 请求完新版本信息的回调
  69. //console.log(res.hasUpdate);
  70. });
  71. manager.onUpdateReady(function () {
  72. wx.showModal({
  73. title: '更新提示',
  74. content: '新版本已经准备好,是否重启应用?',
  75. success: function (res) {
  76. if (res.confirm) {
  77. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  78. manager.applyUpdate();
  79. }
  80. }
  81. })
  82. });
  83. manager.onUpdateFailed(function () {
  84. // 新的版本下载失败
  85. });
  86. } else {
  87. // wx.showModal({
  88. // title: '温馨提示',
  89. // content: '当前微信版本过低,无法更好体验程序,请升级到最新微信版本后重试。'
  90. // })
  91. }
  92. },
  93. })
  94. }
  95. })