cat-search.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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="{
  7. top: navbarBtn.top + statusBarHeight + 'px;',
  8. height: navbarBtn.height + 'px;',
  9. fontSize: fontSizeSetting + 'px;'
  10. }"
  11. @click="this.$api.navigateTo(clickPath)"
  12. >
  13. <view
  14. class="gosearch-btn"
  15. :style="{
  16. paddingLeft: navbarBtn.height + 'px;',
  17. left: navbarBtn.height / 2 + 'px;',
  18. borderRadius: navbarBtn.height / 2 + 'px;',
  19. width: 375 - navbarBtn.width - 20 + 'px;',
  20. lineHeight: navbarBtn.height + 'px;'
  21. }"
  22. >
  23. <text
  24. class="iconfont icon-sousuo"
  25. :style="{
  26. width: navbarBtn.height + 'px;',
  27. height: navbarBtn.height + 'px;',
  28. lineHeight: navbarBtn.height + 'px;'
  29. }"
  30. ></text>
  31. <view class="input">搜索商品/项目仪器</view>
  32. </view>
  33. </view>
  34. <view class="category-tab">
  35. <view class="category-tab-item" :class="categoryTabIndex == 1 ? 'active' : ''" @click="categoryTabClick(1)"
  36. >产品</view
  37. >
  38. <view class="category-tab-item" :class="categoryTabIndex == 2 ? 'active' : ''" @click="categoryTabClick(2)"
  39. >仪器</view
  40. >
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. var self
  46. export default {
  47. name: 'headerNavbar',
  48. props: {
  49. navbarData: {
  50. // 由父页面传递的数据
  51. type: Object
  52. },
  53. systeminfo: {
  54. type: Object
  55. },
  56. headerBtnPosi: {
  57. type: Object
  58. },
  59. page: {
  60. type: Number
  61. },
  62. headerTitle: {
  63. type: String
  64. },
  65. type: {
  66. type: String
  67. }
  68. },
  69. data() {
  70. return {
  71. headerType: '',
  72. clickPath: '/pages/search/search',
  73. haveBack: true, // 是否有返回按钮,true 有 false 没有 若从分享页进入则为 false
  74. statusBarHeight: 0, // 状态栏高度
  75. navbarHeight: 0, // 顶部导航栏高度,
  76. navbarBtn: {
  77. // 胶囊位置信息
  78. height: 0,
  79. width: 0,
  80. top: 0,
  81. bottom: 0,
  82. right: 0
  83. },
  84. platform: '',
  85. fontSizeSetting: 0,
  86. categoryTabIndex: 1
  87. }
  88. },
  89. created() {
  90. this.headerType = this.type
  91. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  92. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  93. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  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,
  107. // 胶囊top - 状态栏高度
  108. top: headerPosi.top - statusBarHeight,
  109. // 胶囊bottom - 胶囊height - 状态栏height (现胶囊bottom 为距离导航栏底部的长度)
  110. bottom: headerPosi.bottom - headerPosi.height - statusBarHeight,
  111. // 屏幕宽度 - 胶囊right
  112. right: this.systeminfo.screenWidth - headerPosi.right
  113. }
  114. console.log(btnPosi)
  115. let haveBack
  116. if (getCurrentPages().length === 1) {
  117. // 当只有一个页面时
  118. haveBack = false
  119. } else {
  120. haveBack = true
  121. }
  122. ;(this.haveBack = haveBack), // 获取是否是通过分享进入的小程序
  123. (this.statusBarHeight = statusBarHeight),
  124. (this.navbarHeight = headerPosi.bottom + btnPosi.bottom), // 原胶囊bottom + 现胶囊bottom
  125. (this.$parent.navbarHeight = this.navbarHeight)
  126. this.$parent.statusBarHeight = this.statusBarHeight
  127. // console.log(this.navbarHeight);
  128. this.navbarBtn = btnPosi
  129. },
  130. onLoad() {},
  131. methods: {
  132. _goBack: function() {
  133. uni.navigateBack({
  134. delta: this.page
  135. })
  136. },
  137. _goHome: function() {
  138. uni.switchTab({
  139. url: '/pages/tabBar/home/index'
  140. })
  141. },
  142. categoryTabClick(index) {
  143. this.categoryTabIndex = index
  144. this.$emit('click', this.categoryTabIndex)
  145. }
  146. },
  147. onShow() {}
  148. }
  149. </script>
  150. <style lang="scss">
  151. .navbar-wrap {
  152. position: fixed;
  153. width: 100%;
  154. top: 0;
  155. z-index: 100000;
  156. background-color: #ffffff;
  157. box-sizing: border-box;
  158. &.bg-color {
  159. animation: showColor 0.3s ease-in-out both;
  160. }
  161. &.no-color {
  162. animation: hideColor 0.3s ease-in-out both;
  163. }
  164. }
  165. .navbar-text {
  166. width: 100%;
  167. color: #000000;
  168. font-weight: 500;
  169. position: fixed;
  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. .category-tab {
  200. width: 100%;
  201. height: 76rpx;
  202. display: flex;
  203. border-bottom: 1px solid #eee;
  204. position: absolute;
  205. bottom: -76rpx;
  206. background-color: #ffffff;
  207. .category-tab-item {
  208. flex: 1;
  209. font-size: $font-size-30;
  210. line-height: 76rpx;
  211. text-align: center;
  212. color: #93979f;
  213. position: relative;
  214. &::before {
  215. content: '';
  216. width: 57rpx;
  217. height: 4rpx;
  218. background-color: #fff;
  219. position: absolute;
  220. bottom: 0;
  221. left: 50%;
  222. margin-left: -28rpx;
  223. }
  224. &.active {
  225. color: #F3B574;
  226. &::before {
  227. background-color: #F3B574;
  228. }
  229. }
  230. }
  231. }
  232. </style>