header-poduct.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. 商品详情
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. var self;
  16. export default{
  17. name:'headerNavbar',
  18. props:{
  19. navbarData: { // 由父页面传递的数据
  20. type: Object
  21. },
  22. systeminfo:{
  23. type:Object
  24. },
  25. headerBtnPosi:{
  26. type:Object
  27. },
  28. page:{
  29. type:Number
  30. },
  31. headerColor:{
  32. type:Boolean
  33. },
  34. headerTitle:{
  35. type:String
  36. },
  37. type:{
  38. type:String
  39. },
  40. },
  41. data() {
  42. return{
  43. headerType:'',
  44. CustomBar:this.CustomBar,// 顶部导航栏高度
  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/index/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. box-sizing: border-box;
  124. &.bg-color{
  125. animation: showColor 0.3s ease-in-out both;
  126. }
  127. &.no-color{
  128. animation: hideColor 0.3s ease-in-out both;
  129. }
  130. }
  131. .navbar-text {
  132. width: 100%;
  133. color: #000000;
  134. font-weight: 500;
  135. position: fixed;
  136. text-align: center;
  137. }
  138. .gosearch-btn{
  139. height: 100%;
  140. background: rgba(255, 255, 255, 0.6);
  141. font-size: 28rpx;
  142. color: #999999;
  143. position: relative;
  144. box-sizing: border-box;
  145. position:absolute ;
  146. top: 0;
  147. border: 0.5px solid rgba(0, 0, 0, 0.1);
  148. .icon-sousuo{
  149. height: 100%;
  150. text-align: center;
  151. display: block;
  152. position: absolute;
  153. left: 0;
  154. top: 0;
  155. font-size: 34rpx;
  156. color: #999999;
  157. z-index: 10;
  158. }
  159. .input{
  160. height: 100%;
  161. float: left;
  162. font-size: $font-size-24;
  163. text-align: left;
  164. }
  165. }
  166. .navbar-icon {
  167. position: fixed;
  168. display: flex;
  169. border-radius: 50%;
  170. text-align: center;
  171. background: rgba(255,255,255,0.6);
  172. border: 0.5px solid rgba(0,0,0, 0.1);
  173. box-sizing: border-box;
  174. z-index: 9999;
  175. }
  176. .navbar-icon .iconfont {
  177. height: 100%;
  178. width: 100%;
  179. font-size: 30rpx;
  180. font-weight: bold;
  181. display: inline-block;
  182. overflow: hidden;
  183. }
  184. .navbar-icon view {
  185. height: 18px;
  186. border-left: 0.5px solid rgba(0,0,0, 0.3);
  187. margin-top: 6px;
  188. }
  189. .navbar-loading {
  190. background: #fff;
  191. text-align: center;
  192. }
  193. @keyframes showColor {
  194. 0% {background: rgba(255,255,255,0);}
  195. 50% {background: rgba(255,255,255,0.5);}
  196. 100% {background: rgba(255,255,255,1);}
  197. }
  198. @keyframes hideColor {
  199. 0% {background: rgba(255,255,255,1);}
  200. 50% {background: rgba(255,255,255,0.5);}
  201. 100% {background: rgba(255,255,255,0);}
  202. }
  203. </style>