header-poduct.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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-text" :style="{lineHeight:(navbarHeight - statusBarHeight)+'px;',fontSize:fontSizeSetting+'px;'}">
  5.     {{navbarData.title ? navbarData.title : " "}}
  6.   </view>
  7.   <view class="navbar-icon" v-if="navbarData.showCapsule ? navbarData.showCapsule : true"
  8. :style="{top:navbarBtn.top + statusBarHeight+'px;',lineHeight:navbarBtn.height+'px;',left:(navbarBtn.right+5)+'px;',width:navbarBtn.height+'px;',height:navbarBtn.height+'px;'}">
  9. <text v-if='haveBack' @click="_goBack" class="iconfont icon-fanhui"></text>
  10. <text v-else @click="_goHome" class="iconfont icon-shouye"></text>
  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. haveBack: true, // 是否有返回按钮,true 有 false 没有 若从分享页进入则为 false
  45.     statusBarHeight: 0, // 状态栏高度
  46.     navbarHeight: 0, // 顶部导航栏高度,
  47.     navbarBtn: { // 胶囊位置信息
  48.       height: 0,
  49.       width: 0,
  50.       top: 0,
  51.       bottom: 0,
  52.       right: 0
  53. },
  54. platform:'',
  55. fontSizeSetting:0
  56. }
  57. },
  58. created() {
  59. this.headerType = this.type
  60. console.log(this.headerType);
  61. // console.log(this.headerColor)
  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. let haveBack;
  85. if (getCurrentPages().length === 1) { // 当只有一个页面时
  86.      haveBack = false;
  87. } else {
  88.      haveBack = true;
  89. }
  90.     this.haveBack=haveBack, // 获取是否是通过分享进入的小程序
  91.     this.statusBarHeight=statusBarHeight,
  92.     this.navbarHeight= headerPosi.bottom + btnPosi.bottom, // 原胶囊bottom + 现胶囊bottom
  93. this.$parent.navbarHeight = this.navbarHeight
  94. this.$parent.statusBarHeight = this.statusBarHeight
  95. // console.log(this.navbarHeight);
  96.     this.navbarBtn=btnPosi
  97. },
  98. onLoad(){
  99. },
  100. methods:{
  101. _goBack: function () {
  102.       uni.navigateBack({
  103.         delta: this.page
  104.       });
  105.     },
  106.     _goHome: function () {
  107.       uni.switchTab({
  108.         url: '/pages/tabBar/home/home'
  109.       })
  110.     }
  111. },
  112. onShow(){
  113. }
  114. }
  115. </script>
  116. <style lang="scss">
  117. .navbar-wrap {
  118. position: fixed;
  119. width: 100%;
  120. top: 0;
  121. z-index: 100000;
  122. box-sizing: border-box;
  123. &.bg-color{
  124. animation: showColor 0.3s ease-in-out both;
  125. }
  126. &.no-color{
  127. animation: hideColor 0.3s ease-in-out both;
  128. }
  129. }
  130. .navbar-text {
  131. text-align: center;
  132. color: #000000;
  133. font-weight: 500;
  134. }
  135. .navbar-icon {
  136. position: fixed;
  137. display: flex;
  138. border-radius: 50%;
  139. text-align: center;
  140. background: rgba(255,255,255,0.2);
  141. border: 1px solid rgba(0,0,0, 0.2);
  142. box-sizing: border-box;
  143. }
  144. .navbar-icon .iconfont {
  145. height: 100%;
  146. width: 100%;
  147. font-size: 38rpx;
  148. font-weight: bold;
  149. display: inline-block;
  150. overflow: hidden;
  151. }
  152. .navbar-icon view {
  153. height: 18px;
  154. border-left: 0.5px solid rgba(0,0,0, 0.3);
  155. margin-top: 6px;
  156. }
  157. .navbar-loading {
  158. background: #fff;
  159. text-align: center;
  160. }
  161. @keyframes showColor {
  162. 0% {background: rgba(255,255,255,0);}
  163. 50% {background: rgba(255,255,255,0.5);}
  164. 100% {background: rgba(255,255,255,1);}
  165. }
  166. @keyframes hideColor {
  167. 0% {background: rgba(255,255,255,1);}
  168. 50% {background: rgba(255,255,255,0.5);}
  169. 100% {background: rgba(255,255,255,0);}
  170. }
  171. </style>