header-payment.vue 4.7 KB

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