tui-custom.vue 4.3 KB

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