header-back.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template name="headerNavbar">
  2. <!-- 自定义导航栏 -->
  3. <view class="navbar-wrap" :style="{ height: navbarHeight + 'px', paddingTop: statusBarHeight + 'px' }">
  4. <view
  5. class="navbar-text"
  6. :style="{ lineHeight: navbarHeight - statusBarHeight + 'px;', fontSize: fontSizeSetting + 'px;' }"
  7. :class="platformClass"
  8. >
  9. {{ navbarData.title ? navbarData.title : ' ' }}
  10. </view>
  11. <view
  12. class="navbar-icon"
  13. v-if="navbarData.showCapsule == 1 ? true : false"
  14. :style="{
  15. top: navbarBtn.top + statusBarHeight + 'px;',
  16. left: navbarBtn.right + 'px;',
  17. height: navbarBtn.height + 'px;',
  18. lineHeight: navbarBtn.height + 'px;'
  19. }"
  20. >
  21. <text v-if="isShare" @click="_goBack" class="iconfont icon-shouye"></text>
  22. <text v-else @click="_goBack" class="iconfont icon-fanhui"></text>
  23. </view>
  24. <view
  25. class="navbar-icon"
  26. v-if="navbarData.showSearch == 1 ? true : false"
  27. :style="{
  28. top: navbarBtn.top + statusBarHeight + 'px;',
  29. right: navbarBtn.width + 'px;',
  30. height: navbarBtn.height + 'px;',
  31. lineHeight: navbarBtn.height + 'px;'
  32. }"
  33. >
  34. <text @click.stop="_goSearchPath" class="iconfont icon-iconfonticonfontsousuo1"></text>
  35. <text v-if="screenTab === 3" @click.stop="_showRightDrawer" class="iconfont icon-shaixuan"></text>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. var self
  41. export default {
  42. name: 'headerNavbar',
  43. props: {
  44. navbarData: {
  45. // 由父页面传递的数据
  46. type: Object
  47. },
  48. systeminfo: {
  49. type: Object
  50. },
  51. headerBtnPosi: {
  52. type: Object
  53. },
  54. isShare: {
  55. type: Boolean
  56. },
  57. isDelete: {
  58. type: Boolean
  59. },
  60. isUsertype: {
  61. type: Number
  62. },
  63. screenTab: {
  64. type: Number
  65. }
  66. },
  67. data() {
  68. return {
  69. haveBack: true, // 是否有返回按钮,true 有 false 没有 若从分享页进入则为 false
  70. statusBarHeight: 0, // 状态栏高度
  71. navbarHeight: 0, // 顶部导航栏高度
  72. navbarBtn: {
  73. // 胶囊位置信息
  74. height: 0,
  75. width: 0,
  76. top: 0,
  77. bottom: 0,
  78. right: 0
  79. },
  80. platformClass: '',
  81. fontSizeSetting: 0
  82. }
  83. },
  84. created() {
  85. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  86. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  87. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  88. if (this.systeminfo.platform == 'android') {
  89. this.platformClass = 'left'
  90. } else {
  91. this.platformClass = 'center'
  92. }
  93. /**
  94. * wx.getMenuButtonBoundingClientRect() 坐标信息以屏幕左上角为原点
  95. * 菜单按键宽度: 87
  96. * 菜单按键高度: 32
  97. * 菜单按键左边界坐标: 278
  98. * 菜单按键上边界坐标: 26
  99. * 菜单按键右边界坐标: 365
  100. * 菜单按键下边界坐标: 58
  101. */
  102. let btnPosi = {
  103. // 胶囊实际位置,坐标信息不是左上角原点
  104. height: headerPosi.height,
  105. width: headerPosi.width, // 胶囊top - 状态栏高度
  106. top: headerPosi.top - statusBarHeight, // 胶囊bottom - 胶囊height - 状态栏height (现胶囊bottom 为距离导航栏底部的长度)
  107. bottom: headerPosi.bottom - headerPosi.height - statusBarHeight, // 屏幕宽度 - 胶囊right
  108. right: this.systeminfo.screenWidth - headerPosi.right
  109. }
  110. let haveBack
  111. if (getCurrentPages().length === 1) {
  112. // 当只有一个页面时
  113. haveBack = false
  114. } else {
  115. haveBack = true
  116. }
  117. ;(this.haveBack = haveBack), // 获取是否是通过分享进入的小程序
  118. (this.statusBarHeight = statusBarHeight),
  119. (this.navbarHeight = headerPosi.bottom + btnPosi.bottom), // 原胶囊bottom + 现胶囊bottom
  120. (this.navbarBtn = btnPosi)
  121. },
  122. watch: {
  123. screenTab(newVal, oldVal) {
  124. // newVal是新值,oldVal是旧值
  125. this.screenTab = newVal
  126. }
  127. },
  128. methods: {
  129. _goBack() {
  130. if (this.isShare) {
  131. this._goHome()
  132. } else if (this.isDelete) {
  133. this._goUser()
  134. } else {
  135. uni.navigateBack({
  136. delta: 1
  137. })
  138. }
  139. },
  140. _goHome() {
  141. uni.switchTab({
  142. url: '/pages/tabBar/home/index'
  143. })
  144. },
  145. _goUser() {
  146. uni.switchTab({
  147. url: '/pages/tabBar/user/user'
  148. })
  149. },
  150. _goSearchPath() {
  151. this.$emit('goSearchPath')
  152. },
  153. _showRightDrawer() {
  154. //显示筛选抽屉
  155. this.$parent.rightDrawer = true
  156. }
  157. },
  158. onShow() {}
  159. }
  160. </script>
  161. <style lang="scss">
  162. .navbar-wrap {
  163. position: fixed;
  164. width: 100%;
  165. top: 0;
  166. z-index: 100000;
  167. box-sizing: border-box;
  168. background: #ffffff;
  169. }
  170. .navbar-text {
  171. font-size: 30rpx;
  172. color: #000000;
  173. font-weight: 500;
  174. }
  175. .navbar-text.center {
  176. text-align: center;
  177. }
  178. .navbar-text.left {
  179. text-align: left;
  180. padding-left: 38px;
  181. }
  182. .navbar-icon {
  183. position: fixed;
  184. display: flex;
  185. box-sizing: border-box;
  186. }
  187. .navbar-icon .iconfont {
  188. display: inline-block;
  189. overflow: hidden;
  190. font-size: 42rpx;
  191. padding-right: 40rpx;
  192. margin-top: 1px;
  193. }
  194. .navbar-icon .icon-iconfonticonfontsousuo1 {
  195. color: #000000;
  196. }
  197. .navbar-icon .icon-shaixuan {
  198. color: #000000;
  199. }
  200. .navbar-icon view {
  201. height: 18px;
  202. border-left: 0.5px solid rgba(0, 0, 0, 0.3);
  203. margin-top: 6px;
  204. }
  205. .navbar-loading {
  206. background: #fff;
  207. text-align: center;
  208. }
  209. </style>