header-poduct.vue 6.2 KB

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