custom-d.vue 4.1 KB

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