navbar.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="test-container">
  3. <!-- 自定义导航栏 -->
  4. <NavBar title="导航栏测试" :show-back="true" />
  5. <view class="content" :style="{ paddingTop: navBarHeight + 'px' }">
  6. <view class="info-card">
  7. <text class="title">胶囊按钮信息</text>
  8. <view class="info-item" v-if="capsuleInfo">
  9. <text class="label">Top:</text>
  10. <text class="value">{{ capsuleInfo.top }} px</text>
  11. </view>
  12. <view class="info-item" v-if="capsuleInfo">
  13. <text class="label">Height:</text>
  14. <text class="value">{{ capsuleInfo.height }} px</text>
  15. </view>
  16. <view class="info-item" v-if="capsuleInfo">
  17. <text class="label">Width:</text>
  18. <text class="value">{{ capsuleInfo.width }} px</text>
  19. </view>
  20. <view class="info-item" v-if="capsuleInfo">
  21. <text class="label">Left:</text>
  22. <text class="value">{{ capsuleInfo.left }} px</text>
  23. </view>
  24. <view class="info-item" v-if="capsuleInfo">
  25. <text class="label">Right:</text>
  26. <text class="value">{{ capsuleInfo.right }} px</text>
  27. </view>
  28. <text class="title" style="margin-top: 32rpx;">状态栏信息</text>
  29. <view class="info-item">
  30. <text class="label">状态栏高度:</text>
  31. <text class="value">{{ statusBarHeight }} px</text>
  32. </view>
  33. <text class="title" style="margin-top: 32rpx;">导航栏信息</text>
  34. <view class="info-item">
  35. <text class="label">导航栏总高度:</text>
  36. <text class="value">{{ navBarHeight }} px</text>
  37. </view>
  38. </view>
  39. <view class="tips">
  40. <text class="tips-title">💡 提示信息</text>
  41. <text class="tips-text">1. 如果看不到胶囊信息,请检查是否在微信小程序中运行</text>
  42. <text class="tips-text">2. H5 端不会显示胶囊按钮</text>
  43. <text class="tips-text">3. 检查 pages.json 中是否设置了 navigationStyle: custom</text>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script setup>
  49. import { ref, computed, onMounted } from 'vue'
  50. import NavBar from '@/components/nav-bar/index.vue'
  51. const capsuleInfo = ref(null)
  52. const statusBarHeight = ref(0)
  53. const navBarHeight = computed(() => {
  54. if (!capsuleInfo.value) return 44
  55. return statusBarHeight.value + capsuleInfo.value.height
  56. })
  57. onMounted(() => {
  58. // #ifdef MP-WEIXIN
  59. const menuInfo = uni.getMenuButtonBoundingClientRect()
  60. capsuleInfo.value = menuInfo
  61. const systemInfo = uni.getSystemInfoSync()
  62. statusBarHeight.value = systemInfo.statusBarHeight || 0
  63. console.log('✅ 胶囊信息获取成功:', menuInfo)
  64. console.log('✅ 状态栏高度:', statusBarHeight.value)
  65. // #endif
  66. // #ifndef MP-WEIXIN
  67. console.log('⚠️ 非微信小程序环境,无法获取胶囊信息')
  68. // #endif
  69. })
  70. </script>
  71. <style lang="scss" scoped>
  72. .test-container {
  73. min-height: 100vh;
  74. background: #f5f6f8;
  75. }
  76. .content {
  77. padding: 20rpx;
  78. .info-card {
  79. background: #ffffff;
  80. border-radius: 16rpx;
  81. padding: 32rpx;
  82. margin-bottom: 20rpx;
  83. .title {
  84. font-size: 32rpx;
  85. font-weight: 600;
  86. color: #333333;
  87. display: block;
  88. margin-bottom: 24rpx;
  89. }
  90. .info-item {
  91. display: flex;
  92. justify-content: space-between;
  93. padding: 16rpx 0;
  94. border-bottom: 1rpx solid #f0f0f0;
  95. &:last-child {
  96. border-bottom: none;
  97. }
  98. .label {
  99. font-size: 28rpx;
  100. color: #999999;
  101. }
  102. .value {
  103. font-size: 28rpx;
  104. color: #333333;
  105. font-weight: 500;
  106. }
  107. }
  108. }
  109. .tips {
  110. background: linear-gradient(135deg, #fff5e6 0%, #ffe8cc 100%);
  111. border-radius: 16rpx;
  112. padding: 32rpx;
  113. .tips-title {
  114. font-size: 28rpx;
  115. font-weight: 600;
  116. color: #ff9500;
  117. display: block;
  118. margin-bottom: 16rpx;
  119. }
  120. .tips-text {
  121. font-size: 24rpx;
  122. color: #666666;
  123. display: block;
  124. line-height: 1.8;
  125. }
  126. }
  127. }
  128. </style>