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.

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