fix: 统一web_result项目导航栏组件化

详细说明:
- 创建共享的导航组件nav-component.js
- 动态检测页面位置自动调整路径
- 修复index.html和所有子页面导航链接不一致问题
- 统一Logo样式和响应式设计
- 添加移动端菜单支持
This commit is contained in:
Yep_Q
2025-09-09 20:34:34 +08:00
parent 3e7d0f39f8
commit e665ee15ea
8 changed files with 154 additions and 261 deletions

View File

@@ -118,47 +118,7 @@
<!-- Navigation --> <!-- Navigation -->
<nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300" id="navbar"> <nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300" id="navbar">
<div class="container mx-auto px-6 py-4"> <!-- Content will be dynamically generated by nav-component.js -->
<div class="flex items-center justify-between">
<div class="flex items-center fade-in-left">
<div class="w-10 h-10 bg-gradient-to-br from-emerald-400 to-blue-500 rounded-lg flex items-center justify-center mr-3">
<i class="fas fa-charging-station text-white"></i>
</div>
<div>
<h1 class="text-lg font-bold">NEVIT 2024</h1>
<p class="text-xs text-gray-500">新能源汽车产业博览会</p>
</div>
</div>
<div class="hidden md:flex space-x-8">
<a href="index.html" class="nav-link active text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-home mr-2"></i>首页
</a>
<a href="pages/overview.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-info-circle mr-2"></i>展会概览
</a>
<a href="pages/exhibition.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-th-large mr-2"></i>展览内容
</a>
<a href="pages/marketing.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-bullhorn mr-2"></i>营销推广
</a>
<a href="pages/operation.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-cogs mr-2"></i>运营服务
</a>
<a href="pages/budget.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-chart-pie mr-2"></i>预算分析
</a>
<a href="pages/risk.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-shield-alt mr-2"></i>风险评估
</a>
</div>
<div class="flex items-center space-x-4">
<button class="md:hidden p-2" id="mobileMenuBtn">
<i class="fas fa-bars text-xl"></i>
</button>
</div>
</div>
</div>
</nav> </nav>
<!-- Hero Section --> <!-- Hero Section -->
@@ -599,6 +559,7 @@
</div> </div>
</footer> </footer>
<script src="js/nav-component.js"></script>
<script src="js/main.js"></script> <script src="js/main.js"></script>
</body> </body>
</html> </html>

View File

