custom-navbar.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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" :style="{ backgroundImage: 'url(' + imgsArr.navBarJtIcon + ')' }"></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. import cacheManager from '@/utils/cacheManager.js';
  18. export default {
  19. props: {
  20. title: String,
  21. titleSize: { type: Number, default: 32 }, // 默认字号
  22. titleColor: { type: String, default: '#333' },
  23. showBackBtn:{type:Boolean, default: false}
  24. },
  25. data() {
  26. return {
  27. statusBarHeight: 0,
  28. // 初始化 imgsArr,设置默认空对象
  29. imgsArr: { navBarJtIcon: '' }
  30. };
  31. },
  32. methods: {
  33. handleBack() {
  34. this.$emit('back')
  35. }
  36. },
  37. mounted() {
  38. // 获取状态栏高度(兼容不同设备)
  39. uni.getSystemInfo({
  40. success: (res) => {
  41. this.statusBarHeight = res.statusBarHeight;
  42. }
  43. });
  44. },
  45. created() {
  46. this.imgsArr.navBarJtIcon = cacheManager.get('projectImg').nav_bar_jt;
  47. },
  48. };
  49. </script>
  50. <style>
  51. .custom-nav {
  52. width: 100%;
  53. background-color: #FFFFFF; /* 背景色 */
  54. display: flex;
  55. flex-direction: column;
  56. }
  57. .status-bar {
  58. width: 100%;
  59. }
  60. .nav-content {
  61. height: 44px; /* 导航栏主体高度 */
  62. display: flex;
  63. justify-content: center;
  64. align-items: center;
  65. }
  66. .nav-title {
  67. font-weight: bold; /* 可加粗 */
  68. }
  69. </style>