139 lines
2.8 KiB
Vue
139 lines
2.8 KiB
Vue
<script setup>
|
|
import { ref, computed } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { useSceneStore } from '../store/scene'
|
|
|
|
const router = useRouter()
|
|
const sceneStore = useSceneStore()
|
|
|
|
// 当前路由路径
|
|
const currentRoute = computed(() => router.currentRoute.value.path)
|
|
|
|
// 是否显示返回按钮
|
|
const showBackButton = computed(() => {
|
|
return currentRoute.value !== '/'
|
|
})
|
|
|
|
// 返回上一页
|
|
const goBack = () => {
|
|
router.back()
|
|
}
|
|
|
|
// 返回首页
|
|
const goHome = () => {
|
|
router.push('/')
|
|
}
|
|
|
|
// 获取页面标题
|
|
const getPageTitle = computed(() => {
|
|
const titles = {
|
|
'/': '2026新春H5',
|
|
'/qianmen': '前门商圈',
|
|
'/chongwen': '崇文商圈',
|
|
'/wangfujing': '王府井商圈',
|
|
'/longfusi': '隆福寺商圈',
|
|
'/dongzhimen': '东直门商圈',
|
|
'/ai-spring': 'AI春联生成',
|
|
'/end': '活动结束'
|
|
}
|
|
return titles[currentRoute.value] || '2026新春H5'
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<header class="common-header">
|
|
<!-- 返回按钮 -->
|
|
<div class="header-left" v-if="showBackButton" @click="goBack">
|
|
<span class="back-icon">←</span>
|
|
</div>
|
|
|
|
<!-- 空占位,保持标题居中 -->
|
|
<div class="header-left" v-else></div>
|
|
|
|
<!-- 页面标题 -->
|
|
<div class="header-title">
|
|
{{ getPageTitle }}
|
|
</div>
|
|
|
|
<!-- 右侧操作按钮 -->
|
|
<div class="header-right">
|
|
<button class="home-btn" @click="goHome" v-if="currentRoute !== '/'">
|
|
首页
|
|
</button>
|
|
</div>
|
|
</header>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.common-header {
|
|
width: 100%;
|
|
max-width: 750px;
|
|
height: 0.88rem;
|
|
background-color: #ff6b35;
|
|
color: #fff;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 0 0.2rem;
|
|
font-size: 0.32rem;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
z-index: 100;
|
|
box-shadow: 0 2px 10px rgba(255, 107, 53, 0.3);
|
|
}
|
|
|
|
.header-left,
|
|
.header-right {
|
|
width: 1rem;
|
|
height: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.header-left {
|
|
justify-content: flex-start;
|
|
}
|
|
|
|
.header-right {
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.back-icon {
|
|
font-size: 0.4rem;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.header-title {
|
|
flex: 1;
|
|
text-align: center;
|
|
font-weight: bold;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
.home-btn {
|
|
background-color: rgba(255, 255, 255, 0.2);
|
|
color: #fff;
|
|
border: none;
|
|
border-radius: 0.15rem;
|
|
padding: 0.1rem 0.2rem;
|
|
font-size: 0.24rem;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s ease;
|
|
}
|
|
|
|
.home-btn:hover {
|
|
background-color: rgba(255, 255, 255, 0.3);
|
|
}
|
|
|
|
/* 适配安全区域 */
|
|
@supports (padding-top: env(safe-area-inset-top)) {
|
|
.common-header {
|
|
padding-top: env(safe-area-inset-top);
|
|
height: calc(0.88rem + env(safe-area-inset-top));
|
|
}
|
|
}
|
|
</style> |