index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. <!-- 使用 H5 原生 CSS 绘制返回箭头,防止打包后图标丢失 @Author: Antigravity -->
  7. <view class="back-arrow" :style="{ borderColor: color }"></view>
  8. </view>
  9. <view class="title-box">
  10. <text class="title-text" :style="{ color: color }">{{ title }}</text>
  11. </view>
  12. <view class="right-box">
  13. <slot name="right"></slot>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup>
  19. import { ref, onMounted } from 'vue'
  20. const props = defineProps({
  21. title: {
  22. type: String,
  23. default: ''
  24. },
  25. showBack: {
  26. type: Boolean,
  27. default: true
  28. },
  29. bgColor: {
  30. type: String,
  31. default: '#ffffff'
  32. },
  33. color: {
  34. type: String,
  35. default: '#000000'
  36. }
  37. })
  38. const statusBarHeight = ref(44)
  39. onMounted(() => {
  40. const sysInfo = uni.getSystemInfoSync()
  41. statusBarHeight.value = sysInfo.statusBarHeight || 44
  42. })
  43. const goBack = () => {
  44. uni.navigateBack()
  45. }
  46. </script>
  47. <style lang="scss" scoped>
  48. .nav-bar {
  49. position: sticky;
  50. top: 0;
  51. z-index: 999;
  52. width: 100%;
  53. }
  54. .nav-content {
  55. height: 44px;
  56. display: flex;
  57. align-items: center;
  58. padding: 0 32rpx;
  59. position: relative;
  60. }
  61. .left-box {
  62. position: absolute;
  63. left: 32rpx;
  64. z-index: 10;
  65. /* 扩大点击区域 */
  66. padding: 20rpx 40rpx 20rpx 0;
  67. }
  68. /* 原生 CSS 绘制返回箭头 @Author: Antigravity */
  69. .back-arrow {
  70. width: 22rpx;
  71. height: 22rpx;
  72. border-left: 4rpx solid;
  73. border-top: 4rpx solid;
  74. transform: rotate(-45deg);
  75. background: transparent;
  76. }
  77. .title-box {
  78. flex: 1;
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. }
  83. .title-text {
  84. font-size: 32rpx;
  85. font-weight: bold;
  86. }
  87. .right-box {
  88. position: absolute;
  89. right: 32rpx;
  90. }
  91. </style>