index.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view class="default_head_content">
  3. <!-- 小程序不支持style写computed形式 -->
  4. <view
  5. v-if="needSetStatusBarHeight" class="status_bar_fit" :style="{
  6. 'height': `${statusBarHeight}px`,
  7. 'background-color': `${backgroundColor}`
  8. }"
  9. ></view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'DefaultHead',
  15. props: {
  16. needSetStatusBarHeight: {
  17. type: Boolean,
  18. default: () => true
  19. },
  20. backgroundColor: {
  21. type: String,
  22. default: () => '#fff'
  23. }
  24. },
  25. emits: [ 'getInfoData' ],
  26. data() {
  27. return {
  28. // 系统信息
  29. systemInfo: {},
  30. // 小程序胶囊信息
  31. menuButtonInfo: {
  32. width: 0,
  33. height: 0,
  34. top: 0,
  35. left: 0,
  36. bottom: 0,
  37. right: 0
  38. },
  39. // 手机状态栏高度
  40. statusBarHeight: 0
  41. }
  42. },
  43. mounted() {
  44. this.handleGetSystemInfo()
  45. // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
  46. this.handleGetMenuButtonInfo()
  47. // #endif
  48. this.$emit('getInfoData', {
  49. systemInfo: this.systemInfo,
  50. menuButtonInfo: this.menuButtonInfo
  51. })
  52. },
  53. methods: {
  54. handleGetSystemInfo() {
  55. this.systemInfo = uni.getSystemInfoSync()
  56. this.statusBarHeight = this.systemInfo.statusBarHeight
  57. },
  58. handleGetMenuButtonInfo() {
  59. this.menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  60. }
  61. }
  62. }
  63. </script>
  64. <style
  65. lang="scss"
  66. scoped
  67. >
  68. .default_head_content {
  69. width: 100%;
  70. background: #fff;
  71. .status_bar_fit {
  72. width: 100%;
  73. }
  74. }
  75. </style>