header-back.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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-daohangfanhui"></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-sousuo"></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. isConfim:{
  38. type:Boolean
  39. },
  40. isUsertype:{
  41. type:Number
  42. }
  43. },
  44. data() {
  45. return{
  46. haveBack: true, // 是否有返回按钮,true 有 false 没有 若从分享页进入则为 false
  47. statusBarHeight: 0, // 状态栏高度
  48. navbarHeight: 0, // 顶部导航栏高度
  49. navbarBtn: { // 胶囊位置信息
  50. height: 0,
  51. width: 0,
  52. top: 0,
  53. bottom: 0,
  54. right: 0
  55. },
  56. platformClass:'',
  57. fontSizeSetting:0,
  58. }
  59. },
  60. created() {
  61. let statusBarHeight = this.systeminfo.statusBarHeight // 状态栏高度
  62. let headerPosi = this.headerBtnPosi // 胶囊位置信息
  63. this.fontSizeSetting = this.systeminfo.fontSizeSetting
  64. if(this.systeminfo.platform == 'android'){
  65. this.platformClass = 'left'
  66. }else{
  67. this.platformClass = 'center'
  68. }
  69. /**
  70. * wx.getMenuButtonBoundingClientRect() 坐标信息以屏幕左上角为原点
  71. * 菜单按键宽度: 87
  72. * 菜单按键高度: 32
  73. * 菜单按键左边界坐标: 278
  74. * 菜单按键上边界坐标: 26
  75. * 菜单按键右边界坐标: 365
  76. * 菜单按键下边界坐标: 58
  77. */
  78. let btnPosi = { // 胶囊实际位置,坐标信息不是左上角原点
  79. height: headerPosi.height,
  80. width: headerPosi.width,
  81. // 胶囊top - 状态栏高度
  82. top: headerPosi.top - statusBarHeight,
  83. // 胶囊bottom - 胶囊height - 状态栏height (现胶囊bottom 为距离导航栏底部的长度)
  84. bottom: headerPosi.bottom - headerPosi.height - statusBarHeight,
  85. // 屏幕宽度 - 胶囊right
  86. right: this.systeminfo.screenWidth - headerPosi.right
  87. }
  88. let haveBack;
  89. if (getCurrentPages().length === 1) { // 当只有一个页面时
  90. haveBack = false;
  91. } else {
  92. haveBack = true;
  93. }
  94. this.haveBack=haveBack, // 获取是否是通过分享进入的小程序
  95. this.statusBarHeight=statusBarHeight,
  96. this.navbarHeight= headerPosi.bottom + btnPosi.bottom, // 原胶囊bottom + 现胶囊bottom
  97. this.navbarBtn=btnPosi
  98. },
  99. onLoad(){
  100. },
  101. methods:{
  102. _goBack: function () {
  103. if(this.isShare){
  104. this._goHome()
  105. }else if(this.isDelete){
  106. this._goUser()
  107. }else if(this.isConfim){
  108. this._goOrderList()
  109. }else{
  110. uni.navigateBack({
  111. delta: 1
  112. });
  113. }
  114. },
  115. _goHome: function () {
  116. uni.switchTab({
  117. url: '/pages/tabBar/index/index'
  118. })
  119. },
  120. _goUser: function () {
  121. uni.switchTab({
  122. url: '/pages/tabBar/user/index'
  123. })
  124. },
  125. _goOrderList: function () {
  126. uni.navigateTo({
  127. url: '/pages/user/order/order-list?state=0'
  128. })
  129. },
  130. _goSearchPath:function () {
  131. this.$emit('goSearchPath')
  132. }
  133. },
  134. onShow(){
  135. }
  136. }
  137. </script>
  138. <style lang="scss">
  139. .navbar-wrap {
  140. position: fixed;
  141. width: 100%;
  142. top: 0;
  143. z-index: 100000;
  144. box-sizing: border-box;
  145. background: #FFFFFF;
  146. }
  147. .navbar-text {
  148. font-size: 30rpx;
  149. color: #000000;
  150. font-weight: 500;
  151. }
  152. .navbar-text.center{
  153. text-align: center;
  154. }
  155. .navbar-text.left{
  156. text-align: left;
  157. padding-left: 38px;
  158. }
  159. .navbar-icon {
  160. position: fixed;
  161. display: flex;
  162. box-sizing: border-box;
  163. }
  164. .navbar-icon .iconfont {
  165. display: inline-block;
  166. overflow: hidden;
  167. font-size: 42rpx;
  168. padding-right:40rpx;
  169. margin-top: 1px;
  170. }
  171. .navbar-icon .icon-sousuo {
  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>