fiee-official-website/src/components/customHeader/size1920/index.vue

222 lines
4.7 KiB
Vue
Raw Normal View History

<template>
<!-- 通用页头 -->
<NLayoutHeader
class="custom-header"
:class="{ 'header-scrolled': isScrolled }"
>
<div class="header-container">
2025-05-23 00:50:08 +00:00
<div class="logo" @click="handleToHome">
<NImage width="160" height="50" :src="FiEELogo" preview-disabled />
</div>
<div class="header-menu">
<NMenu
mode="horizontal"
:options="menuOptions"
:inverted="isScrolled"
2025-05-23 00:50:08 +00:00
v-model:value="selectedKey"
@update:value="handleMenuSelect"
/>
</div>
</div>
</NLayoutHeader>
</template>
<script setup>
2025-05-23 06:46:38 +00:00
import FiEELogo from '@/assets/image/header/logo.png'
import { ref, onMounted, onUnmounted } from 'vue'
import { NMenu, NLayoutHeader, NImage } from 'naive-ui'
import { useI18n } from 'vue-i18n'
import { useRouter } from 'vue-router'
import { useHeaderMenuConfig } from '@/config/headerMenuConfig'
2025-05-23 06:46:38 +00:00
const { t } = useI18n()
const router = useRouter()
2025-05-23 00:50:08 +00:00
// 使用统一的菜单配置
2025-05-23 06:46:38 +00:00
const menuOptions = useHeaderMenuConfig()
const selectedKey = ref(null)
2025-05-23 00:50:08 +00:00
2025-05-23 06:46:38 +00:00
const isScrolled = ref(false)
// 递归查找菜单项
function findMenuOptionByKey(options, key) {
for (const option of options) {
2025-05-23 06:46:38 +00:00
if (option.key === key) return option
if (option.children) {
2025-05-23 06:46:38 +00:00
const found = findMenuOptionByKey(option.children, key)
if (found) return found
}
}
2025-05-23 06:46:38 +00:00
return null
}
// 菜单点击跳转
const handleMenuSelect = (key) => {
2025-05-23 06:46:38 +00:00
const option = findMenuOptionByKey(menuOptions, key)
if (option && option.href) {
2025-05-23 06:46:38 +00:00
router.push(option.href)
}
2025-05-23 06:46:38 +00:00
}
// 监听滚动事件
const handleScroll = () => {
//滚动距离大于100px时处理对应的header样式
2025-05-23 06:46:38 +00:00
isScrolled.value = window.scrollY >= 100
}
onMounted(() => {
2025-05-23 06:46:38 +00:00
window.addEventListener('scroll', handleScroll)
})
onUnmounted(() => {
2025-05-23 06:46:38 +00:00
window.removeEventListener('scroll', handleScroll)
})
2025-05-23 00:50:08 +00:00
//点击回到首页
const handleToHome = () => {
2025-05-23 06:46:38 +00:00
router.push('/myhome')
selectedKey.value = null // 重置菜单选中状态
}
</script>
<style scoped lang="scss">
.custom-header {
--header-height: 5rem;
2025-05-23 04:03:48 +00:00
--primary-color: #8b59f7;
transition: all 0.3s ease;
background: transparent;
height: var(--header-height);
&.header-scrolled {
background: rgba(220, 207, 248, 0.95);
2025-05-23 00:50:08 +00:00
backdrop-filter: blur(8px);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
}
.header-container {
2025-05-23 00:50:08 +00:00
max-width: 1700px;
margin: 0 auto;
2025-05-23 00:50:08 +00:00
padding: 0 40px;
height: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.logo {
flex-shrink: 0;
2025-05-23 00:50:08 +00:00
cursor: pointer;
transition: transform 0.3s ease;
margin-right: 100px;
&:hover {
transform: scale(1.05);
}
&:active {
transform: scale(0.98);
}
}
.header-menu {
display: block;
2025-05-23 00:50:08 +00:00
flex: 1;
:deep(.n-menu) {
background: transparent;
justify-content: flex-end;
}
:deep(.n-menu-item) {
position: relative;
margin: 0 20px;
transition: all 0.3s ease;
font-weight: 700;
// font-size: 16px;
font-size: 1.05rem;
2025-05-23 00:50:08 +00:00
min-width: 120px;
text-align: center;
&::after {
2025-05-23 06:46:38 +00:00
content: '';
2025-05-23 00:50:08 +00:00
position: absolute;
bottom: 0;
left: 50%;
width: 0;
height: 2px;
background: var(--primary-color);
transition: all 0.3s ease;
transform: translateX(-50%);
opacity: 0;
border-radius: 2px;
}
&:hover {
&::after {
width: 80px;
height: 3px;
opacity: 1;
}
}
// 选中状态的样式
&.n-menu-item--selected {
&::after {
width: 40px;
opacity: 1;
}
}
}
// 子菜单样式
:deep(.n-submenu) {
.n-submenu-children {
backdrop-filter: blur(16px);
background: rgba(255, 255, 255, 0.9);
border-radius: 12px;
padding: 8px 0;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
transform-origin: top;
animation: dropDown 0.3s ease;
.n-menu-item {
position: relative;
overflow: hidden;
&::before {
2025-05-23 06:46:38 +00:00
content: '';
2025-05-23 00:50:08 +00:00
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--primary-color);
transform: translateX(-100%);
transition: transform 0.3s ease;
opacity: 0.1;
z-index: -1;
}
&:hover {
&::before {
transform: translateX(0);
}
}
}
}
}
}
@keyframes dropDown {
from {
opacity: 0;
transform: translateY(-10px) scale(0.95);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
</style>