123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <template>
- <view
- class="navbar"
- :class="{'gradientBgc': !noBgColor}"
- :style="{
- 'height': (navbarHeight < defaultLogoHeight ? (defaultLogoHeight + 10) : navbarHeight + 10) + 'px',
- 'line-height': (navbarHeight < defaultLogoHeight ? (defaultLogoHeight + 10) : navbarHeight + 10) + 'px',
- }"
- >
- <view class="navbar-box" :style="{'paddingTop': statusBarHeight + 'px'}">
- <image
- v-if="showLogo"
- src="https://minio.menduner.com/dev/fe9890be9b1176f84f2aa282b0f6adce300b133f65eb3d7b45ae057aa5698324.png"
- class="navbar-box-logo"
- :style="{'height': defaultLogoHeight + 'px'}"
- ></image>
- <view v-else class="navbar-box-title" :class="[{'text-left': textLeft}, {'text-center': !textLeft}]">{{ title }}</view>
- </view>
- </view>
- </template>
- <script setup>
- import { ref } from 'vue'
- import { onLoad } from '@dcloudio/uni-app'
- defineProps({
- title: {
- type: String,
- default: '门墩儿'
- },
- showLogo: {
- type: Boolean,
- default: false
- },
- // 是否需要渐变背景
- noBgColor: {
- type: Boolean,
- default: false
- },
- // 标题所在位置
- textLeft: {
- type: Boolean,
- default: true
- }
- })
- const defaultLogoHeight = 40
- const navbarHeight = ref(0)
- const statusBarHeight = ref(0)
- onLoad(() => {
- const systemInfo = uni.getSystemInfoSync()
- statusBarHeight.value = systemInfo.statusBarHeight
- const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
- navbarHeight.value = menuButtonInfo.height + ((menuButtonInfo.top - statusBarHeight.value) * 2) + 15
- // 将navbarHeight存入本地缓存
- const height = navbarHeight.value < defaultLogoHeight ? (defaultLogoHeight + 10) : navbarHeight.value + 10
- uni.setStorageSync('navbarHeight', height || 65)
- })
- defineExpose({
- height: navbarHeight.value < defaultLogoHeight ? (defaultLogoHeight + 10) : navbarHeight.value + 10
- })
- </script>
- <style scoped lang="scss">
- .gradientBgc {
- background: linear-gradient(180deg, #9bfece, #BCFEDE);
- }
- .navbar {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- z-index: 999;
- &-box {
- position: relative;
- width: 100%;
- height: 100%;
- &-logo {
- position: absolute;
- left: 10px;
- width: 95px;
- }
- &-title {
- position: absolute;
- width: 158px;
- height: 51px;
- line-height: 51px;
- color: #0E100F;
- font-style: normal;
- text-transform: none;
- }
- }
- }
- .text-left {
- left: 10px;
- font-family: MiSans-Semibold;
- font-weight: 600;
- font-size: 38rpx;
- }
- .text-center {
- left: 50%;
- transform: translateX(-50%);
- font-family: MiSans-Medium;
- font-size: 38rpx;
- }
- </style>
|