header-order.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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="haveBack" @click="_goBack" class="iconfont icon-daohangfanhui"></text>
  22. </view>
  23. <view
  24. class="navbar-icon"
  25. v-if="navbarData.showSearch == 1 ? true : false"
  26. :style="{
  27. top: navbarBtn.top + statusBarHeight + 'px;',
  28. right: navbarBtn.width + 'px;',
  29. height: navbarBtn.height + 'px;',
  30. lineHeight: navbarBtn.height + 'px;'
  31. }"
  32. >
  33. <text @click.stop="_goSearchPath" class="iconfont icon-sousuo"></text>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. var self
  39. export default {
  40. name: 'headerNavbar',
  41. props: {
  42. navbarData: {
  43. // 由父页面传递的数据
  44. type: Object
  45. },
  46. systeminfo: {
  47. type: Object
  48. },
  49. headerBtnPosi: {
  50. type: Object
  51. },
  52. isShare: {
  53. type: Boolean
  54. },
  55. isDelete: {
  56. type: Boolean
  57. },
  58. isConfim: {
  59. type: Boolean
  60. },
  61. isUsertype: {
  62. type: Number
  63. }
  64. },
  65. data() {
  66. return {
  67. haveBack: true, // 是否有返回按钮,true 有 false 没有 若从分享页进入则为 false
  68. statusBarHeight: 0, // 状态栏高度
  69. navbarHeight: 0, // 顶部导航栏高度
  70. navbarBtn: {
  71. // 胶囊位置信息
  72. height: 0,
  73. width: 0,
  74. top: 0,
  75. bottom: 0,
  76. right: 0
  77. },
  78. platformClass: '',
  79. fontSizeSetting: 0
  80. }
  81. },
  82. created() {
  83. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  84. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  85. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  86. if (this.systeminfo.platform == 'android') {
  87. this.platformClass = 'left'
  88. } else {
  89. this.platformClass = 'center'
  90. }
  91. /**
  92. * wx.getMenuButtonBoundingClientRect() 坐标信息以屏幕左上角为原点
  93. * 菜单按键宽度: 87
  94. * 菜单按键高度: 32
  95. * 菜单按键左边界坐标: 278
  96. * 菜单按键上边界坐标: 26
  97. * 菜单按键右边界坐标: 365
  98. * 菜单按键下边界坐标: 58
  99. */
  100. let btnPosi = {
  101. // 胶囊实际位置,坐标信息不是左上角原点
  102. height: headerPosi.height,
  103. width: headerPosi.width,
  104. // 胶囊top - 状态栏高度
  105. top: headerPosi.top - statusBarHeight,
  106. // 胶囊bottom - 胶囊height - 状态栏height (现胶囊bottom 为距离导航栏底部的长度)
  107. bottom: headerPosi.bottom - headerPosi.height - statusBarHeight,
  108. // 屏幕宽度 - 胶囊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. onLoad() {},
  124. methods: {
  125. _goBack: function() {
  126. if (this.isShare) {
  127. this._goHome()
  128. } else if (this.isDelete) {
  129. this._goUser()
  130. } else if (this.isConfim) {
  131. this._goOrderList()
  132. } else {
  133. uni.navigateBack({
  134. delta: 1
  135. })
  136. }
  137. },
  138. _goHome: function() {
  139. uni.switchTab({
  140. url: '/pages/tabBar/index/index'
  141. })
  142. },
  143. _goUser: function() {
  144. uni.switchTab({
  145. url: '/pages/tabBar/user/index'
  146. })
  147. },
  148. _goOrderList: function() {
  149. uni.navigateTo({
  150. url: '/pages/user/order/order-list?state=0'
  151. })
  152. },
  153. _goSearchPath: function() {
  154. this.$emit('goSearchPath')
  155. }
  156. },
  157. onShow() {}
  158. }
  159. </script>
  160. <style lang="scss">
  161. .navbar-wrap {
  162. position: fixed;
  163. width: 100%;
  164. top: 0;
  165. z-index: 100000;
  166. box-sizing: border-box;
  167. background: #ffffff;
  168. }
  169. .navbar-text {
  170. font-size: 30rpx;
  171. color: #000000;
  172. font-weight: 500;
  173. }
  174. .navbar-text.center {
  175. text-align: center;
  176. }
  177. .navbar-text.left {
  178. text-align: left;
  179. padding-left: 38px;
  180. }
  181. .navbar-icon {
  182. position: fixed;
  183. display: flex;
  184. box-sizing: border-box;
  185. border: 0;
  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-sousuo {
  195. color: #000000;
  196. }
  197. .navbar-icon view {
  198. height: 18px;
  199. border-left: 0.5px solid rgba(0, 0, 0, 0.3);
  200. margin-top: 6px;
  201. }
  202. .navbar-loading {
  203. background: #fff;
  204. text-align: center;
  205. }
  206. </style>