123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <template>
- <view v-if="!hideNavbar" class="nav-bar" :class="{ 'nav-bar-transparent': transparent }">
- <view class="nav-bar-status" :style="{ height: statusBarHeight + 'px' }">
- </view>
- <view class="nav-bar-title" :style="{ height: titleBarHeight +'px' }">
- <template v-if="showTitle">
- <view class="btn-back" @click="goBack">
- <van-icon v-if="hasParent" name="arrow-left" />
- </view>
- <view class="nav-bar-title-text">{{ title }} </view>
- <view></view>
- </template>
- <template v-else>
- <slot></slot>
- </template>
- </view>
- </view>
-
- </template>
- <script>
- export default {
- props: {
- title: String,
- transparent: Boolean,
- showTitle: {
- type: Boolean,
- default: true
- }
- },
- computed: {
- hasParent() {
- return getCurrentPages().length > 1
- }
- },
- data() {
- return {
- hideNavbar: false,
- titleBarHeight: 0,
- statusBarHeight: 0,
- isNotchScreen: false
- }
- },
- created() {
- const self = this
- const windowInfo = uni.getWindowInfo()
- this.statusBarHeight = windowInfo.statusBarHeight
- const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
- this.titleBarHeight = (menuButtonInfo.top - this.statusBarHeight) * 2 + menuButtonInfo.height + (windowInfo.screenWidth / 750 * 16)
- if (this.showTitle) {
- uni.getSystemInfo({
- success(res) {
- const os = res.system.toLowerCase()
- self.$config.os = os
- if (os.includes('windows') || os.includes('mac')) {
- // 可在pc端隐藏导航
- self.$emit('init', {
- detail: {
- navbarHeight: 0,
- pageHeight: windowInfo.screenHeight
- }
- })
- self.hideNavbar = true
-
- // self.statusBarHeight = 0
- // self.titleBarHeight = (windowInfo.screenWidth / 750 * 100)
- // self.$emit('init', {
- // detail: {
- // navbarHeight: (windowInfo.screenWidth / 750 * 100),
- // pageHeight: windowInfo.screenHeight - (windowInfo.screenWidth / 750 * 100)
- // }
- // })
- }
- }
- })
- } else {
- uni.getSystemInfo({
- success(res) {
- const os = res.system.toLowerCase()
- self.$config.os = os
- if (os.includes('windows') || os.includes('mac')) {
- self.statusBarHeight = 0
- self.titleBarHeight = (windowInfo.screenWidth / 750 * 120)
- self.$emit('init', {
- detail: {
- navbarHeight: (windowInfo.screenWidth / 750 * 120),
- pageHeight: windowInfo.screenHeight - (windowInfo.screenWidth / 750 * 120)
- }
- })
- }
- }
- })
- }
- this.$emit('init', {
- detail: {
- navbarHeight: self.hideNavbar ? 0 : (this.statusBarHeight + this.titleBarHeight),
- pageHeight: windowInfo.screenHeight - (self.hideNavbar ? 0 : (this.statusBarHeight + this.titleBarHeight))
- }
- })
- },
- methods: {
- hasSlot() {
- const nodes = this.getRelationNodes(`view`);
- return nodes.length > 0;
- },
- goBack() {
- uni.navigateBack()
- }
- }
- }
- </script>
- <style lang="scss">
- .nav-bar {
- background: linear-gradient( 270deg, #2b2359 9%, #405491 44%, #2b2359 92%), rgba(0,0,0,0.2);
- &.nav-bar-transparent{
- background: none;
- .nav-bar-title{
- view{
- color: #333333;
- }
- }
- }
- .nav-bar-title{
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 32rpx;
- view{
- color: #ffffff;
- }
- }
- .nav-bar-title-text{
- flex: 1;
- font-weight: 500;
- font-size: $fontSize6;
- line-height: 42rpx;
- text-align: left;
- text-transform: none;
- padding-left: 8rpx;
- }
- .btn-back{
- padding: 0 6rpx;
- cursor: pointer;
- }
- }
- </style>
|