cm-header.vue 6.0 KB

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