index copy.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view
  3. class="navbar"
  4. :class="{'gradientBgc': !noBgColor}"
  5. :style="{
  6. 'height': (navbarHeight < defaultLogoHeight ? (defaultLogoHeight + 10) : navbarHeight + 10) + 'px',
  7. 'line-height': (navbarHeight < defaultLogoHeight ? (defaultLogoHeight + 10) : navbarHeight + 10) + 'px',
  8. }"
  9. >
  10. <view class="navbar-box" :style="{'paddingTop': statusBarHeight + 'px'}">
  11. <image
  12. v-if="showLogo"
  13. src="https://minio.menduner.com/dev/fe9890be9b1176f84f2aa282b0f6adce300b133f65eb3d7b45ae057aa5698324.png"
  14. class="navbar-box-logo"
  15. :style="{'height': defaultLogoHeight + 'px'}"
  16. ></image>
  17. <view v-else class="navbar-box-title MiSans-Semibold">{{ title }}</view>
  18. </view>
  19. </view>
  20. </template>
  21. <script setup>
  22. import { ref } from 'vue'
  23. import { onLoad } from '@dcloudio/uni-app'
  24. defineProps({
  25. title: {
  26. type: String,
  27. default: '门墩儿'
  28. },
  29. showLogo: {
  30. type: Boolean,
  31. default: false
  32. },
  33. // 是否需要渐变背景
  34. noBgColor: {
  35. type: Boolean,
  36. default: false
  37. }
  38. })
  39. const defaultLogoHeight = 40
  40. const navbarHeight = ref(0)
  41. const statusBarHeight = ref(0)
  42. onLoad(() => {
  43. const systemInfo = uni.getSystemInfoSync()
  44. statusBarHeight.value = systemInfo.statusBarHeight
  45. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  46. navbarHeight.value = menuButtonInfo.height + ((menuButtonInfo.top - statusBarHeight.value) * 2) + 15
  47. })
  48. defineExpose({
  49. height: navbarHeight.value < defaultLogoHeight ? (defaultLogoHeight + 10) : navbarHeight.value
  50. })
  51. </script>
  52. <style scoped lang="scss">
  53. .gradientBgc {
  54. background: linear-gradient(180deg, #9bfece, #BCFEDE);
  55. }
  56. .navbar {
  57. position: fixed;
  58. top: 0;
  59. left: 0;
  60. width: 100%;
  61. z-index: 999;
  62. &-box {
  63. position: relative;
  64. width: 100%;
  65. height: 100%;
  66. &-logo {
  67. position: absolute;
  68. left: 10px;
  69. width: 95px;
  70. }
  71. &-title {
  72. position: absolute;
  73. left: 10px;
  74. width: 158px;
  75. height: 51px;
  76. font-family: MiSans, MiSans;
  77. font-weight: 600;
  78. font-size: 38rpx;
  79. color: #0E100F;
  80. font-style: normal;
  81. text-transform: none;
  82. }
  83. }
  84. }
  85. </style>