fix: 前端导航栏改为动态加载

修复问题:
1. 顶部导航栏不显示后台新增的类别 → 改为从API动态加载
2. 前端页面移除"添加数据"按钮 → 数据由后台管理员管理
3. 前端移除"后台"入口 → 管理员直接访问/admin
This commit is contained in:
2026-04-09 12:36:16 +08:00
parent 842663278c
commit cb52022662
8 changed files with 269 additions and 78 deletions

View File

@@ -16,15 +16,8 @@
<span class="text-xl font-bold text-gray-800">ParamHub</span>
<span class="text-sm text-gray-500">参数百科</span>
</div>
<div class="flex gap-6 text-sm" id="navLinks">
<a href="/" class="text-indigo-600 font-medium">首页</a>
<a href="/models" class="text-gray-600 hover:text-indigo-600">模型</a>
<a href="/gpus" class="text-gray-600 hover:text-indigo-600">GPU</a>
<a href="/cpus" class="text-gray-600 hover:text-indigo-600">CPU</a>
<a href="/tools" class="text-gray-600 hover:text-indigo-600">工具</a>
<a href="/compare" class="text-gray-600 hover:text-indigo-600">对比</a>
<a href="/knowledge" class="text-gray-600 hover:text-indigo-600">知识库</a>
<a href="/admin" class="text-gray-600 hover:text-indigo-600">后台</a>
<div class="flex gap-4 text-sm" id="navLinks">
<!-- 动态加载 -->
</div>
</div>
</nav>
@@ -91,6 +84,40 @@
red: {bg: 'bg-red-500', gradient: 'from-red-500 to-red-600', icon: 'text-red-500'}
};
// 加载导航栏
function renderNavBar() {
// 内置页面
const builtinPages = [
{name: '首页', href: '/'},
{name: '工具', href: '/tools'},
{name: '对比', href: '/compare'},
{name: '知识库', href: '/knowledge'}
];
// 内置分类映射
const categoryPages = {
'ai-models': '/models',
'gpus': '/gpus',
'cpus': '/cpus'
};
let navHtml = '';
// 先添加内置页面
builtinPages.forEach(p => {
const isActive = window.location.pathname === p.href;
navHtml += `<a href="${p.href}" class="${isActive ? 'text-indigo-600 font-medium' : 'text-gray-600 hover:text-indigo-600'}">${p.name}</a>`;
});
// 添加分类
categories.forEach(cat => {
const href = categoryPages[cat.id] || `/category/${cat.id}`;
navHtml += `<a href="${href}" class="text-gray-600 hover:text-indigo-600">${cat.name}</a>`;
});
document.getElementById('navLinks').innerHTML = navHtml;
}
// 加载分类和数据统计
async function loadData() {
// 并行加载分类和统计
@@ -101,6 +128,9 @@
categories = await catRes.json();
const stats = await statsRes.json();
// 渲染导航栏
renderNavBar();
// 渲染统计卡片
renderStatsCards(stats);