App.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. let kind = uni.getStorageSync('userKind')
  35. // uni.switchTab({
  36. // url: '/pages/home/companyHome'
  37. // })
  38. // uni.switchTab({
  39. // url: '/pages/home/oversawHome'
  40. // })
  41. uni.switchTab({
  42. url: '/pages/home/headHome'
  43. })
  44. }
  45. }
  46. },
  47. fail: () => {
  48. uni.showModal({
  49. title: '错误',
  50. content: '获取当前系统版本失败。'
  51. })
  52. }
  53. })
  54. //#endif
  55. },
  56. onShow: function() {
  57. // console.log('App Show')
  58. },
  59. onHide: function() {
  60. // console.log('App Hide')
  61. },
  62. }
  63. </script>
  64. <style lang="scss">
  65. @import '@/static/scss/index.scss';
  66. page {
  67. height: 100%;
  68. background-color: #F2F7FF;
  69. }
  70. </style>