文件
fenleixinxi/uniapp/components/fc-navbar/fc-navbar.vue
MiAn d508949921 feat: 规范化页面导航与交互体验,优化多端适配
- 统一定制顶部导航组件,支持沉浸式渐变主题与返回逻辑
- 适配 H5 环境的页面跳转逻辑,避免 reLaunch 导致的闪屏问题
- 重构会员、充值、发布等页面布局,改用 Grid 提升移动端适配
- 优化搜索、收藏、消息等页面交互细节,增加点击反馈
- 统一配置页面导航样式,替换原生导航为自定义组件
2026-10-20 13:56:05 +08:00

173 行
3.7 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="fc-navbar" :class="[`fc-navbar--${theme}`]">
<!-- 系统状态栏占位 -->
<view class="fc-navbar__status" :style="{ height: statusBarHeight + 'px' }"></view>
<!-- 导航内容条:精确对齐胶囊高度并避让右侧胶囊 -->
<view
class="fc-navbar__bar"
:style="{
height: barHeight + 'px',
paddingRight: capsulePadding ? (capsulePadding + 'px') : '24rpx',
}"
>
<!-- 返回按钮 -->
<view v-if="showBack" class="fc-navbar__back" @click="onBack">
<text class="fc-navbar__back-icon">‹</text>
</view>
<!-- 标题区域 -->
<view class="fc-navbar__title" :class="{ 'fc-navbar__title--center': center }">
<slot>
<text class="fc-navbar__title-text fc-ellipsis">{{ title }}</text>
</slot>
</view>
<!-- 右侧功能区(位于胶囊左侧) -->
<view class="fc-navbar__right">
<slot name="right"></slot>
</view>
</view>
</view>
</template>
<script>
import { getNavMetrics } from '@/common/utils/navbar.js'
export default {
name: 'FcNavbar',
props: {
/** 导航标题文字 */
title: { type: String, default: '' },
/** 风格主题:gradient(主色渐变白字) | white(白底黑字) */
theme: { type: String, default: 'gradient' },
/** 是否展示左侧返回按钮 */
showBack: { type: Boolean, default: false },
/** 标题文字是否居中 */
center: { type: Boolean, default: true },
},
data() {
return {
statusBarHeight: 20,
barHeight: 44,
capsulePadding: 0,
}
},
created() {
this.initMetrics()
},
methods: {
/**
* 初始化获取设备状态栏和胶囊参数
*/
initMetrics() {
const m = getNavMetrics()
this.statusBarHeight = m.statusBarHeight
this.barHeight = m.navBarHeight
this.capsulePadding = m.capsulePadding
},
/**
* 点击返回上一页,若无历史页面则返回首页
*/
onBack() {
const pages = getCurrentPages ? getCurrentPages() : []
if (pages && pages.length > 1) {
uni.navigateBack()
} else {
// #ifdef H5
uni.redirectTo({
url: '/pages/index/index',
fail: () => {
uni.reLaunch({ url: '/pages/index/index' })
},
})
// #endif
// #ifndef H5
uni.reLaunch({ url: '/pages/index/index' })
// #endif
}
},
},
}
</script>
<style lang="scss" scoped>
.fc-navbar {
position: sticky;
top: 0;
z-index: 99;
&--gradient {
background: $fc-gradient-hero;
.fc-navbar__title-text {
color: #ffffff;
}
.fc-navbar__back-icon {
color: #ffffff;
}
}
&--white {
background: #ffffff;
border-bottom: 2rpx solid $fc-border;
.fc-navbar__title-text {
color: $fc-text;
}
.fc-navbar__back-icon {
color: $fc-text;
}
}
}
.fc-navbar__bar {
display: flex;
align-items: center;
padding-left: 16rpx;
box-sizing: border-box;
position: relative;
}
.fc-navbar__back {
width: 72rpx;
height: 72rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
cursor: pointer;
border-radius: 50%;
transition: background-color 0.2s ease, transform 0.15s ease;
&:active {
transform: scale(0.92);
background-color: rgba(255, 255, 255, 0.18);
}
}
.fc-navbar--white .fc-navbar__back:active {
background-color: rgba(0, 0, 0, 0.06);
}
.fc-navbar__back-icon {
font-size: 54rpx;
line-height: 1;
font-weight: 300;
margin-top: -4rpx;
}
.fc-navbar__title {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
padding: 0 12rpx;
&--center {
justify-content: center;
text-align: center;
}
}
.fc-navbar__title-text {
font-size: $fc-font-xl;
font-weight: 700;
letter-spacing: 0.5rpx;
}
.fc-navbar__right {
position: relative;
z-index: 1;
display: flex;
align-items: center;
flex-shrink: 0;
min-width: 72rpx;
justify-content: flex-end;
}
</style>