App.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <script>
  2. import {
  3. getNewestVersion
  4. } from '@/api/login.js'
  5. import {
  6. validateVersion
  7. } from "@/utils/validateVersion.js"
  8. import {
  9. appInit,
  10. delMsg
  11. } from '@/utils/jpush.js'
  12. export default {
  13. onLaunch: function() {
  14. //#ifdef APP-PLUS
  15. appInit()
  16. // 检测版本更新
  17. uni.getSystemInfo({
  18. success: async (res) => {
  19. // 获取最新版本
  20. const newsetVersionRes = await getNewestVersion().catch(() => {
  21. uni.showModal({
  22. title: '错误',
  23. content: '获取最新系统版本失败。'
  24. })
  25. })
  26. let newsetVersion = newsetVersionRes.data.version;
  27. uni.setStorageSync('visionNow', res.appWgtVersion)
  28. let higherThanNewest = validateVersion(res.appWgtVersion, newsetVersion)
  29. // 如果版本低于服务上的最新版
  30. if (higherThanNewest) {
  31. //检测是否已登录
  32. let token = uni.getStorageSync('App-Token');
  33. if (token) {
  34. uni.switchTab({
  35. url: '/pages/index'
  36. })
  37. }
  38. }
  39. },
  40. fail: () => {
  41. uni.showModal({
  42. title: '错误',
  43. content: '获取当前系统版本失败。'
  44. })
  45. }
  46. })
  47. //#endif
  48. },
  49. onShow: function() {
  50. // console.log('App Show')
  51. },
  52. onHide: function() {
  53. // console.log('App Hide')
  54. },
  55. }
  56. </script>
  57. <style lang="scss">
  58. @import '@/static/scss/index.scss';
  59. page {
  60. height: 100%;
  61. background-color: #EAF1FF;
  62. }
  63. </style>