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-barNew.vue 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="nav-bar" :class="scrollTop>navHeight?navbgClass:''" :style="{height:navHeight+'px',color:fontColor}">
  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-white.png`" :style="{height:searchHeight+'px',width:searchHeight+'px'}"
  7. class="back" @click="back(title,type,userType,orderId)"></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 { msg } from "@/utils/utils";
  16. import {
  17. onMounted,
  18. ref
  19. } from "vue";
  20. const navHeight = ref(0)
  21. const searchMarginTop = ref(0)
  22. const searchHeight = ref(0)
  23. const searchWidth = ref(0)
  24. const isAlipay = ref(false)
  25. onMounted(() => {
  26. const type = uni.getSystemInfoSync().uniPlatform
  27. isAlipay.value = type === 'mp-alipay'
  28. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  29. const {
  30. top,
  31. width,
  32. height,
  33. right
  34. } = menuButtonInfo
  35. uni.getSystemInfo({
  36. success: (res) => {
  37. const {
  38. statusBarHeight
  39. } = res
  40. const margin = top - statusBarHeight
  41. navHeight.value = (height + statusBarHeight + (margin * 2)) //导航栏总高
  42. searchMarginTop.value = statusBarHeight + margin // 状态栏 + 胶囊按钮边距
  43. searchHeight.value = height // 与胶囊按钮同高
  44. searchWidth.value = right - width // 胶囊按钮右边坐标 - 胶囊按钮宽度 = 按钮左边可使用宽度
  45. },
  46. })
  47. })
  48. const props = defineProps({
  49. title: {
  50. type: String,
  51. default: ''
  52. },
  53. orderId: {
  54. type: String,
  55. default: ''
  56. },
  57. type: {
  58. type: String,
  59. default: ''
  60. },
  61. userType: {
  62. type: String,
  63. default: ''
  64. },
  65. isBack: {
  66. type: Boolean,
  67. default: true
  68. },
  69. scrollTop: {
  70. type: Number,
  71. default: 0
  72. },
  73. navbgClass: {
  74. type: String,
  75. default: 'nav-bg'
  76. },
  77. fontColor: {
  78. type: String,
  79. default: '#000'
  80. },
  81. })
  82. const back = () => {
  83. uni.navigateBack({
  84. delta: 1
  85. })
  86. }
  87. </script>
  88. <style scoped>
  89. .nav-bg {
  90. background: #01243A;
  91. }
  92. .nav-bgXin {
  93. background: #01243A;
  94. color:#fff;
  95. }
  96. .blank {
  97. width: 100%;
  98. display: none;
  99. }
  100. .nav-bar {
  101. position: fixed;
  102. width: 100%;
  103. z-index: 999;
  104. }
  105. .nav-bar .title {
  106. text-align: center;
  107. width: 100%;
  108. font-size: 28rpx;
  109. font-weight: bold;
  110. position: relative;
  111. color: white;
  112. }
  113. .back {
  114. position: absolute;
  115. left: 10rpx;
  116. }
  117. </style>