header-back.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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="handleNavigateBack" class="iconfont icon-shouye"></text>
  22. <text v-else @click="handleNavigateBack" 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="handleShowRightDrawer" 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. console.log('isShare', this.isShare)
  86. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  87. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  88. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  89. if (this.systeminfo.platform == 'android') {
  90. this.platformClass = 'left'
  91. } else {
  92. this.platformClass = 'center'
  93. }
  94. /**
  95. * wx.getMenuButtonBoundingClientRect() 坐标信息以屏幕左上角为原点
  96. * 菜单按键宽度: 87
  97. * 菜单按键高度: 32
  98. * 菜单按键左边界坐标: 278
  99. * 菜单按键上边界坐标: 26
  100. * 菜单按键右边界坐标: 365
  101. * 菜单按键下边界坐标: 58
  102. */
  103. let btnPosi = {
  104. // 胶囊实际位置,坐标信息不是左上角原点
  105. height: headerPosi.height,
  106. width: headerPosi.width, // 胶囊top - 状态栏高度
  107. top: headerPosi.top - statusBarHeight, // 胶囊bottom - 胶囊height - 状态栏height (现胶囊bottom 为距离导航栏底部的长度)
  108. bottom: headerPosi.bottom - headerPosi.height - statusBarHeight, // 屏幕宽度 - 胶囊right
  109. right: this.systeminfo.screenWidth - headerPosi.right
  110. }
  111. let haveBack
  112. if (getCurrentPages().length === 1) {
  113. // 当只有一个页面时
  114. haveBack = false
  115. } else {
  116. haveBack = true
  117. }
  118. ;(this.haveBack = haveBack), // 获取是否是通过分享进入的小程序
  119. (this.statusBarHeight = statusBarHeight),
  120. (this.navbarHeight = headerPosi.bottom + btnPosi.bottom), // 原胶囊bottom + 现胶囊bottom
  121. (this.navbarBtn = btnPosi)
  122. },
  123. watch: {
  124. screenTab(newVal, oldVal) {
  125. // newVal是新值,oldVal是旧值
  126. this.screenTab = newVal
  127. }
  128. },
  129. methods: {
  130. handleNavigateBack() {
  131. if (this.isShare) {
  132. let data = {
  133. type: 'switchTab',
  134. url: '/pages/tabBar/home/index'
  135. }
  136. this.$emit('navigatePath', data)
  137. } else if (this.isDelete) {
  138. let data = {
  139. type: 'switchTab',
  140. url: '/pages/tabBar/user/user'
  141. }
  142. this.$emit('navigatePath', data)
  143. } else {
  144. uni.navigateBack({
  145. delta: 1
  146. })
  147. }
  148. },
  149. handleSearchPath() {
  150. let data = {
  151. type: 'navigateTo',
  152. url: '/pages/user/order/order-search'
  153. }
  154. this.$emit('navigatePath', data)
  155. },
  156. handleShowRightDrawer() {
  157. //显示筛选抽屉
  158. this.$parent.rightDrawer = true
  159. }
  160. },
  161. onShow() {}
  162. }
  163. </script>
  164. <style lang="scss">
  165. .navbar-wrap {
  166. position: fixed;
  167. width: 100%;
  168. top: 0;
  169. z-index: 100000;
  170. box-sizing: border-box;
  171. background: #ffffff;
  172. }
  173. .navbar-text {
  174. font-size: 30rpx;
  175. color: #000000;
  176. font-weight: 500;
  177. }
  178. .navbar-text.center {
  179. text-align: center;
  180. }
  181. .navbar-text.left {
  182. text-align: left;
  183. padding-left: 38px;
  184. }
  185. .navbar-icon {
  186. position: fixed;
  187. display: flex;
  188. box-sizing: border-box;
  189. }
  190. .navbar-icon .iconfont {
  191. display: inline-block;
  192. overflow: hidden;
  193. font-size: 42rpx;
  194. padding-right: 40rpx;
  195. margin-top: 1px;
  196. }
  197. .navbar-icon .icon-iconfonticonfontsousuo1 {
  198. color: #000000;
  199. }
  200. .navbar-icon .icon-shaixuan {
  201. color: #000000;
  202. }
  203. .navbar-icon view {
  204. height: 18px;
  205. border-left: 0.5px solid rgba(0, 0, 0, 0.3);
  206. margin-top: 6px;
  207. }
  208. .navbar-loading {
  209. background: #fff;
  210. text-align: center;
  211. }
  212. </style>