App.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script>
  2. import Vue from 'vue'
  3. // import app from './utils/api.js'
  4. export default {
  5. onLaunch: function() {
  6. uni.getSystemInfo({
  7. success: function (res) {
  8. Vue.prototype.screenHeight=res.screenHeight
  9. Vue.prototype.screenWidth=res.screenWidth
  10. console.log(res);
  11. const tabBarHeight = res.screenHeight - res.windowHeight;
  12. Vue.prototype.tabBarHeight=tabBarHeight
  13. if (uni.getMenuButtonBoundingClientRect()) {
  14. console.log('小程序');
  15. // 小程序状态栏是指显示电量的那一小部分
  16. thisWechat(res.statusBarHeight)
  17. }else{
  18. console.log('app');
  19. thisApp(res.statusBarHeight)
  20. }
  21. }
  22. });
  23. function thisWechat(statusBarHeight){
  24. // 获取胶囊位置
  25. let meunButtonInfo=uni.getMenuButtonBoundingClientRect()
  26. // console.log(meunButtonInfo);
  27. Vue.prototype.meunButtonInfo=meunButtonInfo.height
  28. // 计算出导航栏高度+动态栏
  29. let allHeight = meunButtonInfo.bottom + (meunButtonInfo.top - statusBarHeight )*2;
  30. // console.log(allHeight);
  31. let navheight;
  32. Vue.prototype.navheight=allHeight
  33. // 按钮离顶
  34. let alltop = meunButtonInfo.top
  35. Vue.prototype.navTop=alltop
  36. // 动态栏高度
  37. let statusHeight
  38. Vue.prototype.statusHeight=statusBarHeight
  39. };
  40. function thisApp(statusBarHeight){
  41. // console.log(uni.getSystemInfoSync());
  42. // 导航栏高度
  43. // let appAllHeight;console.log();
  44. // Vue.prototype.appAllHeight=statusBarHeight+44+'px';
  45. // console.log(statusBarHeight);
  46. let customBarHeight;
  47. if (uni.getSystemInfoSync().platform === 'android') {
  48. customBarHeight = statusBarHeight + 50;
  49. } else if (uni.getSystemInfoSync().platform === 'ios') {
  50. // iOS 平台
  51. // 在这里根据 iOS 平台的特性计算自定义状态栏高度
  52. // ...
  53. customBarHeight = statusBarHeight + 45;
  54. } else {
  55. // 其他平台
  56. // ...
  57. customBarHeight = statusBarHeight;
  58. }
  59. // console.log(customBarHeight);
  60. Vue.prototype.customBar = customBarHeight;
  61. }
  62. },
  63. onLoad() {
  64. }
  65. }
  66. </script>
  67. <style>
  68. /*每个页面公共css */
  69. body{
  70. background-color: #f0f2f5;
  71. }
  72. view{
  73. box-sizing: border-box;
  74. padding: 0;
  75. }
  76. </style>