customNav.vue 2.03 KB
<template>
    <view class="custom-nav" :style="{ height: statusBarHeight + 'px' }">
        <view :style="{ height: statusBarHeight + 'px' }"></view>
        <view class="nav-content">
            <view class="nav-left" @click="onBack">
                <uni-icons type="left" size="24" color="#333" />
            </view>
            <view class="nav-title">车辆详情</view>
        </view>
    </view>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-facing-decorator';

@Component({})
export default class customNav extends Vue {
    // 状态栏高度(微信小程序中由系统提供)
    @Prop({ type: Number, required: false, default: 48 })
    statusBarHeight: number;

    onBack() {
        const pages = getCurrentPages();
        if (pages.length <= 1) {
            uni.switchTab({ url: '/pages/tabbar/HomePage' });
            return;
        }
        const previousRoute = pages[pages.length - 2]?.route || '';
        if (previousRoute === 'module/auction/AuctionVehiclePage') {
            uni.switchTab({ url: '/pages/tabbar/AuctionPage' });
            return;
        }
        uni.navigateBack({
            delta: 1,
            fail: () => {
                uni.switchTab({ url: '/pages/tabbar/HomePage' });
            },
        });
    }
}
</script>

<style scoped lang="scss">
.custom-nav {
    width: 100%;
    position: fixed;
    top: -1px;
    left: 0;
    z-index: 999; // 确保在页面内容上方
    background: #ffffff;
}

.nav-content {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    height: 44px;
    background: #ffffff;
}

.nav-left {
    position: absolute;
    left: 2px;
    width: 80rpx;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-icon {
    font-size: 36rpx;
    color: #333;
}

.nav-title {
    font-size: 32rpx;
    color: #333;
    font-weight: 400;
}

.nav-right {
    position: absolute;
    right: 16rpx;
    height: 100%;
    display: flex;
    align-items: center;
}
</style>