NavBar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="navbar">
  3. <view class="content" :style="{ background: isScrolling ? '#fff' : bagColor }">
  4. <view :style="{ height: `${getHeight.barTop}px` }"></view>
  5. <view class="acea-row row-center-wrapper bar" :style="{ height: `${getHeight.barHeight}px` }">
  6. <view class="back-icon acea-row row-center-wrapper">
  7. <view
  8. v-show="showBack"
  9. @click="back"
  10. class="iconfont icon-ic_leftarrow back-icon"
  11. :style="{ color: `${iconColor}`, fontSize: `${iconSize}`, fontWeight: `${iconWeight}` }"
  12. >
  13. </view>
  14. <view
  15. v-show="showHome"
  16. @click="home"
  17. class="iconfont icon-icon_home back-icon"
  18. :style="{ color: `${iconColor}`, fontSize: `${iconSize}`, fontWeight: `${iconWeight}` }"
  19. >
  20. </view>
  21. </view>
  22. <view class="title" :style="{ color: `${textColor}`, fontSize: `${textSize}`, fontWeight: `${textWeight}` }">{{ titleText }}</view>
  23. <view class="right-icon acea-row row-center-wrapper">
  24. <view v-show="showRight" class="right-icon"></view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="placeholder">
  29. <view :style="{ height: `${getHeight.barTop}px` }"></view>
  30. <view :style="{ height: `${getHeight.barHeight}px` }"></view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. name: 'navbar',
  37. props: {
  38. // 滚动至下部
  39. isScrolling: {
  40. type: Boolean,
  41. default: false
  42. },
  43. // 是否显示返回icon
  44. showBack: {
  45. type: Boolean,
  46. default: false
  47. },
  48. showHome: {
  49. type: Boolean,
  50. default: false
  51. },
  52. // Title
  53. titleText: {
  54. type: String,
  55. default: ''
  56. },
  57. // icon 颜色
  58. iconColor: {
  59. type: String,
  60. default: '#000000'
  61. },
  62. // icon 字号
  63. iconSize: {
  64. type: String,
  65. default: '40rpx'
  66. },
  67. // icon 字重
  68. iconWeight: {
  69. type: String,
  70. default: 'bold'
  71. },
  72. // Title 颜色
  73. textColor: {
  74. type: String,
  75. default: '#333'
  76. },
  77. // Title 字号
  78. textSize: {
  79. type: String,
  80. default: '34rpx'
  81. },
  82. // Title 字重
  83. textWeight: {
  84. type: String,
  85. default: '500'
  86. },
  87. // 背景色
  88. bagColor: {
  89. type: String,
  90. default: 'transparent'
  91. },
  92. showRight:{
  93. type: Boolean,
  94. default: false
  95. },
  96. },
  97. data() {
  98. return {
  99. getHeight: this.$util.getWXStatusHeight()
  100. };
  101. },
  102. methods: {
  103. back() {
  104. console.log(111)
  105. uni.navigateBack();
  106. },
  107. home() {
  108. uni.switchTab({
  109. url:'/pages/index/index'
  110. })
  111. }
  112. }
  113. };
  114. </script>
  115. <style lang="scss">
  116. .navbar {
  117. position: relative;
  118. color: #333;
  119. .content {
  120. position: fixed;
  121. top: 0;
  122. right: 0;
  123. left: 0;
  124. z-index: 998;
  125. background-color: var(--view-theme);
  126. font-weight: 500;
  127. font-size: 34rpx;
  128. color: #ffffff;
  129. .back-icon,
  130. .right-icon {
  131. width: 40rpx;
  132. height: 40rpx;
  133. }
  134. .bar {
  135. padding: 0 30rpx;
  136. }
  137. .title {
  138. flex: 1;
  139. text-align: center;
  140. }
  141. }
  142. }
  143. </style>