nav-bar.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view v-if="!hideNavbar" class="nav-bar" :class="{ 'nav-bar-transparent': transparent,'hide_nav_bar':hideNavbar }">
  3. <view class="nav-bar-status" :style="{ height: statusBarHeight + 'px' }"></view>
  4. <view class="nav-bar-title">
  5. <template v-if="showTitle">
  6. <view class="btn-back" @click="goBack">
  7. <van-icon name="arrow-left"/>
  8. </view>
  9. <view class="nav-bar-title-text">{{ title }}</view>
  10. <view></view>
  11. </template>
  12. <template v-else>
  13. <slot></slot>
  14. </template>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. props: {
  21. title: String,
  22. transparent: Boolean,
  23. showTitle: {
  24. type: Boolean,
  25. default: true
  26. }
  27. },
  28. computed: {
  29. hasParent() {
  30. return getCurrentPages().length > 1
  31. }
  32. },
  33. data() {
  34. return {
  35. hideNavbar: false,
  36. titleBarHeight: 0,
  37. statusBarHeight: 0,
  38. isNotchScreen: false
  39. }
  40. },
  41. created() {
  42. const self = this
  43. const windowInfo = uni.getWindowInfo()
  44. this.statusBarHeight = windowInfo.statusBarHeight
  45. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  46. this.titleBarHeight = (menuButtonInfo.top - this.statusBarHeight) * 2 + menuButtonInfo.height + (windowInfo.screenWidth / 750 * 16)
  47. if (this.showTitle) {
  48. uni.getSystemInfo({
  49. success(res) {
  50. const os = res.system.toLowerCase()
  51. self.$config.os = os
  52. if (os.includes('windows') || os.includes('mac')) {
  53. self.$emit('init', {
  54. detail: {
  55. navbarHeight: 0,
  56. pageHeight: windowInfo.screenHeight
  57. }
  58. })
  59. self.hideNavbar = true
  60. // self.statusBarHeight = 0
  61. // self.titleBarHeight = (windowInfo.screenWidth / 750 * 100)
  62. // self.$emit('init', {
  63. // detail: {
  64. // navbarHeight: (windowInfo.screenWidth / 750 * 100),
  65. // pageHeight: windowInfo.screenHeight - (windowInfo.screenWidth / 750 * 100)
  66. // }
  67. // })
  68. } else {
  69. self.$emit('init', {
  70. detail: {
  71. navbarHeight: self.hideNavbar ? 0 : (self.statusBarHeight + self.titleBarHeight),
  72. pageHeight: windowInfo.screenHeight - (self.hideNavbar ? 0 : (self.statusBarHeight + self.titleBarHeight)) - res.safeAreaInsets.bottom
  73. }
  74. })
  75. }
  76. }
  77. })
  78. } else {
  79. uni.getSystemInfo({
  80. success(res) {
  81. const os = res.system.toLowerCase()
  82. self.$config.os = os
  83. if (os.includes('windows') || os.includes('mac')) {
  84. self.statusBarHeight = 0
  85. self.titleBarHeight = (windowInfo.screenWidth / 750 * 120)
  86. self.$emit('init', {
  87. detail: {
  88. navbarHeight: (windowInfo.screenWidth / 750 * 120),
  89. pageHeight: windowInfo.screenHeight - (windowInfo.screenWidth / 750 * 120)
  90. }
  91. })
  92. } else {
  93. self.$emit('init', {
  94. detail: {
  95. navbarHeight: self.hideNavbar ? 0 : (self.statusBarHeight + self.titleBarHeight),
  96. pageHeight: windowInfo.screenHeight - (self.hideNavbar ? 0 : (self.statusBarHeight + self.titleBarHeight)) - res.safeAreaInsets.bottom
  97. }
  98. })
  99. }
  100. }
  101. })
  102. }
  103. // this.$emit('init', {
  104. // detail: {
  105. // navbarHeight: self.hideNavbar ? 0 : (this.statusBarHeight + this.titleBarHeight),
  106. // pageHeight: windowInfo.screenHeight - (self.hideNavbar ? 0 : (this.statusBarHeight + this.titleBarHeight))
  107. // }
  108. // })
  109. },
  110. methods: {
  111. hasSlot() {
  112. const nodes = this.getRelationNodes(`view`);
  113. return nodes.length > 0;
  114. },
  115. goBack() {
  116. const pages = getCurrentPages();
  117. // 获取当前页面的实例
  118. const currentPage = pages[pages.length - 1];
  119. // 获取当前页面的路径
  120. const currentPath = currentPage.route;
  121. if (currentPath === 'pages/checkIn/activity-end') {
  122. this.navigateTo('/pages/index/index')
  123. return false
  124. }
  125. this.refreshData()
  126. if (this.hasParent) {
  127. uni.navigateBack()
  128. } else if (this.$store.getters.page.length > 0) {
  129. this.$store.commit('DELETE_PAGE')
  130. console.log(this.$store.getters.page)
  131. } else {
  132. this.navigateTo('/pages/index/index')
  133. }
  134. }
  135. }
  136. }
  137. </script>
  138. <style lang="scss">
  139. .nav-bar {
  140. background: linear-gradient(270deg, #2b2359 9%, #405491 44%, #2b2359 92%), rgba(0, 0, 0, 0.2);
  141. width: 100%;
  142. position: fixed;
  143. left: 0;
  144. z-index: 10;
  145. height: $navBarHeight;
  146. top: 0;
  147. display: flex;
  148. flex-direction: column;
  149. &.nav-bar-transparent {
  150. background: none;
  151. .nav-bar-title {
  152. view {
  153. color: #333333;
  154. }
  155. }
  156. }
  157. .nav-bar-title {
  158. display: flex;
  159. justify-content: space-between;
  160. align-items: center;
  161. padding: 0 16rpx;
  162. flex: 1;
  163. min-height: 1px;
  164. view {
  165. color: #ffffff;
  166. }
  167. }
  168. .nav-bar-title-text {
  169. flex: 1;
  170. font-weight: 500;
  171. font-size: $fontSize5;
  172. //line-height: 42rpx;
  173. line-height: 1.5;
  174. text-align: left;
  175. text-transform: none;
  176. padding-left: 8rpx;
  177. }
  178. .btn-back {
  179. padding: 0 6rpx;
  180. cursor: pointer;
  181. }
  182. }
  183. </style>