header-pay.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template name="headerNavbar">
  2. <!-- 自定义导航栏 -->
  3. <view class='navbar-wrap' :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="{width:headerBtnPosi.height+'px;',lineHeight:(navbarBtn.height)+'px',top:navbarBtn.top + statusBarHeight+'px;',left:navbarBtn.right+'px;',height:(navbarBtn.height)+'px;'}">
  9. <text @click="_goHome" class="iconfont icon-fanhuishouye" :style="{width:headerBtnPosi.width/2+'px',height:navbarBtn.height+'px'}"></text>
  10.   </view>
  11. </view>
  12. </template>
  13. <script>
  14. var self;
  15. export default{
  16. name:'headerNavbar',
  17. props:{
  18. navbarData: { // 由父页面传递的数据
  19. type: Object
  20. },
  21. systeminfo:{
  22. type:Object
  23. },
  24. headerBtnPosi:{
  25. type:Object
  26. },
  27. isBackType:{
  28. type:Boolean,
  29. default:false
  30. },
  31. page:{
  32. type:Number,
  33. default:1
  34. },
  35. path:{
  36. type:String
  37. }
  38. },
  39. data() {
  40. return{
  41. // haveBack: true, // 是否有返回按钮,true 有 false 没有 若从分享页进入则为 false
  42.     statusBarHeight: 0, // 状态栏高度
  43.     navbarHeight: 0, // 顶部导航栏高度
  44.     navbarBtn: { // 胶囊位置信息
  45.       height: 0,
  46.       width: 0,
  47.       top: 0,
  48.       bottom: 0,
  49.       right: 0
  50. },
  51. platform:'',
  52. fontSizeSetting:0,
  53. screenWidth:0
  54. }
  55. },
  56. created() {
  57. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  58. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  59. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  60.     /**
  61.      * wx.getMenuButtonBoundingClientRect() 坐标信息以屏幕左上角为原点
  62.      * 菜单按键宽度: 87
  63.      * 菜单按键高度: 32
  64.      * 菜单按键左边界坐标: 278
  65.      * 菜单按键上边界坐标: 26
  66.      * 菜单按键右边界坐标: 365
  67.      * 菜单按键下边界坐标: 58
  68.      */
  69. let btnPosi = { // 胶囊实际位置,坐标信息不是左上角原点
  70.       height: headerPosi.height,
  71.       width: headerPosi.width,
  72.       // 胶囊top - 状态栏高度
  73.       top: headerPosi.top - statusBarHeight,
  74.       // 胶囊bottom - 胶囊height - 状态栏height (现胶囊bottom 为距离导航栏底部的长度)
  75.       bottom: headerPosi.bottom - headerPosi.height - statusBarHeight,
  76.       // 屏幕宽度 - 胶囊right
  77.       right: this.systeminfo.screenWidth - headerPosi.right
  78. }
  79. let haveBack;
  80. if (getCurrentPages().length === 1) { // 当只有一个页面时
  81.      haveBack = false;
  82. } else {
  83.      haveBack = true;
  84. }
  85.     this.isBackType=haveBack, // 获取是否是通过分享进入的小程序
  86.     this.statusBarHeight=statusBarHeight,
  87.     this.navbarHeight= headerPosi.bottom + btnPosi.bottom, // 原胶囊bottom + 现胶囊bottom
  88.     this.navbarBtn=btnPosi
  89. },
  90. onLoad(){
  91. },
  92. methods:{
  93.     _goHome: function () {
  94.       uni.switchTab({
  95.         url: '/pages/tabBar/index/index'
  96.       })
  97.     }
  98. },
  99. onShow(){
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. .navbar-wrap {
  105. position: fixed;
  106. width: 100%;
  107. top: 0;
  108. z-index: 9999;
  109. box-sizing: border-box;
  110. background: #FFFFFF;
  111. }
  112. .navbar-text {
  113. text-align: center;
  114. color: #000000;
  115. font-weight: 500;
  116. }
  117. .navbar-icon {
  118. position: fixed;
  119. display: flex;
  120. border-radius: 64rpx;
  121. box-sizing: border-box;
  122. }
  123. .navbar-icon .iconfont {
  124. text-align: center;
  125. display: inline-block;
  126. overflow: hidden;
  127. margin-bottom: 1px;
  128. &.icon-fanhuishouye {
  129. font-size: 38rpx;
  130. }
  131. }
  132. .navbar-icon .icon-vertical_line {
  133. color: #999999;
  134. }
  135. .navbar-loading {
  136. background: #fff;
  137. text-align: center;
  138. }
  139. </style>