app.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {
  2. wxSetSessionKey
  3. } from "./utils/wxUtils"
  4. App({
  5. onLaunch: function () {
  6. const updateManager = wx.getUpdateManager()
  7. updateManager.onCheckForUpdate(function (res) {
  8. // 请求完新版本信息的回调
  9. })
  10. updateManager.onUpdateReady(function () {
  11. wx.showModal({
  12. title: '更新提示',
  13. content: '新版本已经准备好,是否重启应用?',
  14. success: function (res) {
  15. if (res.confirm) {
  16. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  17. updateManager.applyUpdate()
  18. }
  19. }
  20. })
  21. })
  22. updateManager.onUpdateFailed(function () {
  23. // 新版本下载失败
  24. })
  25. wx.cloud.init({
  26. traceUser: true
  27. })
  28. this.globalData = {
  29. maintab: 1,
  30. currentLab: {}
  31. }
  32. },
  33. onShow() {
  34. this.checkEnvVersion()
  35. },
  36. checkEnvVersion() {
  37. let v = wx.getAccountInfoSync()
  38. let appVersion = wx.getStorageSync('appVersion')
  39. let {
  40. envVersion
  41. } = v.miniProgram
  42. if (appVersion != envVersion) {
  43. wx.clearStorage({
  44. success: (res) => {
  45. wx.setStorageSync('appVersion', envVersion)
  46. wx.redirectTo({
  47. url: '/pages/index/index',
  48. })
  49. },
  50. })
  51. }
  52. wxSetSessionKey()
  53. }
  54. })