2025-05-22 12:30:26 +00:00
|
|
|
|
<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 />
|
2025-05-22 12:30:26 +00:00
|
|
|
|
</div>
|
|
|
|
|
<div class="header-menu">
|
|
|
|
|
<NMenu
|
|
|
|
|
mode="horizontal"
|
|
|
|
|
:options="menuOptions"
|
|
|
|
|
:inverted="isScrolled"
|
2025-05-23 00:50:08 +00:00
|
|
|
|
v-model:value="selectedKey"
|
2025-05-22 12:30:26 +00:00
|
|
|
|
@update:value="handleMenuSelect"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</NLayoutHeader>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-05-23 00:50:08 +00:00
|
|
|
|
import FiEELogo from '@/assets/image/header/logo.png'
|
2025-05-22 12:30:26 +00:00
|
|
|
|
import { ref, onMounted, onUnmounted } from 'vue'
|
|
|
|
|
import { NMenu, NLayoutHeader, NImage } from 'naive-ui'
|
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
import { useRouter } from 'vue-router'
|
2025-05-23 00:50:08 +00:00
|
|
|
|
import { useHeaderMenuConfig } from '@/config/headerMenuConfig'
|
2025-05-22 12:30:26 +00:00
|
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
2025-05-23 00:50:08 +00:00
|
|
|
|
// 使用统一的菜单配置
|
|
|
|
|
const menuOptions = useHeaderMenuConfig()
|
|
|
|
|
const selectedKey = ref(null)
|
|
|
|
|
|
2025-05-22 12:30:26 +00:00
|
|
|
|
const isScrolled = ref(false)
|
|
|
|
|
|
|
|
|
|
// 递归查找菜单项
|
|
|
|
|
function findMenuOptionByKey(options, key) {
|
|
|
|
|
for (const option of options) {
|
2025-05-22 12:51:37 +00:00
|
|
|
|
if (option.key === key) return option;
|
2025-05-22 12:30:26 +00:00
|
|
|
|
if (option.children) {
|
2025-05-22 12:51:37 +00:00
|
|
|
|
const found = findMenuOptionByKey(option.children, key);
|
|
|
|
|
if (found) return found;
|
2025-05-22 12:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-22 12:51:37 +00:00
|
|
|
|
return null;
|
2025-05-22 12:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 菜单点击跳转
|
|
|
|
|
const handleMenuSelect = (key) => {
|
2025-05-22 12:51:37 +00:00
|
|
|
|
const option = findMenuOptionByKey(menuOptions, key);
|
2025-05-22 12:30:26 +00:00
|
|
|
|
if (option && option.href) {
|
2025-05-22 12:51:37 +00:00
|
|
|
|
router.push(option.href);
|
2025-05-22 12:30:26 +00:00
|
|
|
|
}
|
2025-05-22 12:51:37 +00:00
|
|
|
|
};
|
2025-05-22 12:30:26 +00:00
|
|
|
|
|
|
|
|
|
// 监听滚动事件
|
|
|
|
|
const handleScroll = () => {
|
|
|
|
|
//滚动距离大于100px时,处理对应的header样式
|
2025-05-22 12:51:37 +00:00
|
|
|
|
isScrolled.value = window.scrollY >= 100;
|
|
|
|
|
};
|
2025-05-22 12:30:26 +00:00
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
2025-05-22 12:51:37 +00:00
|
|
|
|
window.addEventListener("scroll", handleScroll);
|
|
|
|
|
});
|
2025-05-22 12:30:26 +00:00
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
window.removeEventListener('scroll', handleScroll)
|
|
|
|
|
})
|
2025-05-23 00:50:08 +00:00
|
|
|
|
|
|
|
|
|
//点击回到首页
|
|
|
|
|
const handleToHome = () => {
|
|
|
|
|
router.push('/')
|
|
|
|
|
selectedKey.value = null // 重置菜单选中状态
|
|
|
|
|
}
|
2025-05-22 12:30:26 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.custom-header {
|
|
|
|
|
--header-height: 80px;
|
2025-05-23 00:50:08 +00:00
|
|
|
|
--primary-color: #8B59F7;
|
2025-05-22 12:30:26 +00:00
|
|
|
|
position: fixed;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
z-index: 1000;
|
|
|
|
|
transition: all 0.3s ease;
|
|
|
|
|
background: transparent;
|
|
|
|
|
height: var(--header-height);
|
|
|
|
|
|
|
|
|
|
&.header-scrolled {
|
|
|
|
|
background: rgba(255, 255, 255, 0.95);
|
2025-05-23 00:50:08 +00:00
|
|
|
|
backdrop-filter: blur(8px);
|
2025-05-22 12:30:26 +00:00
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.header-container {
|
2025-05-23 00:50:08 +00:00
|
|
|
|
max-width: 1700px;
|
2025-05-22 12:30:26 +00:00
|
|
|
|
margin: 0 auto;
|
2025-05-23 00:50:08 +00:00
|
|
|
|
padding: 0 40px;
|
2025-05-22 12:30:26 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2025-05-22 12:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.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;
|
|
|
|
|
min-width: 120px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
|
content: '';
|
|
|
|
|
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 {
|
|
|
|
|
content: '';
|
|
|
|
|
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);
|
|
|
|
|
}
|
2025-05-22 12:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
</style>
|