index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="nav-bar" :style="{ backgroundColor: bgColor }">
  3. <view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
  4. <view class="nav-content">
  5. <view class="left-box" @click="goBack" v-if="showBack">
  6. <uni-icons type="left" size="20" :color="color"></uni-icons>
  7. </view>
  8. <view class="title-box">
  9. <text class="title-text" :style="{ color: color }">{{ title }}</text>
  10. </view>
  11. <view class="right-box">
  12. <slot name="right"></slot>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script setup>
  18. import { ref, onMounted } from 'vue'
  19. const props = defineProps({
  20. title: {
  21. type: String,
  22. default: ''
  23. },
  24. showBack: {
  25. type: Boolean,
  26. default: true
  27. },
  28. bgColor: {
  29. type: String,
  30. default: '#ffffff'
  31. },
  32. color: {
  33. type: String,
  34. default: '#000000'
  35. }
  36. })
  37. const statusBarHeight = ref(44)
  38. onMounted(() => {
  39. const sysInfo = uni.getSystemInfoSync()
  40. statusBarHeight.value = sysInfo.statusBarHeight || 44
  41. })
  42. const goBack = () => {
  43. uni.navigateBack()
  44. }
  45. </script>
  46. <style lang="scss" scoped>
  47. .nav-bar {
  48. position: sticky;
  49. top: 0;
  50. z-index: 999;
  51. width: 100%;
  52. }
  53. .nav-content {
  54. height: 44px;
  55. display: flex;
  56. align-items: center;
  57. padding: 0 32rpx;
  58. position: relative;
  59. }
  60. .left-box {
  61. position: absolute;
  62. left: 32rpx;
  63. z-index: 10;
  64. }
  65. .title-box {
  66. flex: 1;
  67. display: flex;
  68. justify-content: center;
  69. align-items: center;
  70. }
  71. .title-text {
  72. font-size: 32rpx;
  73. font-weight: bold;
  74. }
  75. .right-box {
  76. position: absolute;
  77. right: 32rpx;
  78. }
  79. </style>