custom-p.vue 5.8 KB

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