navbar.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <!-- 自定义导航栏 -->
  3. <view class="nav-bar-box">
  4. <!-- 状态栏占位 -->
  5. <view class="status-bar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
  6. <!-- 真正的导航栏内容 -->
  7. <view class="nav-bar">
  8. <view class="nav-bar-left">
  9. <view class="left-bg" v-if="back && back!='false'" @click="onBack">
  10. <uni-icons type="back" size="16" color="#34343A" />
  11. </view>
  12. </view>
  13. <view class="nav-bar-center" v-if="viewLogo">
  14. <image :src="$store.state.app.config.logo_image_url_mobile" mode="heightFix" />
  15. </view>
  16. <view class="nav-bar-center" v-else>
  17. <text class="title">{{title}}</text>
  18. </view>
  19. <view class="nav-bar-right"></view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'navbar',
  26. props: {
  27. // 是否采用自定义导航模式
  28. custom: {
  29. type: [Boolean, String],
  30. default: false
  31. },
  32. // 是否返回
  33. back: {
  34. type: [Boolean, String],
  35. default: true
  36. },
  37. // 标题
  38. title: {
  39. type: String,
  40. default: ''
  41. },
  42. // 标题颜色
  43. color: {
  44. type: String,
  45. default: '#353535'
  46. },
  47. // 背景色
  48. bgcolor: {
  49. type: String,
  50. default: '#fff'
  51. },
  52. // 标题是否居中
  53. center: {
  54. type: [Boolean, String],
  55. default: false
  56. },
  57. // 搜索框
  58. search: {
  59. type: [Boolean, String],
  60. default: false
  61. },
  62. // 是否固定导航
  63. fixed: {
  64. type: [Boolean, String],
  65. default: false
  66. },
  67. // 是否背景透明
  68. transparent: {
  69. type: [Boolean, String],
  70. default: false
  71. },
  72. // 设置层叠
  73. zIndex: {
  74. type: [Number, String],
  75. default: '2022'
  76. },
  77. viewLogo: {
  78. type: [Boolean, String],
  79. default: true
  80. },
  81. backPath: {
  82. type: [String],
  83. default: ''
  84. }
  85. },
  86. data() {
  87. return {
  88. // 状态栏高度
  89. statusBarHeight: 0,
  90. // 导航栏高度
  91. navBarHeight: 82 + 11
  92. }
  93. },
  94. //第一次加载时调用
  95. created() {
  96. //获取手机状态栏高度
  97. this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
  98. },
  99. methods: {
  100. onBack() {
  101. let routes = getCurrentPages();
  102. //获取当前页路径
  103. let curPage = routes[routes.length - 1].route;
  104. if (!this.backPath && (curPage.indexOf('tabbar') != -1 || curPage.indexOf('start_answering') != -1)) {
  105. //如果是tabbar页返回直接退出登录
  106. this.$store.dispatch('user/signOut');
  107. window.location.href = '/';
  108. } else {
  109. if (this.backPath) {
  110. uni.reLaunch({
  111. url: this.backPath
  112. })
  113. } else {
  114. uni.navigateBack({
  115. delta: 1
  116. })
  117. }
  118. }
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss">
  124. .nav-bar-box {
  125. width: 100%;
  126. position: fixed;
  127. z-index: 99;
  128. top: 0;
  129. .nav-bar {
  130. background-color: #ffffff;
  131. display: flex;
  132. justify-content: center;
  133. align-items: center;
  134. height: 92rpx;
  135. .nav-bar-left {
  136. flex: 1;
  137. padding: 0 16rpx;
  138. .left-bg {
  139. display: flex;
  140. justify-content: center;
  141. align-items: center;
  142. width: 60rpx;
  143. height: 60rpx;
  144. border-radius: 80rpx;
  145. background-color: $uni-bg-color-grey;
  146. }
  147. }
  148. .nav-bar-center {
  149. display: flex;
  150. justify-content: center;
  151. align-items: center;
  152. image {
  153. height: 92rpx;
  154. }
  155. .title {
  156. font-size: 18px;
  157. font-weight: 500;
  158. }
  159. }
  160. .nav-bar-right {
  161. flex: 1;
  162. padding: 0 16rpx;
  163. }
  164. }
  165. }
  166. </style>