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.

nav-bar.vue 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 && !isAlipay">
  6. <image :src="`/static/image/icon-back.png`" mode="aspectFill"
  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. const isAlipay = ref(false)
  24. onMounted(() => {
  25. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  26. const type = uni.getSystemInfoSync().uniPlatform
  27. isAlipay.value = type === 'mp-alipay'
  28. const {
  29. top,
  30. width,
  31. height,
  32. right
  33. } = menuButtonInfo
  34. uni.getSystemInfo({
  35. success: (res) => {
  36. const {
  37. statusBarHeight
  38. } = res
  39. const margin = top - statusBarHeight
  40. navHeight.value = (height + statusBarHeight + (margin * 2)) //导航栏总高
  41. searchMarginTop.value = statusBarHeight + margin // 状态栏 + 胶囊按钮边距
  42. searchHeight.value = height // 与胶囊按钮同高
  43. searchWidth.value = right - width // 胶囊按钮右边坐标 - 胶囊按钮宽度 = 按钮左边可使用宽度
  44. },
  45. })
  46. })
  47. const props = defineProps({
  48. title: {
  49. type: String,
  50. default: ''
  51. },
  52. isBack: {
  53. type: Boolean,
  54. default: true
  55. }
  56. })
  57. const back = () => {
  58. uni.navigateBack({
  59. delta: 1
  60. })
  61. }
  62. </script>
  63. <style scoped>
  64. .blank {
  65. width: 100%;
  66. }
  67. .nav-bar {
  68. background: linear-gradient(to left, #43A1E0 0%, #13E7C1 100%);
  69. position: fixed;
  70. width: 100%;
  71. z-index: 999;
  72. }
  73. .nav-bar .title {
  74. text-align: center;
  75. width: 100%;
  76. font-size: 28rpx;
  77. font-weight: bold;
  78. position: relative;
  79. }
  80. .back {
  81. position: absolute;
  82. left: 10rpx;
  83. }
  84. </style>