header-poduct.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template name="headerNavbar">
  2. <!-- 自定义导航栏 -->
  3. <view
  4. class="navbar-wrap"
  5. :class="[headerColor ? 'bg-color' : 'bg-color']"
  6. :style="{ height: navbarHeight + 'px', paddingTop: CustomBar / 2 + 'px' }"
  7. >
  8. <view
  9. class="navbar-icon"
  10. v-if="navbarData.showCapsule ? navbarData.showCapsule : true"
  11. :style="{
  12. top: navbarBtn.top + statusBarHeight + 'px;',
  13. lineHeight: navbarBtn.height + 'px;',
  14. left: 12 + 'px;',
  15. width: navbarBtn.height + 'px;',
  16. height: navbarBtn.height + 'px;'
  17. }"
  18. >
  19. <text v-if="haveBack" @click="_goBack" class="iconfont icon-daohangfanhui"></text>
  20. <text v-else @click="_goHome" class="iconfont icon-fanhuishouye"></text>
  21. </view>
  22. <view
  23. class="navbar-text"
  24. :style="{
  25. top: navbarBtn.top + statusBarHeight + 'px;',
  26. height: navbarBtn.height + 'px;',
  27. fontSize: fontSizeSetting + 'px;'
  28. }"
  29. >
  30. 商品详情
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. var self
  36. export default {
  37. name: 'headerNavbar',
  38. props: {
  39. navbarData: {
  40. // 由父页面传递的数据
  41. type: Object
  42. },
  43. systeminfo: {
  44. type: Object
  45. },
  46. headerBtnPosi: {
  47. type: Object
  48. },
  49. page: {
  50. type: Number
  51. },
  52. headerColor: {
  53. type: Boolean
  54. },
  55. headerTitle: {
  56. type: String
  57. },
  58. type: {
  59. type: String
  60. }
  61. },
  62. data() {
  63. return {
  64. headerType: '',
  65. CustomBar: this.CustomBar, // 顶部导航栏高度
  66. clickPath: '/search/pages/search/search',
  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. platform: '',
  79. fontSizeSetting: 0
  80. }
  81. },
  82. created() {
  83. this.headerType = this.type
  84. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  85. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  86. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  87. /**
  88. * wx.getMenuButtonBoundingClientRect() 坐标信息以屏幕左上角为原点
  89. * 菜单按键宽度: 87
  90. * 菜单按键高度: 32
  91. * 菜单按键左边界坐标: 278
  92. * 菜单按键上边界坐标: 26
  93. * 菜单按键右边界坐标: 365
  94. * 菜单按键下边界坐标: 58
  95. */
  96. let btnPosi = {
  97. // 胶囊实际位置,坐标信息不是左上角原点
  98. height: headerPosi.height,
  99. width: headerPosi.width,
  100. // 胶囊top - 状态栏高度
  101. top: headerPosi.top - statusBarHeight,
  102. // 胶囊bottom - 胶囊height - 状态栏height (现胶囊bottom 为距离导航栏底部的长度)
  103. bottom: headerPosi.bottom - headerPosi.height - statusBarHeight,
  104. // 屏幕宽度 - 胶囊right
  105. right: this.systeminfo.screenWidth - headerPosi.right
  106. }
  107. console.log(btnPosi)
  108. let haveBack
  109. if (getCurrentPages().length === 1) {
  110. // 当只有一个页面时
  111. haveBack = false
  112. } else {
  113. haveBack = true
  114. }
  115. ;(this.haveBack = haveBack), // 获取是否是通过分享进入的小程序
  116. (this.statusBarHeight = statusBarHeight),
  117. (this.navbarHeight = headerPosi.bottom + btnPosi.bottom), // 原胶囊bottom + 现胶囊bottom
  118. (this.$parent.navbarHeight = this.navbarHeight)
  119. this.$parent.statusBarHeight = this.statusBarHeight
  120. // console.log(this.navbarHeight);
  121. this.navbarBtn = btnPosi
  122. },
  123. onLoad() {},
  124. methods: {
  125. _goBack: function() {
  126. uni.navigateBack({
  127. delta: this.page
  128. })
  129. },
  130. _goHome: function() {
  131. uni.switchTab({
  132. url: '/pages/tabBar/index/index'
  133. })
  134. }
  135. },
  136. onShow() {}
  137. }
  138. </script>
  139. <style lang="scss">
  140. .navbar-wrap {
  141. position: fixed;
  142. width: 100%;
  143. top: 0;
  144. z-index: 100000;
  145. box-sizing: border-box;
  146. &.bg-color {
  147. animation: showColor 0.3s ease-in-out both;
  148. }
  149. &.no-color {
  150. animation: hideColor 0.3s ease-in-out both;
  151. }
  152. }
  153. .navbar-text {
  154. width: 100%;
  155. color: #000000;
  156. font-weight: 500;
  157. position: fixed;
  158. text-align: center;
  159. }
  160. .gosearch-btn {
  161. height: 100%;
  162. background: rgba(255, 255, 255, 0.6);
  163. font-size: 28rpx;
  164. color: #999999;
  165. position: relative;
  166. box-sizing: border-box;
  167. position: absolute;
  168. top: 0;
  169. border: 0.5px solid rgba(0, 0, 0, 0.1);
  170. .icon-sousuo {
  171. height: 100%;
  172. text-align: center;
  173. display: block;
  174. position: absolute;
  175. left: 0;
  176. top: 0;
  177. font-size: 34rpx;
  178. color: #999999;
  179. z-index: 10;
  180. }
  181. .input {
  182. height: 100%;
  183. float: left;
  184. font-size: $font-size-24;
  185. text-align: left;
  186. }
  187. }
  188. .navbar-icon {
  189. position: fixed;
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. border-radius: 50%;
  194. text-align: center;
  195. background: rgba(255, 255, 255, 0.6);
  196. border: 0.5px solid rgba(0, 0, 0, 0.1);
  197. box-sizing: border-box;
  198. z-index: 9999;
  199. }
  200. .navbar-icon .iconfont {
  201. flex: 1;
  202. font-size: 30rpx;
  203. font-weight: bold;
  204. overflow: hidden;
  205. padding: 0;
  206. margin: 0;
  207. }
  208. .navbar-icon view {
  209. height: 18px;
  210. border-left: 0.5px solid rgba(0, 0, 0, 0.3);
  211. margin-top: 6px;
  212. }
  213. .navbar-loading {
  214. background: #fff;
  215. text-align: center;
  216. }
  217. @keyframes showColor {
  218. 0% {
  219. background: rgba(255, 255, 255, 0);
  220. }
  221. 50% {
  222. background: rgba(255, 255, 255, 0.5);
  223. }
  224. 100% {
  225. background: rgba(255, 255, 255, 1);
  226. }
  227. }
  228. @keyframes hideColor {
  229. 0% {
  230. background: rgba(255, 255, 255, 1);
  231. }
  232. 50% {
  233. background: rgba(255, 255, 255, 0.5);
  234. }
  235. 100% {
  236. background: rgba(255, 255, 255, 0);
  237. }
  238. }
  239. </style>