header-back.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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;'}" :class="platformClass">
  5.     {{navbarData.title ? navbarData.title : " "}}
  6.   </view>
  7.   <view class="navbar-icon" v-if="navbarData.showCapsule == 1 ? true : false"
  8. :style="{top:navbarBtn.top + statusBarHeight+'px;',left:(navbarBtn.right)+'px;',height:navbarBtn.height+'px;',lineHeight:navbarBtn.height+'px;'}">
  9. <text v-if='haveBack' @click="_goBack" class="iconfont icon-fanhui"></text>
  10.   </view>
  11. <view class="navbar-icon" v-if="navbarData.showSearch == 1 ? true : false"
  12. :style="{top:navbarBtn.top + statusBarHeight+'px;',right:(navbarBtn.width)+'px;',height:navbarBtn.height+'px;',lineHeight:navbarBtn.height+'px;'}">
  13. <text @click.stop="_goSearchPath" class="iconfont icon-iconfonticonfontsousuo1"></text>
  14.   </view>
  15. </view>
  16. </template>
  17. <script>
  18. var self;
  19. export default{
  20. name:'headerNavbar',
  21. props:{
  22. navbarData: { // 由父页面传递的数据
  23. type: Object
  24. },
  25. systeminfo:{
  26. type:Object
  27. },
  28. headerBtnPosi:{
  29. type:Object
  30. },
  31. isShare:{
  32. type:Boolean
  33. },
  34. isDelete:{
  35. type:Boolean
  36. }
  37. },
  38. data() {
  39. return{
  40. haveBack: true, // 是否有返回按钮,true 有 false 没有 若从分享页进入则为 false
  41.     statusBarHeight: 0, // 状态栏高度
  42.     navbarHeight: 0, // 顶部导航栏高度
  43.     navbarBtn: { // 胶囊位置信息
  44.       height: 0,
  45.       width: 0,
  46.       top: 0,
  47.       bottom: 0,
  48.       right: 0
  49. },
  50. platformClass:'',
  51. fontSizeSetting:0,
  52. }
  53. },
  54. created() {
  55. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  56. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  57. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  58. // console.log(this.systeminfo.platform)
  59. // console.log(this.systeminfo.fontSizeSetting)
  60. if(this.systeminfo.platform == 'android'){
  61. this.platformClass = 'left'
  62. }else{
  63. this.platformClass = 'center'
  64. }
  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. // console.log(this.navbarHeight);
  94.     this.navbarBtn=btnPosi
  95. },
  96. onLoad(){
  97. },
  98. methods:{
  99. _goBack: function () {
  100. if(this.isShare){
  101. this._goHome()
  102. }else if(this.isDelete){
  103. this._goUser()
  104. }else{
  105. uni.navigateBack({
  106.         delta: 1
  107.       });
  108. }
  109.     },
  110.     _goHome: function () {
  111.       uni.switchTab({
  112.         url: '/pages/tabBar/home/home'
  113.       })
  114.     },
  115.     _goUser: function () {
  116.       uni.switchTab({
  117.         url: '/pages/tabBar/user/user'
  118.       })
  119.     },
  120. _goSearchPath:function () {
  121. this.$emit('goSearchPath')
  122. }
  123. },
  124. onShow(){
  125. }
  126. }
  127. </script>
  128. <style lang="scss">
  129. .navbar-wrap {
  130. position: fixed;
  131. width: 100%;
  132. top: 0;
  133. z-index: 100000;
  134. box-sizing: border-box;
  135. background: #FFFFFF;
  136. }
  137. .navbar-text {
  138. font-size: 30rpx;
  139. color: #000000;
  140. font-weight: 500;
  141. }
  142. .navbar-text.center{
  143. text-align: center;
  144. }
  145. .navbar-text.left{
  146. text-align: left;
  147. padding-left: 38px;
  148. }
  149. .navbar-icon {
  150. position: fixed;
  151. display: flex;
  152. box-sizing: border-box;
  153. }
  154. .navbar-icon .iconfont {
  155. display: inline-block;
  156. overflow: hidden;
  157. font-size: 42rpx;
  158. padding-right:40rpx;
  159. margin-top: 1px;
  160. }
  161. .navbar-icon .icon-iconfonticonfontsousuo1 {
  162. color: #000000;
  163. }
  164. .navbar-icon view {
  165. height: 18px;
  166. border-left: 0.5px solid rgba(0,0,0, 0.3);
  167. margin-top: 6px;
  168. }
  169. .navbar-loading {
  170. background: #fff;
  171. text-align: center;
  172. }
  173. </style>