App.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <script>
  2. import config from './config'
  3. import store from '@/store'
  4. import { getToken } from '@/utils/auth'
  5. import "@/static/iconfont.css";
  6. export default {
  7. onLaunch: function() {
  8. this.initApp()
  9. },
  10. methods: {
  11. // 初始化应用
  12. initApp() {
  13. // 初始化应用配置
  14. this.initConfig()
  15. // 检查用户登录状态
  16. //#ifdef H5
  17. this.checkLogin()
  18. //#endif
  19. this.updateManager();
  20. },
  21. initConfig() {
  22. this.globalData.config = config
  23. },
  24. /**
  25. * 小程序主动更新
  26. */
  27. updateManager() {
  28. const updateManager = uni.getUpdateManager();
  29. updateManager.onCheckForUpdate(res => {
  30. // 请求完新版本信息的回调
  31. // console.log(res.hasUpdate)
  32. })
  33. updateManager.onUpdateReady(() => {
  34. uni.showModal({
  35. title: '更新提示',
  36. content: '新版本已经准备好,即将重启应用',
  37. showCancel: false,
  38. success(res) {
  39. if (res.confirm) {
  40. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  41. updateManager.applyUpdate()
  42. }
  43. }
  44. })
  45. })
  46. updateManager.onUpdateFailed(() => {
  47. // 新的版本下载失败
  48. uni.showModal({
  49. title: '更新提示',
  50. content: '新版本下载失败',
  51. showCancel: false
  52. })
  53. })
  54. },
  55. checkLogin() {
  56. if (!getToken()) {
  57. this.$tab.reLaunch('/pages/login')
  58. }
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss">
  64. @import '@/static/scss/index.scss'
  65. </style>