Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view class="nav-bar" :class="scrollTop>navHeight?'nav-bg':''" :style="{height:navHeight+'px'}">
  3. <view class="title" :style="{paddingTop:searchMarginTop+'px',height:searchHeight+'px',lineHeight:searchHeight+'px'}">
  4. <block v-if="isBack">
  5. <image :src="`/static/image/icon-back.png`"
  6. :style="{height:searchHeight+'px',width:searchHeight+'px'}" class="back" @click="back"></image>
  7. </block>
  8. <text>{{title}}</text>
  9. </view>
  10. </view>
  11. <view class="blank" :style="{height:navHeight+'px'}"></view>
  12. </template>
  13. <script setup lang="ts">
  14. import {
  15. onMounted,
  16. ref
  17. } from "vue";
  18. const navHeight = ref(0)
  19. const searchMarginTop = ref(0)
  20. const searchHeight = ref(0)
  21. const searchWidth = ref(0)
  22. onMounted(() => {
  23. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  24. const {
  25. top,
  26. width,
  27. height,
  28. right
  29. } = menuButtonInfo
  30. uni.getSystemInfo({
  31. success: (res) => {
  32. const {
  33. statusBarHeight
  34. } = res
  35. const margin = top - statusBarHeight
  36. navHeight.value = (height + statusBarHeight + (margin * 2)) //导航栏总高
  37. searchMarginTop.value = statusBarHeight + margin // 状态栏 + 胶囊按钮边距
  38. searchHeight.value = height // 与胶囊按钮同高
  39. searchWidth.value = right - width // 胶囊按钮右边坐标 - 胶囊按钮宽度 = 按钮左边可使用宽度
  40. },
  41. })
  42. })
  43. const props = defineProps({
  44. title: {
  45. type: String,
  46. default: ''
  47. },
  48. isBack: {
  49. type: Boolean,
  50. default: true
  51. },
  52. scrollTop:{
  53. type:Number,
  54. default:0
  55. }
  56. })
  57. const back = () => {
  58. uni.navigateBack({
  59. delta: 1
  60. })
  61. }
  62. </script>
  63. <style scoped>
  64. .nav-bg{
  65. background: linear-gradient(to right,#13E7C1,#43A1E0);
  66. }
  67. .blank {
  68. width: 100%;
  69. display: none;
  70. }
  71. .nav-bar {
  72. /* background: linear-gradient(to left, #43A1E0 0%, #13E7C1 100%); */
  73. position: fixed;
  74. width: 100%;
  75. z-index: 999;
  76. }
  77. .nav-bar .title {
  78. text-align: center;
  79. width: 100%;
  80. font-size: 28rpx;
  81. font-weight: bold;
  82. position: relative;
  83. }
  84. .back {
  85. position: absolute;
  86. left: 10rpx;
  87. }
  88. </style>