header-back.vue 5.2 KB

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