Files
chongdun-mianya/components/credit-header/credit-header.vue
2026-11-13 09:37:34 +08:00

118 lines
2.4 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="credit-header" :class="{ 'is-curved': curved }">
<view :style="{ height: statusBarHeight + 'px' }"></view>
<view class="nav-bar">
<view v-if="showBack && canBack" class="back-btn" @tap="handleBack">
<view class="back-arrow"></view>
</view>
</view>
<view class="hero-title">
<text class="hero-slash">///</text>
<text class="hero-text">{{ title }}</text>
<text class="hero-slash">///</text>
</view>
<slot></slot>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
defineProps({
title: {
type: String,
default: ''
},
showBack: {
type: Boolean,
default: true
},
// 底部是否做成弧形(下单页)
curved: {
type: Boolean,
default: false
}
})
const statusBarHeight = ref(0)
const canBack = ref(false)
onMounted(() => {
statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight || 0
// 支付宝端用透明原生导航栏自带的返回按钮(pages.json 里 navigationBarTextStyle 已设为白色)
// 这里不再画第二个箭头;其他端没有原生导航栏,自己画。
// #ifdef MP-ALIPAY
canBack.value = false
// #endif
// #ifndef MP-ALIPAY
canBack.value = getCurrentPages().length > 1
// #endif
})
function handleBack() {
if (getCurrentPages().length > 1) {
uni.navigateBack()
}
}
</script>
<style>
.credit-header {
position: relative;
padding-bottom: 72rpx;
background: linear-gradient(180deg, #4a90ff 0%, #1e6bff 100%);
color: #ffffff;
}
/* 下单页:底部弧形,并给悬浮的品牌卡片留出上半部分高度 */
.credit-header.is-curved {
padding-bottom: 140rpx;
border-radius: 0 0 50% 50% / 0 0 96rpx 96rpx;
}
.nav-bar {
display: flex;
align-items: center;
height: 88rpx;
padding: 0 24rpx;
}
.back-btn {
display: flex;
align-items: center;
justify-content: center;
width: 72rpx;
height: 72rpx;
}
.back-arrow {
width: 22rpx;
height: 22rpx;
margin-left: 8rpx;
border-left: 4rpx solid #ffffff;
border-bottom: 4rpx solid #ffffff;
transform: rotate(45deg);
}
.hero-title {
display: flex;
align-items: center;
justify-content: center;
margin-top: 20rpx;
}
.hero-text {
font-size: 40rpx;
font-weight: 600;
letter-spacing: 4rpx;
}
.hero-slash {
margin: 0 20rpx;
font-size: 32rpx;
font-style: italic;
color: rgba(255, 255, 255, 0.55);
}
</style>