@@ -0,0 +1,140 @@
// 导航组件 - 统一管理所有页面的导航栏
(function() {
// 检测当前页面路径,自动调整链接
const currentPath = window.location.pathname;
const isInPagesFolder = currentPath.includes('/pages/');
const currentPage = currentPath.split('/').pop() || 'index.html';
// 导航项配置
const navItems = [
{ href: 'index.html', icon: 'fa-home', text: '首页', id: 'index' },
{ href: 'overview.html', icon: 'fa-info-circle', text: '展会概览', id: 'overview' },
{ href: 'exhibition.html', icon: 'fa-th-large', text: '展览内容', id: 'exhibition' },
{ href: 'marketing.html', icon: 'fa-bullhorn', text: '营销推广', id: 'marketing' },
{ href: 'operation.html', icon: 'fa-cogs', text: '运营服务', id: 'operation' },
{ href: 'budget.html', icon: 'fa-chart-pie', text: '预算分析', id: 'budget' },
{ href: 'risk.html', icon: 'fa-shield-alt', text: '风险评估', id: 'risk' }
];
// 根据当前页面位置调整路径
function getCorrectPath(href) {
if (href === 'index.html') {
return isInPagesFolder ? '../index.html' : 'index.html';
} else {
return isInPagesFolder ? href : `pages/${href}`;
}
}
// 判断是否为当前激活页面
function isActive(href) {
return currentPage === href ||
(currentPage === '' && href === 'index.html');
}
// 生成导航HTML
function generateNavHTML() {
return `
<div class="container mx-auto px-6 py-4">
<div class="flex items-center justify-between">
<div class="flex items-center fade-in-left">
<div class="w-10 h-10 bg-gradient-to-br from-emerald-400 to-blue-500 rounded-lg flex items-center justify-center mr-3">
<i class="fas fa-charging-station text-white"></i>
</div>
<div>
<h1 class="text-lg font-bold">NEVIT 2024</h1>
<p class="text-xs text-gray-500">新能源汽车产业博览会</p>
</div>
</div>
<div class="hidden md:flex space-x-8">
${navItems.map(item => `
<a href="${getCorrectPath(item.href)}"
class="nav-link ${isActive(item.href) ? 'active' : ''} text-gray-700 hover:text-emerald-500 transition-colors"
data-nav="${item.id}">
<i class="fas ${item.icon} mr-2"></i>${item.text}
</a>
`).join('')}
</div>
<button class="md:hidden" id="mobile-menu-button">
<i class="fas fa-bars text-2xl text-gray-700"></i>
</button>
</div>
</div>
<!-- Mobile Menu -->
<div class="hidden md:hidden fixed top-16 left-0 w-full bg-white shadow-lg" id="mobile-menu">
<div class="px-6 py-4 space-y-3">
${navItems.map(item => `
<a href="${getCorrectPath(item.href)}"
class="block py-2 px-4 rounded ${isActive(item.href) ? 'bg-emerald-50 text-emerald-500' : 'text-gray-700 hover:bg-gray-50'}"
data-nav="${item.id}">
<i class="fas ${item.icon} mr-2"></i>${item.text}
</a>
`).join('')}
</div>
</div>`;
}
// 初始化导航
function initNav() {
const navElement = document.querySelector('nav') || document.getElementById('navbar');
if (navElement) {
// 保留原有的class和id
const originalClasses = navElement.className;
const originalId = navElement.id;
// 更新导航内容
navElement.innerHTML = generateNavHTML();
// 恢复原有属性
if (originalClasses) navElement.className = originalClasses;
if (originalId) navElement.id = originalId;
// 添加移动端菜单交互
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
if (mobileMenuButton && mobileMenu) {
mobileMenuButton.addEventListener('click', () => {
mobileMenu.classList.toggle('hidden');
});
// 点击菜单项后关闭移动端菜单
mobileMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.add('hidden');
});
});
}
// 添加滚动效果
let lastScrollTop = 0;
window.addEventListener('scroll', () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > lastScrollTop && scrollTop > 100) {
// 向下滚动 - 隐藏导航
navElement.style.transform = 'translateY(-100%)';
} else {
// 向上滚动 - 显示导航
navElement.style.transform = 'translateY(0)';
}
// 添加背景效果
if (scrollTop > 50) {
navElement.classList.add('bg-white/95', 'backdrop-blur-md');
} else {
navElement.classList.remove('bg-white/95', 'backdrop-blur-md');
}
lastScrollTop = scrollTop;
});
}
}
// DOM加载完成后初始化
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initNav);
} else {
initNav();
}
})();

View File

@@ -225,37 +225,7 @@
<body class="bg-gray-50"> <body class="bg-gray-50">
<!-- Navigation --> <!-- Navigation -->
<nav class="fixed top-0 w-full glass-morphism shadow-lg z-50 transition-all duration-300"> <nav class="fixed top-0 w-full glass-morphism shadow-lg z-50 transition-all duration-300">
<div class="container mx-auto px-6 py-4"> <!-- Content will be dynamically generated by nav-component.js -->
<div class="flex items-center justify-between">
<div class="flex items-center">
<h1 class="text-2xl font-bold gradient-text">NEVIT 2024</h1>
<span class="ml-3 text-sm text-gray-500">新能源汽车产业博览会</span>
</div>
<div class="hidden md:flex space-x-8">
<a href="../index.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-home mr-2"></i>首页
</a>
<a href="overview.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-info-circle mr-2"></i>展会概览
</a>
<a href="exhibition.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-th-large mr-2"></i>展览内容
</a>
<a href="marketing.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-bullhorn mr-2"></i>营销推广
</a>
<a href="operation.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-cogs mr-2"></i>运营服务
</a>
<a href="budget.html" class="nav-link active text-emerald-500">
<i class="fas fa-chart-pie mr-2"></i>预算分析
</a>
<a href="risk.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-shield-alt mr-2"></i>风险评估
</a>
</div>
</div>
</div>
</nav> </nav>
<!-- Hero Section with Parallax --> <!-- Hero Section with Parallax -->
@@ -1117,5 +1087,6 @@
counterObserver.observe(el); counterObserver.observe(el);
}); });
</script> </script>
<script src="../js/nav-component.js"></script>
</body> </body>
</html> </html>

View File

