custom.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template name="headerNavbar">
  2. <!-- 自定义导航栏 -->
  3. <view class='navbar-wrap'
  4. :style="{height:CustomBar+'px',paddingTop:StatusBar+'px',background:navbarData.bgColor ? navbarData.bgColor : ''}">
  5. <view class="navbar-text"
  6. :style="{color:navbarData.textColor ? navbarData.textColor:'',lineHeight:(CustomBar - StatusBar)+'px;',fontSize:fontSizeSetting+'px;',paddingLeft:navbarData.textLeft ? '' : (capsule.height+10)+'px'}"
  7. :class="platformClass">
  8. {{navbarData.title ? navbarData.title : " "}}
  9. </view>
  10. <view class="navbar-icon" v-if="navbarData.showCapsule == 1 ? true : false"
  11. :style="{top:capsule.top +'px;',left:((screenWidth-capsule.right)+9)+'px;',height:capsule.height+'px;',lineHeight:capsule.height+'px;'}">
  12. <text v-if="navbarData.haveBack" @tap="BackPage" class="iconfont icon-fanhui"></text>
  13. <text v-if="navbarData.haveHome" @tap="_goHome" class="iconfont icon-shouye1"></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. },
  26. data() {
  27. return {
  28. CustomBar: this.CustomBar, // 顶部导航栏高度
  29. StatusBar: this.StatusBar,
  30. fontSizeSetting: this.fontSizeSetting,
  31. screenWidth: this.screenWidth,
  32. capsule: this.capsule,
  33. platformClass: this.platformClass,
  34. }
  35. },
  36. created() {
  37. if (getCurrentPages().length === 1) { // 当只有一个页面时
  38. this.navbarData.haveBack = false;
  39. } else {
  40. this.navbarData.haveBack = true;
  41. }
  42. },
  43. onLoad() {
  44. },
  45. methods: {
  46. BackPage: function() {
  47. this.$emit('navigateBack')
  48. },
  49. _goSearchPath: function() {
  50. this.$emit('goSearchPath')
  51. },
  52. _goHome: function() {
  53. uni.switchTab({
  54. url: '/pages/tabBar/home/index'
  55. })
  56. }
  57. },
  58. onShow() {
  59. }
  60. }
  61. </script>
  62. <style lang="scss">
  63. .navbar-wrap {
  64. position: fixed;
  65. width: 100%;
  66. top: 0;
  67. z-index: 100000;
  68. box-sizing: border-box;
  69. }
  70. .navbar-text {
  71. font-size: 30rpx;
  72. color: #000000;
  73. font-weight: 500;
  74. }
  75. .navbar-text.center {
  76. text-align: center;
  77. }
  78. .navbar-text.left {
  79. text-align: left;
  80. padding-left: 45px;
  81. }
  82. .navbar-icon {
  83. position: fixed;
  84. display: flex;
  85. box-sizing: border-box;
  86. }
  87. .navbar-icon .iconfont {
  88. display: inline-block;
  89. overflow: hidden;
  90. font-size: 44rpx;
  91. padding-right: 40rpx;
  92. margin-top: 1px;
  93. color: #FFFFFF;
  94. }
  95. .navbar-icon view {
  96. height: 18px;
  97. border-left: 0.5px solid rgba(0, 0, 0, 0.3);
  98. margin-top: 6px;
  99. }
  100. .navbar-loading {
  101. background: #fff;
  102. text-align: center;
  103. }
  104. </style>