or-custom.vue 3.0 KB

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