App.vue 2.9 KB

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