App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script>
  2. import Vue from 'vue'
  3. import {
  4. updateMini
  5. } from '@/util/sqma.js'
  6. import {
  7. isWechat
  8. } from '@/util/squ.js'
  9. import { login, LoginAlready, LoginSuccess, LoginUnBind, LoginRedirect } from '@/util/login.js'
  10. import squni from '@/util/squni.js'
  11. import config from '@/common/config.js'
  12. export default {
  13. async onLaunch(e) {
  14. console.log('App onLaunch...')
  15. this.vueStylePrototype()
  16. // #ifdef MP-WEIXIN
  17. this.$store.commit('setPlatform', 'WxMa')
  18. // 微信小程序打开场景
  19. this.$store.commit('setScene', e.scene)
  20. // 微信小程序更新检查
  21. updateMini();
  22. // #endif
  23. // #ifdef H5
  24. this.$store.commit('setPlatform', isWechat() ? 'WxMp' : 'H5')
  25. // #endif
  26. },
  27. async onShow() {
  28. console.log('App onShow...')
  29. // 如果写在onLaunch里面,用户重新进入小程序Token可能过期,需要做Token刷新逻辑
  30. await this.checkReady()
  31. // 保证onLaunch执行完后,再执行页面级别的onShow/onLoad(两个需要分别进行await this.$ready)
  32. this.$emitReady()
  33. },
  34. onHide() {
  35. console.log('App onHide...')
  36. },
  37. methods: {
  38. async checkReady() {
  39. if (config.jumpDefaultBrowser && isWechat()) {
  40. squni.routeWithParams('/pages/main/jump-default-browser')
  41. return
  42. }
  43. // 登录
  44. await login().then(async res => {
  45. if (res === LoginAlready || res === LoginSuccess) {
  46. await this.$store.dispatch('GetUserInfo')
  47. } else if (res === LoginUnBind) {
  48. await this.$store.dispatch('GetUserInfo')
  49. } else if (res === LoginRedirect) {
  50. // do nothing...
  51. } else {
  52. squni.toast((res && res.data && res.data.message) || '登录失败')
  53. }
  54. })
  55. },
  56. vueStylePrototype() {
  57. uni.getSystemInfo({
  58. success: function(e) {
  59. // ====== 顶部导航高度 ======//
  60. // #ifndef MP
  61. Vue.prototype.StatusBar = e.statusBarHeight;
  62. if (e.platform == 'android') {
  63. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  64. } else {
  65. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  66. };
  67. // #endif
  68. // #ifdef MP-WEIXIN
  69. Vue.prototype.StatusBar = e.statusBarHeight;
  70. let custom = wx.getMenuButtonBoundingClientRect();
  71. Vue.prototype.Custom = custom;
  72. Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
  73. // #endif
  74. // #ifdef MP-ALIPAY
  75. Vue.prototype.StatusBar = e.statusBarHeight;
  76. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  77. // #endif
  78. // ====== 可用窗口高度 =====//
  79. // #ifdef MP-WEIXIN
  80. Vue.prototype.AvailableHeight = e.windowHeight + e.statusBarHeight;
  81. // #endif
  82. // #ifdef H5
  83. Vue.prototype.AvailableHeight = e.windowHeight + e.statusBarHeight - Vue.prototype
  84. .CustomBar;
  85. // #endif
  86. }
  87. })
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss">
  93. /*每个页面公共css */
  94. @import "@/uni_modules/colorui/main.css";
  95. @import "@/uni_modules/colorui/icon.css";
  96. // @import "@/uni_modules/uview-ui/index.scss";
  97. @import "common/common.scss";
  98. </style>