header-back.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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="screenTab === 3" @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. screenTab:{
  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. watch: {
  102. screenTab(newVal, oldVal){
  103. // newVal是新值,oldVal是旧值
  104. this.screenTab = newVal
  105. }
  106. },
  107. methods:{
  108. _goBack() {
  109. if(this.isShare){
  110. this._goHome()
  111. }else if(this.isDelete){
  112. this._goUser()
  113. }else{
  114. uni.navigateBack({
  115.         delta: 1
  116.       })
  117. }
  118.     },
  119.     _goHome() {
  120.       uni.switchTab({
  121.         url: '/pages/tabBar/home/index'
  122.       })
  123.     },
  124.     _goUser() {
  125.       uni.switchTab({
  126.         url: '/pages/tabBar/user/user'
  127.       })
  128.     },
  129. _goSearchPath() {
  130. this.$emit('goSearchPath')
  131. },
  132. _showRightDrawer() {
  133. //显示筛选抽屉
  134. this.$parent.rightDrawer = true
  135. },
  136. },
  137. onShow(){
  138. }
  139. }
  140. </script>
  141. <style lang="scss">
  142. .navbar-wrap {
  143. position: fixed;
  144. width: 100%;
  145. top: 0;
  146. z-index: 100000;
  147. box-sizing: border-box;
  148. background: #FFFFFF;
  149. }
  150. .navbar-text {
  151. font-size: 30rpx;
  152. color: #000000;
  153. font-weight: 500;
  154. }
  155. .navbar-text.center{
  156. text-align: center;
  157. }
  158. .navbar-text.left{
  159. text-align: left;
  160. padding-left: 38px;
  161. }
  162. .navbar-icon {
  163. position: fixed;
  164. display: flex;
  165. box-sizing: border-box;
  166. }
  167. .navbar-icon .iconfont {
  168. display: inline-block;
  169. overflow: hidden;
  170. font-size: 42rpx;
  171. padding-right:40rpx;
  172. margin-top: 1px;
  173. }
  174. .navbar-icon .icon-iconfonticonfontsousuo1 {
  175. color: #000000;
  176. }
  177. .navbar-icon .icon-shaixuan {
  178. color: #000000;
  179. }
  180. .navbar-icon view {
  181. height: 18px;
  182. border-left: 0.5px solid rgba(0,0,0, 0.3);
  183. margin-top: 6px;
  184. }
  185. .navbar-loading {
  186. background: #fff;
  187. text-align: center;
  188. }
  189. </style>