app.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. let util = require('./utils/util')
  2. App({
  3. globalData: {},
  4. onLaunch: function() {
  5. this.checkVersion()
  6. },
  7. onShow() {
  8. this.getNavHeight()
  9. },
  10. checkVersion() {
  11. if (!wx.canIUse('getUpdateManager')) return wx.showModal({ title: '提示', content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试' })
  12. const updateManager = wx.getUpdateManager()
  13. updateManager.onCheckForUpdate(res => {
  14. if (res.hasUpdate) {
  15. wx.showModal({
  16. title: '更新提示',
  17. content: '检测到新版本,是否下载新版本并重启小程序',
  18. success: res => {
  19. if (res.confirm) {
  20. util.showLoad('下载中')
  21. updateManager.onUpdateReady(() => {
  22. util.hideLoad()
  23. updateManager.applyUpdate()
  24. })
  25. updateManager.onUpdateFailed(() => {
  26. util.hideLoad()
  27. wx.showModal({ title: '已有新版本', content: '新版本已经上线了,请删除当前小程序,重新搜索打开' })
  28. })
  29. }
  30. }
  31. })
  32. }
  33. })
  34. },
  35. // 获取导航栏高度
  36. getNavHeight() {
  37. const menu_btn = wx.getMenuButtonBoundingClientRect()
  38. wx.getSystemInfo({
  39. success: res => {
  40. const statusBar_h = res.statusBarHeight
  41. const nav_top = menu_btn.top - statusBar_h
  42. const nav_height = statusBar_h + menu_btn.height + nav_top * 2
  43. this.globalData.menuBtnHeight = menu_btn.height
  44. this.globalData.navHeight = nav_height
  45. this.globalData.navTop = nav_top
  46. this.globalData.screenHeight = res.screenHeight
  47. },
  48. fail: () => setTimeout(() => this.getNavHeight(),1000)
  49. })
  50. }
  51. })