cm-custom.vue 3.1 KB

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