多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.7 KiB

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