Navbar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <block v-if="isShow()">
  3. <view v-if="hideBtn" class="u-navbar" :style="{ backgroundColor: bgColor, textAlign: 'center' }">
  4. <view
  5. class="u-navbar__placeholder"
  6. v-if="fixed"
  7. :style="{
  8. height: $u.addUnit($u.getPx(height) + $u.sys().statusBarHeight,'px'),
  9. }"
  10. ></view>
  11. <view :class="[fixed && 'u-navbar--fixed']">
  12. <u-status-bar v-if="safeAreaInsetTop" :bgColor="bgColor"></u-status-bar>
  13. <view class="u-navbar__content" :class="[border && 'u-border-bottom']" :style="{ height: contentHeight, backgroundColor: bgColor }">
  14. <view class="u-navbar__content__left" hover-class="u-navbar__content__left--hover" hover-start-time="150" style="position: relative;">
  15. <text class="u-line-1 u-navbar__content__title" :style="[{ height: contentHeight, lineHeight: contentHeight, margin: '0 auto' }, $u.addStyle(titleStyle)]">
  16. {{ title }}
  17. </text>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <u-navbar v-else :title="title" :autoBack="true" :placeholder="true" :bgColor="bgColor"></u-navbar>
  23. </block>
  24. </template>
  25. <script>
  26. import props from './props.js';
  27. /**
  28. * Navbar 自定义导航栏
  29. * @property {Boolean} h5Show 是否在h5模式下显示 (默认 false )
  30. * @property {Boolean} hideBtn 是否隐藏返回按钮 (默认 false )
  31. */
  32. export default {
  33. mixins: [props],
  34. props: {
  35. h5Show: Boolean,
  36. hideBtn: Boolean,
  37. back: Boolean,
  38. home: Boolean
  39. },
  40. data () {
  41. return {
  42. systemInfo : this.$store.getters.getSystemInfo,
  43. statusBarHeight: uni.$u.addUnit(uni.$u.getPx(this.height) + uni.$u.sys().statusBarHeight, 'px'),
  44. contentHeight: uni.$u.addUnit(this.height)
  45. }
  46. },
  47. methods: {
  48. isShow () {
  49. if (this.systemInfo.uniPlatform == 'web') {
  50. return this.h5Show
  51. }
  52. return true;
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .u-navbar {
  59. &--fixed {
  60. position: fixed;
  61. left: 0;
  62. right: 0;
  63. top: 0;
  64. z-index: 11;
  65. }
  66. &__content {
  67. @include flex(row);
  68. align-items: center;
  69. height: 44px;
  70. background-color: #9acafc;
  71. position: relative;
  72. justify-content: center;
  73. &__left,
  74. &__right {
  75. padding: 0 13px;
  76. position: absolute;
  77. top: 0;
  78. bottom: 0;
  79. @include flex(row);
  80. align-items: center;
  81. }
  82. &__left {
  83. left: 0;
  84. &--hover {
  85. opacity: 0.7;
  86. }
  87. &__text {
  88. font-size: 15px;
  89. margin-left: 3px;
  90. }
  91. }
  92. &__title {
  93. text-align: center;
  94. font-size: 16px;
  95. color: $u-main-color;
  96. }
  97. &__right {
  98. right: 0;
  99. &__text {
  100. font-size: 15px;
  101. margin-left: 3px;
  102. }
  103. }
  104. }
  105. }
  106. </style>