Files
param-hub-python/templates/index.html
hubian 842663278c fix: 添加动态分类页面路由和模板
修复问题:
- 新增类别的详情页面路由不存在
- 导航栏缺少后台入口

新增:
- /category/{id} 路由
- category.html 模板页面
- 导航栏添加后台入口
2026-04-09 12:22:56 +08:00

202 lines
9.3 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ParamHub - 参数百科</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
</head>
<body class="bg-gray-50 min-h-screen">
<!-- 导航栏 -->
<nav class="bg-white shadow-sm sticky top-0 z-50">
<div class="max-w-7xl mx-auto px-4 py-3 flex justify-between items-center">
<div class="flex items-center gap-2">
<i class="ri-dashboard-3-line text-2xl text-indigo-600"></i>
<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>
</div>
</nav>
<!-- 主内容 -->
<main class="max-w-7xl mx-auto px-4 py-8">
<!-- 搜索框 -->
<div class="bg-white rounded-xl shadow-sm p-6 mb-8">
<div class="flex gap-4">
<div class="flex-1 relative">
<i class="ri-search-line absolute left-4 top-1/2 -translate-y-1/2 text-gray-400"></i>
<input type="text" id="searchInput" placeholder="搜索参数..."
class="w-full pl-12 pr-4 py-3 border border-gray-200 rounded-lg focus:outline-none focus:border-indigo-400 text-lg"
onkeyup="if(event.key==='Enter')search()">
</div>
<button onclick="search()" class="px-6 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition">
<i class="ri-search-line mr-2"></i>搜索
</button>
</div>
</div>
<!-- 统计卡片 - 动态生成 -->
<div class="grid grid-cols-4 gap-4 mb-8" id="statsCards">
<div class="text-center text-gray-400 py-8">加载中...</div>
</div>
<!-- 分类快捷入口 - 动态生成 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
<i class="ri-folder-line text-indigo-600"></i>
参数分类
</h2>
<div id="categoryCards" class="grid grid-cols-4 gap-4">
<div class="text-center text-gray-400 py-8">加载中...</div>
</div>
</div>
<!-- 热门模型 -->
<div class="bg-white rounded-xl shadow-sm p-6">
<h2 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2">
<i class="ri-flashlight-line text-indigo-600"></i>
热门模型
</h2>
<div id="latestModels" class="grid grid-cols-2 gap-4">
<div class="text-center text-gray-400 py-8">加载中...</div>
</div>
</div>
</main>
<!-- 页脚 -->
<footer class="bg-white border-t mt-8 py-6 text-center text-gray-500 text-sm">
ParamHub - 参数百科 | AI模型与硬件参数速查平台
</footer>
<script>
let categories = [];
const colorMap = {
blue: {bg: 'bg-blue-500', gradient: 'from-blue-500 to-blue-600', icon: 'text-blue-500'},
green: {bg: 'bg-green-500', gradient: 'from-green-500 to-green-600', icon: 'text-green-500'},
purple: {bg: 'bg-purple-500', gradient: 'from-purple-500 to-purple-600', icon: 'text-purple-500'},
orange: {bg: 'bg-orange-500', gradient: 'from-orange-500 to-orange-600', icon: 'text-orange-500'},
teal: {bg: 'bg-teal-500', gradient: 'from-teal-500 to-teal-600', icon: 'text-teal-500'},
red: {bg: 'bg-red-500', gradient: 'from-red-500 to-red-600', icon: 'text-red-500'}
};
// 加载分类和数据统计
async function loadData() {
// 并行加载分类和统计
const [catRes, statsRes] = await Promise.all([
fetch('/api/categories'),
fetch('/api/stats')
]);
categories = await catRes.json();
const stats = await statsRes.json();
// 渲染统计卡片
renderStatsCards(stats);
// 渲染分类卡片
renderCategoryCards();
// 渲染热门模型
renderLatestModels(stats.latest_models || []);
}
// 渲染统计卡片
function renderStatsCards(stats) {
const statItems = [
{key: 'models_count', label: 'AI模型', icon: 'ri-robot-line', color: 'blue'},
{key: 'gpus_count', label: 'GPU显卡', icon: 'ri-cpu-line', color: 'green'},
{key: 'cpus_count', label: 'CPU处理器', icon: 'ri-memory-line', color: 'purple'},
{key: 'knowledge_count', label: '知识条目', icon: 'ri-book-open-line', color: 'teal'}
];
document.getElementById('statsCards').innerHTML = statItems.map(item => {
const c = colorMap[item.color] || colorMap.blue;
return `
<div class="bg-gradient-to-r ${c.gradient} rounded-xl p-5 text-white">
<div class="flex items-center gap-3">
<i class="${item.icon} text-3xl opacity-80"></i>
<div>
<div class="text-2xl font-bold">${stats[item.key] || 0}</div>
<div class="text-sm opacity-80">${item.label}</div>
</div>
</div>
</div>
`;
}).join('');
}
// 渲染分类卡片
function renderCategoryCards() {
if (categories.length === 0) {
document.getElementById('categoryCards').innerHTML = '<div class="col-span-4 text-center text-gray-400 py-8">暂无分类</div>';
return;
}
// 内置页面映射
const pageMap = {
'ai-models': '/models',
'gpus': '/gpus',
'cpus': '/cpus'
};
document.getElementById('categoryCards').innerHTML = categories.map(cat => {
const c = colorMap[cat.color] || colorMap.blue;
const link = pageMap[cat.id] || `/category/${cat.id}`;
return `
<a href="${link}" class="bg-white rounded-xl shadow-sm p-5 hover:shadow-md transition group">
<div class="text-center">
<div class="w-14 h-14 rounded-xl ${c.bg} bg-opacity-10 flex items-center justify-center mx-auto group-hover:scale-110 transition">
<i class="${cat.icon} text-3xl ${c.icon}"></i>
</div>
<div class="mt-3 font-medium text-gray-800">${cat.name}</div>
<div class="text-xs text-gray-500 mt-1 truncate">${cat.description || ''}</div>
</div>
</a>
`;
}).join('');
}
// 渲染热门模型
function renderLatestModels(models) {
if (models.length === 0) {
document.getElementById('latestModels').innerHTML = '<div class="col-span-2 text-center text-gray-400 py-8">暂无数据</div>';
return;
}
document.getElementById('latestModels').innerHTML = models.map(m => `
<a href="/models" class="flex items-center gap-4 p-4 rounded-lg hover:bg-gray-50 transition">
<div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600 font-bold">
${m.name.substring(0, 2)}
</div>
<div class="flex-1">
<div class="font-medium text-gray-800">${m.name}</div>
<div class="text-sm text-gray-500">${m.organization} | ${m.parameters}B参数</div>
</div>
<div class="text-sm text-gray-400">${m.is_open_source ? '开源' : '商业'}</div>
</a>
`).join('');
}
// 搜索
async function search() {
const keyword = document.getElementById('searchInput').value.trim();
if (!keyword) return;
window.location.href = `/models?q=${encodeURIComponent(keyword)}`;
}
// 初始化
loadData();
</script>
</body>
</html>