App.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <script>
  2. import Vue from 'vue'
  3. export default {
  4. globalData: {
  5. // 全局设置状态栏和导航栏高度
  6. statusBarH: 0,
  7. customBarH: 0,
  8. },
  9. onLaunch: function() {
  10. uni.getSystemInfo({
  11. success: (e) => {
  12. // 获取手机状态栏高度
  13. let statusBar = e.statusBarHeight
  14. let customBar
  15. // #ifndef MP
  16. customBar = statusBar + (e.platform == 'android' ? 50 : 45)
  17. // #endif
  18. // #ifdef MP-WEIXIN
  19. // 获取胶囊按钮的布局位置信息
  20. let menu = wx.getMenuButtonBoundingClientRect()
  21. // 导航栏高度 = 胶囊下距离 + 胶囊上距离 - 状态栏高度
  22. customBar = menu.bottom + menu.top - statusBar
  23. // #endif
  24. // #ifdef MP-ALIPAY
  25. customBar = statusBar + e.titleBarHeight
  26. // #endif
  27. // 注意:此方法不支持原生Nvue页面
  28. Vue.prototype.statusBarH = statusBar
  29. Vue.prototype.customBarH = customBar
  30. // 支持nvue页面写法(兼容H5/小程序/APP/APP-Nvue)
  31. this.globalData.statusBarH = statusBar
  32. this.globalData.customBarH = customBar
  33. }
  34. })
  35. },
  36. onShow: function() {},
  37. onHide: function() {}
  38. }
  39. </script>
  40. <style lang="scss">
  41. /*每个页面公共css */
  42. @import '@/uni_modules/uni-scss/index.scss';
  43. /* #ifndef APP-NVUE */
  44. @import '@/static/customicons.css';
  45. // 设置整个项目的背景色
  46. page {
  47. background-color: #f5f5f5;
  48. }
  49. /* #endif */
  50. .example-info {
  51. font-size: 14px;
  52. color: #333;
  53. padding: 10px;
  54. }
  55. </style>