NavBar.vue 2.5 KB

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