2026-04-03 08:38:34 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<!-- 状态栏占位 -->
|
2026-04-14 08:46:29 +08:00
|
|
|
|
<!-- <view class="nav-placeholder" :style="{ height: 35 + 'px' }"></view> -->
|
2026-04-03 08:38:34 +08:00
|
|
|
|
|
2026-04-14 08:46:29 +08:00
|
|
|
|
<view class="navbar" :style="{ height: navHeight + 'rpx' }">
|
2026-04-23 14:35:54 +08:00
|
|
|
|
<view class="left" @tap="goBack">
|
2026-04-14 08:46:29 +08:00
|
|
|
|
<uni-icons type="left" size="18" v-if="showBack" />
|
2026-04-03 08:38:34 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
|
2026-04-07 10:55:39 +08:00
|
|
|
|
<!-- 标题 -->
|
2026-04-03 08:38:34 +08:00
|
|
|
|
<view class="title">{{ title }}</view>
|
|
|
|
|
|
|
2026-04-07 10:55:39 +08:00
|
|
|
|
<!-- 右侧插槽 -->
|
2026-04-03 08:38:34 +08:00
|
|
|
|
<view class="right">
|
|
|
|
|
|
<slot name="right"></slot>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
2026-04-14 08:46:29 +08:00
|
|
|
|
<!-- <view class="contentBox"></view> -->
|
2026-04-03 08:38:34 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
import { ref, onMounted, toRefs } from 'vue'
|
2026-04-07 10:55:39 +08:00
|
|
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
|
|
|
|
import { getTabBarList } from '../until'
|
2026-04-14 08:46:29 +08:00
|
|
|
|
import { findIndex } from 'lodash'
|
2026-04-07 10:55:39 +08:00
|
|
|
|
|
2026-04-03 08:38:34 +08:00
|
|
|
|
const props = defineProps({
|
2026-04-07 10:55:39 +08:00
|
|
|
|
title: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
default: ''
|
|
|
|
|
|
},
|
|
|
|
|
|
backUrl: {
|
|
|
|
|
|
type: String,
|
|
|
|
|
|
default: ''
|
|
|
|
|
|
},
|
|
|
|
|
|
showBack: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: true
|
|
|
|
|
|
}
|
2026-04-03 08:38:34 +08:00
|
|
|
|
})
|
2026-04-07 10:55:39 +08:00
|
|
|
|
|
|
|
|
|
|
const { backUrl, title, showBack } = toRefs(props)
|
|
|
|
|
|
|
|
|
|
|
|
// 状态栏 + 导航栏高度
|
2026-04-03 08:38:34 +08:00
|
|
|
|
const statusBarHeight = ref(0)
|
|
|
|
|
|
const navHeight = ref(0)
|
2026-04-07 10:55:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 返回目标路由
|
|
|
|
|
|
const backTarget = ref('')
|
|
|
|
|
|
const isTabBar = ref('')
|
|
|
|
|
|
|
|
|
|
|
|
// 获取系统信息
|
2026-04-03 08:38:34 +08:00
|
|
|
|
onMounted(() => {
|
2026-04-07 10:55:39 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const res = uni.getSystemInfoSync()
|
2026-04-14 08:46:29 +08:00
|
|
|
|
|
2026-04-07 10:55:39 +08:00
|
|
|
|
statusBarHeight.value = res.statusBarHeight || 0
|
2026-04-14 08:46:29 +08:00
|
|
|
|
console.log(statusBarHeight, 'statusBarHeight==>');
|
2026-04-07 10:55:39 +08:00
|
|
|
|
// 标准导航栏高度 44px + 状态栏 = 总高度
|
2026-04-14 08:46:29 +08:00
|
|
|
|
navHeight.value = statusBarHeight.value + 60
|
2026-04-07 10:55:39 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.warn('获取系统信息失败', e)
|
|
|
|
|
|
}
|
2026-04-03 08:38:34 +08:00
|
|
|
|
})
|
2026-04-07 10:55:39 +08:00
|
|
|
|
|
|
|
|
|
|
//页面加载时获取上一页路由
|
2026-04-03 08:38:34 +08:00
|
|
|
|
onLoad(() => {
|
2026-04-07 10:55:39 +08:00
|
|
|
|
const tabList = getTabBarList()
|
|
|
|
|
|
const isTabBarNav = findIndex(tabList, (i) => i.pagePath == backUrl.value) != -1
|
2026-04-14 08:46:29 +08:00
|
|
|
|
console.log(tabList, backUrl, isTabBarNav);
|
2026-04-07 10:55:39 +08:00
|
|
|
|
isTabBar.value = isTabBarNav
|
2026-04-03 08:38:34 +08:00
|
|
|
|
|
2026-04-07 10:55:39 +08:00
|
|
|
|
if (backUrl.value) {
|
|
|
|
|
|
backTarget.value = backUrl.value
|
|
|
|
|
|
return
|
2026-04-03 08:38:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 10:55:39 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const pages = getCurrentPages()
|
|
|
|
|
|
if (pages && pages.length >= 2) {
|
|
|
|
|
|
const prevPage = pages[pages.length - 2]
|
|
|
|
|
|
backTarget.value = prevPage.route || ''
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.warn('获取页面栈失败', e)
|
|
|
|
|
|
}
|
2026-04-03 08:38:34 +08:00
|
|
|
|
})
|
2026-04-07 10:55:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 返回逻辑
|
2026-04-03 08:38:34 +08:00
|
|
|
|
const goBack = () => {
|
2026-04-07 10:55:39 +08:00
|
|
|
|
if (!showBack.value) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (backTarget.value) {
|
|
|
|
|
|
const url = backTarget.value.startsWith('/') ? backTarget.value : `/${backTarget.value}`;
|
2026-04-03 08:38:34 +08:00
|
|
|
|
|
2026-04-07 10:55:39 +08:00
|
|
|
|
if (isTabBar.value) uni.switchTab({ url: url })
|
|
|
|
|
|
else uni.navigateTo({ url: url })
|
2026-04-03 08:38:34 +08:00
|
|
|
|
} else {
|
2026-04-07 10:55:39 +08:00
|
|
|
|
// 无目标路由 正常返回
|
2026-04-03 08:38:34 +08:00
|
|
|
|
uni.navigateBack()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2026-04-07 10:55:39 +08:00
|
|
|
|
.nav-placeholder {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 导航栏主体:fixed 固定在顶部 */
|
2026-04-03 08:38:34 +08:00
|
|
|
|
.navbar {
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
top: 0;
|
|
|
|
|
|
left: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
padding: 0 20rpx;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
z-index: 999;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.left {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-04-07 10:55:39 +08:00
|
|
|
|
justify-content: center;
|
|
|
|
|
|
width: 40rpx;
|
|
|
|
|
|
height: 100%;
|
2026-04-03 08:38:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.title {
|
2026-04-14 08:46:29 +08:00
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
text-align: center;
|
2026-04-07 10:55:39 +08:00
|
|
|
|
color: #333;
|
|
|
|
|
|
max-width: 400rpx;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
text-overflow: ellipsis;
|
2026-04-03 08:38:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.right {
|
|
|
|
|
|
min-width: 60rpx;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 10:55:39 +08:00
|
|
|
|
.content {
|
2026-04-03 08:38:34 +08:00
|
|
|
|
width: 100%;
|
2026-04-07 10:55:39 +08:00
|
|
|
|
box-sizing: border-box;
|
2026-04-03 08:38:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|