@@ -114,45 +114,7 @@
<body class="bg-gray-50"> <body class="bg-gray-50">
<!-- Navigation --> <!-- Navigation -->
<nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300"> <nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300">
<div class="container mx-auto px-6 py-4"> <!-- Content will be dynamically generated by nav-component.js -->
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="w-10 h-10 bg-gradient-to-br from-emerald-400 to-blue-500 rounded-lg flex items-center justify-center mr-3">
<i class="fas fa-charging-station text-white"></i>
</div>
<div>
<h1 class="text-lg font-bold">NEVIT 2024</h1>
<p class="text-xs text-gray-500">新能源汽车产业博览会</p>
</div>
</div>
<div class="hidden md:flex space-x-8">
<a href="../index.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-home mr-2"></i>首页
</a>
<a href="overview.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-info-circle mr-2"></i>展会概览
</a>
<a href="exhibition.html" class="nav-link active text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-th-large mr-2"></i>展览内容
</a>
<a href="marketing.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-bullhorn mr-2"></i>营销推广
</a>
<a href="operation.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-cogs mr-2"></i>运营服务
</a>
<a href="budget.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-chart-pie mr-2"></i>预算分析
</a>
<a href="risk.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-shield-alt mr-2"></i>风险评估
</a>
</div>
<button class="md:hidden text-gray-700">
<i class="fas fa-bars text-2xl"></i>
</button>
</div>
</div>
</nav> </nav>
<!-- Page Header --> <!-- Page Header -->
@@ -831,5 +793,6 @@
} }
}); });
</script> </script>
<script src="../js/nav-component.js"></script>
</body> </body>
</html> </html>

View File

@@ -117,45 +117,7 @@
<body class="bg-gray-50"> <body class="bg-gray-50">
<!-- Navigation --> <!-- Navigation -->
<nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300"> <nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300">
<div class="container mx-auto px-6 py-4"> <!-- Content will be dynamically generated by nav-component.js -->
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="w-10 h-10 bg-gradient-to-br from-emerald-400 to-blue-500 rounded-lg flex items-center justify-center mr-3">
<i class="fas fa-charging-station text-white"></i>
</div>
<div>
<h1 class="text-lg font-bold">NEVIT 2024</h1>
<p class="text-xs text-gray-500">新能源汽车产业博览会</p>
</div>
</div>
<div class="hidden md:flex space-x-8">
<a href="../index.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-home mr-2"></i>首页
</a>
<a href="overview.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-info-circle mr-2"></i>展会概览
</a>
<a href="exhibition.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-th-large mr-2"></i>展览内容
</a>
<a href="marketing.html" class="nav-link active text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-bullhorn mr-2"></i>营销推广
</a>
<a href="operation.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-cogs mr-2"></i>运营服务
</a>
<a href="budget.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-chart-pie mr-2"></i>预算分析
</a>
<a href="risk.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-shield-alt mr-2"></i>风险评估
</a>
</div>
<button class="md:hidden text-gray-700">
<i class="fas fa-bars text-2xl"></i>
</button>
</div>
</div>
</nav> </nav>
<!-- Page Header --> <!-- Page Header -->
@@ -813,5 +775,6 @@
</div> </div>
</div> </div>
</footer> </footer>
<script src="../js/nav-component.js"></script>
</body> </body>
</html> </html>

View File

@@ -146,45 +146,7 @@
<body class="bg-gray-50"> <body class="bg-gray-50">
<!-- Navigation --> <!-- Navigation -->
<nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300"> <nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300">
<div class="container mx-auto px-6 py-4"> <!-- Content will be dynamically generated by nav-component.js -->
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="w-10 h-10 bg-gradient-to-br from-emerald-400 to-blue-500 rounded-lg flex items-center justify-center mr-3">
<i class="fas fa-charging-station text-white"></i>
</div>
<div>
<h1 class="text-lg font-bold">NEVIT 2024</h1>
<p class="text-xs text-gray-600 font-medium">新能源汽车产业博览会</p>
</div>
</div>
<div class="hidden md:flex space-x-8">
<a href="../index.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-home mr-2"></i>首页
</a>
<a href="overview.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-info-circle mr-2"></i>展会概览
</a>
<a href="exhibition.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-th-large mr-2"></i>展览内容
</a>
<a href="marketing.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-bullhorn mr-2"></i>营销推广
</a>
<a href="operation.html" class="nav-link active text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-cogs mr-2"></i>运营服务
</a>
<a href="budget.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-chart-pie mr-2"></i>预算分析
</a>
<a href="risk.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-shield-alt mr-2"></i>风险评估
</a>
</div>
<button class="md:hidden text-gray-700">
<i class="fas fa-bars text-2xl"></i>
</button>
</div>
</div>
</nav> </nav>
<!-- Page Header with Background Image --> <!-- Page Header with Background Image -->
@@ -1413,5 +1375,6 @@
observer.observe(el); observer.observe(el);
}); });
</script> </script>
<script src="../js/nav-component.js"></script>
</body> </body>
</html> </html>

