選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

92 行
1.8 KiB

  1. <template>
  2. <view class="ai-nav-title">
  3. <view class="nav-fixed" :style="{ height: totalHeight + 'px' }">
  4. <text
  5. class="nav-title"
  6. :style="{
  7. top: titleTop + 'px',
  8. lineHeight: titleLineHeight + 'px',
  9. fontSize: titleFontSize + 'px'
  10. }"
  11. >
  12. {{ title }}
  13. </text>
  14. </view>
  15. <view class="nav-placeholder" :style="{ height: totalHeight + 'px' }"></view>
  16. </view>
  17. </template>
  18. <script setup>
  19. import { onMounted, ref } from 'vue'
  20. defineProps({
  21. title: {
  22. type: String,
  23. default: ''
  24. }
  25. })
  26. const totalHeight = ref(88)
  27. const titleTop = ref(54)
  28. const titleLineHeight = ref(24)
  29. const titleFontSize = ref(18)
  30. function setNavMetrics() {
  31. const systemInfo = uni.getSystemInfoSync()
  32. const statusBarHeight = systemInfo.statusBarHeight || 0
  33. let menuButton = null
  34. // #ifdef MP-WEIXIN
  35. menuButton = uni.getMenuButtonBoundingClientRect()
  36. // #endif
  37. if (menuButton && menuButton.top && menuButton.height) {
  38. const navPadding = menuButton.top - statusBarHeight
  39. totalHeight.value = menuButton.bottom + navPadding
  40. titleLineHeight.value = Math.min(28, menuButton.height)
  41. titleFontSize.value = 18
  42. titleTop.value = menuButton.top + (menuButton.height - titleLineHeight.value) / 2
  43. return
  44. }
  45. totalHeight.value = statusBarHeight + 44
  46. titleLineHeight.value = 24
  47. titleFontSize.value = 18
  48. titleTop.value = statusBarHeight + 10
  49. }
  50. onMounted(() => {
  51. setNavMetrics()
  52. })
  53. </script>
  54. <style lang="scss" scoped>
  55. .ai-nav-title {
  56. position: relative;
  57. z-index: 90;
  58. }
  59. .nav-fixed {
  60. position: fixed;
  61. top: 0;
  62. left: 0;
  63. right: 0;
  64. z-index: 90;
  65. background: #ffffff;
  66. box-sizing: border-box;
  67. }
  68. .nav-title {
  69. position: absolute;
  70. left: 30rpx;
  71. color: #333333;
  72. font-weight: 700;
  73. white-space: nowrap;
  74. }
  75. .nav-placeholder {
  76. width: 100%;
  77. background: #ffffff;
  78. }
  79. </style>