cat-search.vue 5.5 KB

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