custom-floor.vue 5.7 KB

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