View File

@@ -84,45 +84,7 @@
<body class="bg-gray-50"> <body class="bg-gray-50">
<!-- Navigation --> <!-- Navigation -->
<nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300"> <nav class="fixed top-0 w-full glass-morphism shadow-md z-50 transition-all duration-300">
<div class="container mx-auto px-6 py-4"> <!-- Content will be dynamically generated by nav-component.js -->
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="w-10 h-10 bg-gradient-to-br from-emerald-400 to-blue-500 rounded-lg flex items-center justify-center mr-3">
<i class="fas fa-charging-station text-white"></i>
</div>
<div>
<h1 class="text-lg font-bold">NEVIT 2024</h1>
<p class="text-xs text-gray-500">新能源汽车产业博览会</p>
</div>
</div>
<div class="hidden md:flex space-x-8">
<a href="../index.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-home mr-2"></i>首页
</a>
<a href="overview.html" class="nav-link active text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-info-circle mr-2"></i>展会概览
</a>
<a href="exhibition.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-th-large mr-2"></i>展览内容
</a>
<a href="marketing.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-bullhorn mr-2"></i>营销推广
</a>
<a href="operation.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-cogs mr-2"></i>运营服务
</a>
<a href="budget.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-chart-pie mr-2"></i>预算分析
</a>
<a href="risk.html" class="text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-shield-alt mr-2"></i>风险评估
</a>
</div>
<button class="md:hidden text-gray-700">
<i class="fas fa-bars text-2xl"></i>
</button>
</div>
</div>
</nav> </nav>
<!-- Page Header --> <!-- Page Header -->
@@ -519,5 +481,6 @@
</div> </div>
</div> </div>
</footer> </footer>
<script src="../js/nav-component.js"></script>
</body> </body>
</html> </html>

View File

@@ -217,39 +217,7 @@
<body class="bg-gray-50"> <body class="bg-gray-50">
<!-- Navigation --> <!-- Navigation -->
<nav class="fixed top-0 w-full glass-morphism shadow-lg z-50 transition-all duration-300"> <nav class="fixed top-0 w-full glass-morphism shadow-lg z-50 transition-all duration-300">
<div class="container mx-auto px-6 py-4"> <!-- Content will be dynamically generated by nav-component.js -->
<div class="flex items-center justify-between">
<div class="flex items-center">
<h1 class="text-2xl font-bold bg-gradient-to-r from-emerald-500 to-blue-500 bg-clip-text text-transparent">
NEVIT 2024
</h1>
<span class="ml-3 text-sm text-gray-500">新能源汽车产业博览会</span>
</div>
<div class="hidden md:flex space-x-8">
<a href="../index.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-home mr-2"></i>首页
</a>
<a href="overview.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-info-circle mr-2"></i>展会概览
</a>
<a href="exhibition.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-th-large mr-2"></i>展览内容
</a>
<a href="marketing.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-bullhorn mr-2"></i>营销推广
</a>
<a href="operation.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-cogs mr-2"></i>运营服务
</a>
<a href="budget.html" class="nav-link text-gray-700 hover:text-emerald-500 transition-colors">
<i class="fas fa-chart-pie mr-2"></i>预算分析
</a>
<a href="risk.html" class="nav-link active text-emerald-500">
<i class="fas fa-shield-alt mr-2"></i>风险评估
</a>
</div>
</div>
</div>
</nav> </nav>
<!-- Hero Section with Matrix Effect --> <!-- Hero Section with Matrix Effect -->
@@ -1072,5 +1040,6 @@
progressObserver.observe(bar); progressObserver.observe(bar);
}); });
</script> </script>
<script src="../js/nav-component.js"></script>
</body> </body>
</html> </html>