header-poduct.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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+5)+'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="{height:navbarBtn.height+'px;',fontSize:fontSizeSetting+'px;'}">
  10.     <view class="gosearch-btn" :style="{paddingLeft:navbarBtn.height+'px;',top:5+'px;',left:(navbarBtn.right+navbarBtn.height+20)+'px;',borderRadius:navbarBtn.height/2+'px;',width:200+'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:'/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. let haveBack;
  87. if (getCurrentPages().length === 1) { // 当只有一个页面时
  88.      haveBack = false;
  89. } else {
  90.      haveBack = true;
  91. }
  92.     this.haveBack=haveBack, // 获取是否是通过分享进入的小程序
  93.     this.statusBarHeight=statusBarHeight,
  94.     this.navbarHeight= headerPosi.bottom + btnPosi.bottom, // 原胶囊bottom + 现胶囊bottom
  95. this.$parent.navbarHeight = this.navbarHeight
  96. this.$parent.statusBarHeight = this.statusBarHeight
  97. // console.log(this.navbarHeight);
  98.     this.navbarBtn=btnPosi
  99. },
  100. onLoad(){
  101. },
  102. methods:{
  103. _goBack: function () {
  104.       uni.navigateBack({
  105.         delta: this.page
  106.       });
  107.     },
  108.     _goHome: function () {
  109.       uni.switchTab({
  110.         url: '/pages/tabBar/home/index'
  111.       })
  112.     }
  113. },
  114. onShow(){
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. .navbar-wrap {
  120. position: fixed;
  121. width: 100%;
  122. top: 0;
  123. z-index: 100000;
  124. box-sizing: border-box;
  125. &.bg-color{
  126. animation: showColor 0.3s ease-in-out both;
  127. }
  128. &.no-color{
  129. animation: hideColor 0.3s ease-in-out both;
  130. }
  131. }
  132. .navbar-text {
  133. color: #000000;
  134. font-weight: 500;
  135. position: relative;
  136. }
  137. .gosearch-btn{
  138. height: 100%;
  139. background: rgba(255, 255, 255, 0.6);
  140. font-size: 28rpx;
  141. color: #666666;
  142. position: relative;
  143. box-sizing: border-box;
  144. position:absolute ;
  145. border: 1px solid rgba(0, 0, 0, 0.1);
  146. .icon-sousuo{
  147. height: 100%;
  148. text-align: center;
  149. display: block;
  150. position: absolute;
  151. left: 0;
  152. top: 0;
  153. font-size: 34rpx;
  154. color: #666666;
  155. z-index: 10;
  156. }
  157. .input{
  158. width: 400rpx;
  159. height: 100%;
  160. float: left;
  161. font-size: $font-size-24;
  162. text-align: left;
  163. }
  164. }
  165. .navbar-icon {
  166. position: fixed;
  167. display: flex;
  168. border-radius: 50%;
  169. text-align: center;
  170. background: rgba(255,255,255,0.6);
  171. border: 1px solid rgba(0,0,0, 0.1);
  172. box-sizing: border-box;
  173. z-index: 9999;
  174. }
  175. .navbar-icon .iconfont {
  176. height: 100%;
  177. width: 100%;
  178. font-size: 38rpx;
  179. font-weight: bold;
  180. display: inline-block;
  181. overflow: hidden;
  182. }
  183. .navbar-icon view {
  184. height: 18px;
  185. border-left: 0.5px solid rgba(0,0,0, 0.3);
  186. margin-top: 6px;
  187. }
  188. .navbar-loading {
  189. background: #fff;
  190. text-align: center;
  191. }
  192. @keyframes showColor {
  193. 0% {background: rgba(255,255,255,0);}
  194. 50% {background: rgba(255,255,255,0.5);}
  195. 100% {background: rgba(255,255,255,1);}
  196. }
  197. @keyframes hideColor {
  198. 0% {background: rgba(255,255,255,1);}
  199. 50% {background: rgba(255,255,255,0.5);}
  200. 100% {background: rgba(255,255,255,0);}
  201. }
  202. </style>