custom-navbar.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="icon-title-navBar-box">
  3. <!-- 状态栏填充(兼容刘海屏) -->
  4. <view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
  5. <view class="icon-title-box">
  6. <view class="nav-bar-box" v-if="showBackBtn" @click="handleBack">
  7. <view class="nav-bar-icon"></view>
  8. </view>
  9. <!-- 标题区域 -->
  10. <view class="nav-bar-title" :style="{fontSize: titleSize + 'rpx', color: titleColor}">
  11. {{ title }}
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. title: String,
  20. titleSize: { type: Number, default: 32 }, // 默认字号
  21. titleColor: { type: String, default: '#333' },
  22. showBackBtn:{type:Boolean, default: false}
  23. },
  24. data() {
  25. return {
  26. statusBarHeight: 0
  27. };
  28. },
  29. methods: {
  30. handleBack() {
  31. this.$emit('back')
  32. }
  33. },
  34. mounted() {
  35. // 获取状态栏高度(兼容不同设备)
  36. uni.getSystemInfo({
  37. success: (res) => {
  38. this.statusBarHeight = res.statusBarHeight;
  39. }
  40. });
  41. }
  42. };
  43. </script>
  44. <style>
  45. .custom-nav {
  46. width: 100%;
  47. background-color: #FFFFFF; /* 背景色 */
  48. display: flex;
  49. flex-direction: column;
  50. }
  51. .status-bar {
  52. width: 100%;
  53. }
  54. .nav-content {
  55. height: 44px; /* 导航栏主体高度 */
  56. display: flex;
  57. justify-content: center;
  58. align-items: center;
  59. }
  60. .nav-title {
  61. font-weight: bold; /* 可加粗 */
  62. }
  63. </style>