App.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script>
  2. import Vue from 'vue'
  3. import { changeNetworkType } from 'common/utils/changeData.js'
  4. import { NO_NETWORK_TEXT } from 'common/utils/systemConst.js'
  5. export default {
  6. onLaunch: function () {
  7. // 这里是设置宽度高度的
  8. uni.getSystemInfo({
  9. success: function (e) {
  10. Vue.prototype.windowHeight = e.windowHeight
  11. Vue.prototype.windowWidth = e.windowWidth
  12. Vue.prototype.platform = e.platform
  13. // #ifndef MP
  14. Vue.prototype.StatusBar = e.statusBarHeight
  15. if (e.platform === 'android') {
  16. Vue.prototype.globalCustomBarHeight = e.statusBarHeight + 50
  17. } else {
  18. Vue.prototype.globalCustomBarHeight = e.statusBarHeight + 45
  19. }
  20. // #endif
  21. // #ifdef MP-WEIXIN
  22. Vue.prototype.StatusBar = e.statusBarHeight
  23. // eslint-disable-next-line no-undef
  24. const custom = wx.getMenuButtonBoundingClientRect()
  25. Vue.prototype.Custom = custom
  26. Vue.prototype.globalCustomBarHeight = custom.bottom + custom.top - e.statusBarHeight
  27. // #endif
  28. // #ifdef MP-ALIPAY
  29. Vue.prototype.StatusBar = e.statusBarHeight
  30. Vue.prototype.globalCustomBarHeight = e.statusBarHeight + e.titleBarHeight
  31. // #endif
  32. }
  33. })
  34. // app 初始化数据
  35. this.$store.dispatch('initAppData')
  36. },
  37. onShow: function () {
  38. // 监听网络 start
  39. if (!this.networkListenFlag || this.networkListenFlag === false) {
  40. uni.onNetworkStatusChange(res => {
  41. Vue.prototype.networkListenFlag = true // 监听网络变化注册成功,无需重复注册
  42. this.changeNetworkType(this.$store, res.networkType)
  43. if (res.networkType === 'none') {
  44. uni.showToast({
  45. title: NO_NETWORK_TEXT,
  46. icon: 'none'
  47. })
  48. }
  49. })
  50. }
  51. // 监听网络 end
  52. // 查看网络类型
  53. // wifi wifi 网络
  54. // 2g 2g 网络
  55. // 3g 3g 网络
  56. // 4g 4g 网络
  57. // ethernet 有线网络 App
  58. // unknown Android 下不常见的网络类型
  59. // none 无网络
  60. uni.getNetworkType({
  61. success: res => {
  62. this.changeNetworkType(this.$store, res.networkType)
  63. if (res.networkType === 'none') {
  64. uni.showToast({
  65. title: NO_NETWORK_TEXT,
  66. icon: 'none'
  67. })
  68. }
  69. }
  70. })
  71. },
  72. onHide: function () {
  73. console.log('App Hide')
  74. },
  75. methods: {
  76. changeNetworkType
  77. }
  78. }
  79. </script>
  80. <style>
  81. @import '/common/colorui/main.css';
  82. @import '/common/colorui/icon.css';
  83. /* @import "/common/colorui/animation.css"; */
  84. @import '/common/css/common.css';
  85. </style>