NavBar.vue 2.3 KB

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