- 新增发布日期(publish_date)、热度(views)、置顶(is_pinned)字段 - 后台管理表格显示新字段和置顶操作按钮 - 前端默认排序:置顶优先 → 发布日期最新 - 新增多种排序选项:发布日期、热度、名称等 - 新增图片上传API(支持多图上传) - 后台管理表单添加图片上传组件(支持文件选择和粘贴) - 数据创建时自动初始化新字段
199 lines
8.7 KiB
HTML
199 lines
8.7 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>
|
|
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
|
|
<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">
|
|
<a href="/" 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>
|
|
</a>
|
|
</div>
|
|
<div class="flex gap-4 text-sm" id="topNav">
|
|
<!-- 动态加载 -->
|
|
</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-6">
|
|
<div class="flex items-center gap-4">
|
|
<div class="w-16 h-16 rounded-xl bg-indigo-100 flex items-center justify-center">
|
|
<i class="{{ category.icon or 'ri-folder-line' }} text-3xl text-indigo-600"></i>
|
|
</div>
|
|
<div>
|
|
<h1 class="text-2xl font-bold text-gray-800">{{ category.name }}</h1>
|
|
<p class="text-gray-500 mt-1">{{ category.description or '参数数据' }}</p>
|
|
</div>
|
|
<div class="ml-auto">
|
|
<span class="text-sm text-gray-400">共 <span id="itemCount">0</span> 条数据</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 搜索和筛选 -->
|
|
<div class="bg-white rounded-xl shadow-sm p-4 mb-6">
|
|
<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-2 border border-gray-200 rounded-lg focus:outline-none focus:border-indigo-400"
|
|
onkeyup="filterItems()">
|
|
</div>
|
|
<select id="sortBy" onchange="loadItems()" class="px-4 py-2 border border-gray-200 rounded-lg focus:outline-none">
|
|
<option value="default">默认排序(置顶优先)</option>
|
|
<option value="publish_date">按发布日期</option>
|
|
<option value="views">按热度</option>
|
|
<option value="name">按名称</option>
|
|
<option value="created_at">按创建时间</option>
|
|
</select>
|
|
<select id="sortOrder" onchange="loadItems()" class="px-4 py-2 border border-gray-200 rounded-lg focus:outline-none">
|
|
<option value="desc">降序</option>
|
|
<option value="asc">升序</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 数据列表 -->
|
|
<div class="bg-white rounded-xl shadow-sm p-6">
|
|
<div id="itemsList" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 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 - 参数百科
|
|
</footer>
|
|
|
|
<script>
|
|
const categoryId = '{{ category.id }}';
|
|
let allItems = [];
|
|
let categories = [];
|
|
|
|
// 加载导航
|
|
async function loadNav() {
|
|
const res = await fetch('/api/categories');
|
|
categories = await res.json();
|
|
|
|
// 内置页面映射
|
|
const builtinPages = [
|
|
{id: 'home', name: '首页', href: '/'},
|
|
{id: 'tools', name: '工具', href: '/tools'},
|
|
{id: 'compare', name: '对比', href: '/compare'},
|
|
{id: 'knowledge', name: '知识库', href: '/knowledge'}
|
|
];
|
|
|
|
// 内置分类映射
|
|
const categoryPages = {
|
|
'ai-models': '/models',
|
|
'gpus': '/gpus',
|
|
'cpus': '/cpus'
|
|
};
|
|
|
|
let navHtml = '';
|
|
|
|
// 先添加内置页面
|
|
builtinPages.forEach(p => {
|
|
const isActive = 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}`;
|
|
const isActive = cat.id === categoryId;
|
|
navHtml += `<a href="${href}" class="${isActive ? 'text-indigo-600 font-medium' : 'text-gray-600 hover:text-indigo-600'}">${cat.name}</a>`;
|
|
});
|
|
|
|
document.getElementById('topNav').innerHTML = navHtml;
|
|
}
|
|
|
|
// 加载数据
|
|
async function loadItems() {
|
|
const sortBy = document.getElementById('sortBy').value;
|
|
const sortOrder = document.getElementById('sortOrder').value;
|
|
const res = await fetch(`/api/items/${categoryId}?sort=${sortBy}&order=${sortOrder}`);
|
|
allItems = await res.json();
|
|
|
|
document.getElementById('itemCount').textContent = allItems.length;
|
|
renderItems(allItems);
|
|
}
|
|
|
|
// 渲染数据
|
|
function renderItems(items) {
|
|
if (items.length === 0) {
|
|
document.getElementById('itemsList').innerHTML = `
|
|
<div class="col-span-3 text-center py-12">
|
|
<i class="ri-inbox-line text-4xl text-gray-300 mb-4 block"></i>
|
|
<p class="text-gray-400">暂无数据</p>
|
|
</div>
|
|
`;
|
|
return;
|
|
}
|
|
|
|
document.getElementById('itemsList').innerHTML = items.map(item => {
|
|
const fields = Object.entries(item)
|
|
.filter(([key, val]) => !['id', 'category_id', 'created_at', 'updated_at', 'visible', 'is_pinned', 'views', 'publish_date'].includes(key) && val)
|
|
.slice(0, 5)
|
|
.map(([key, val]) => `<span class="text-gray-500 text-sm">${key}: ${val}</span>`)
|
|
.join('<br>');
|
|
|
|
return `
|
|
<div class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition group ${item.is_pinned ? 'bg-yellow-50 border-yellow-300' : ''}">
|
|
<div class="flex items-start justify-between">
|
|
<div>
|
|
<h3 class="font-medium text-gray-800 group-hover:text-indigo-600 flex items-center gap-2">
|
|
${item.is_pinned ? '<i class="ri-pushpin-fill text-yellow-500" title="置顶"></i>' : ''}
|
|
${item.name || item.title || '未命名'}
|
|
</h3>
|
|
<div class="mt-2 space-y-1">
|
|
${fields}
|
|
</div>
|
|
</div>
|
|
<div class="text-right">
|
|
<div class="text-xs text-gray-400">
|
|
${item.publish_date || (item.created_at ? item.created_at.split(' ')[0] : '')}
|
|
</div>
|
|
${item.views ? `<div class="text-xs text-gray-400 mt-1"><i class="ri-eye-line"></i> ${item.views}</div>` : ''}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}).join('');
|
|
}
|
|
|
|
// 搜索过滤
|
|
function filterItems() {
|
|
const keyword = document.getElementById('searchInput').value.trim().toLowerCase();
|
|
if (!keyword) {
|
|
renderItems(allItems);
|
|
return;
|
|
}
|
|
|
|
const filtered = allItems.filter(item => {
|
|
return Object.values(item).some(val =>
|
|
String(val).toLowerCase().includes(keyword)
|
|
);
|
|
});
|
|
renderItems(filtered);
|
|
}
|
|
|
|
// 初始化
|
|
loadNav();
|
|
loadItems();
|
|
</script>
|
|
</body>
|
|
</html> |