my-nav.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view>
  3. <view class="nav-box" :style="{'height':height+'px','background':bgColor}">
  4. <!-- 自定义导航栏 -->
  5. <view class="status_bar" :style="{'height':statusBarHeight+'px'}">
  6. <!-- uni-ui这里是状态栏 -->
  7. </view>
  8. <!-- 胶囊位置信息 -->
  9. <view class="nav-main flex align-center justify-center" :style="{height: navBarHeight+'px'}">
  10. <view class="nav-main-back" @click="search" v-if="backIcon">
  11. <!-- <uni-icons type="search" size="26" color="#000"></uni-icons> -->
  12. <image style="width: 42rpx;height: 34rpx;" src="https://t9.9026.com/imgs/homeSearch.png" mode=""></image>
  13. </view>
  14. <text class="nav-main-title">{{title}}</text>
  15. </view>
  16. </view>
  17. <view :style="{'height':height+'px','background':bgColor}" style="background-color: #fff;">
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. bgColor: {
  25. type: String,
  26. default: "#FFF"
  27. },
  28. backIcon: {
  29. type: Boolean,
  30. default: true
  31. },
  32. title: {
  33. type: String,
  34. default: ""
  35. }
  36. },
  37. data() {
  38. return {
  39. //总高度
  40. height: 0,
  41. //胶囊位置信息
  42. menuButtonRect: {},
  43. //状态栏的高度
  44. statusBarHeight: 0,
  45. //导航栏的高度
  46. navBarHeight: 0
  47. }
  48. },
  49. created() {
  50. // this.height = wx.getStorageSync('navBarHeight')
  51. this.getHeight();
  52. },
  53. methods: {
  54. //获取屏幕导航栏高度
  55. getHeight() {
  56. if (wx.canIUse('getMenuButtonBoundingClientRect')) {
  57. let sysInfo = wx.getSystemInfoSync(); //状态栏的高度
  58. this.statusBarHeight = sysInfo.statusBarHeight;
  59. // 胶囊位置信息
  60. let rect = wx.getMenuButtonBoundingClientRect();
  61. this.menuButtonRect = JSON.parse(JSON.stringify(rect));
  62. // 导航栏高度
  63. let navBarHeight = (rect.top - sysInfo.statusBarHeight) * 2 + rect.height;
  64. this.navBarHeight = navBarHeight;
  65. // 自定义导航栏的高度
  66. this.height = sysInfo.statusBarHeight + navBarHeight;
  67. } else {
  68. wx.showToast({
  69. title: '您的微信版本过低,界面可能会显示不正常',
  70. icon: 'none',
  71. duration: 4000
  72. });
  73. }
  74. },
  75. //返回
  76. search() {
  77. uni.navigateTo({
  78. url:'/pages/index/active-list/index'
  79. })
  80. },
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .nav-box{
  86. width: 100%;
  87. background-color: #fff;
  88. position: fixed;
  89. top: 0;
  90. z-index: 9999;
  91. overflow: hidden;
  92. }
  93. .status_bar {
  94. // height: var(--status-bar-height);
  95. width: 100%;
  96. // background:#ff0;
  97. }
  98. .nav-main {
  99. position: relative;
  100. display: flex;
  101. align-items: center;
  102. justify-content: center;
  103. // background:#f00;
  104. .nav-main-back {
  105. position: absolute;
  106. left: 30rpx;
  107. }
  108. .nav-main-title {
  109. color: #333;
  110. font-size: 16px;
  111. }
  112. }
  113. </style>