Files
product-crawler/templates/index.html
hubian 7b20773c29 feat: v2.0.0 - 合并后台管理到单端口
- 端口从 19011+19012 合并为 19011
- 前台API: http://localhost:19011
- 后台管理: http://localhost:19011/admin
- 新增 templates 目录,整合管理页面模板
- 更新所有路由为 /admin 路径
2026-04-13 10:59:00 +08:00

199 lines
10 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>产品爬取系统 - 后台管理</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
<style>
.gradient-bg { background: linear-gradient(135deg, #10b981 0%, #059669 100%); }
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="flex">
<!-- 侧边栏 -->
<aside class="w-64 bg-slate-800 min-h-screen fixed left-0 top-0">
<div class="p-6">
<h1 class="text-white text-xl font-bold flex items-center gap-2">
<i class="ri-spider-line text-2xl text-emerald-400"></i>
Product Crawler
</h1>
<p class="text-slate-400 text-sm mt-1">产品爬取系统</p>
</div>
<nav class="mt-6">
<a href="/admin" class="flex items-center gap-3 px-6 py-3 bg-slate-700 text-white">
<i class="ri-dashboard-line"></i><span>仪表盘</span>
</a>
<a href="/admin/spiders" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-spider-line"></i><span>爬虫管理</span>
</a>
<a href="/admin/products" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-product-hunt-line"></i><span>产品数据</span>
</a>
<a href="/admin/tasks" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-task-line"></i><span>任务记录</span>
</a>
<a href="/admin/config" class="flex items-center gap-3 px-6 py-3 text-slate-300 hover:bg-slate-700 hover:text-white">
<i class="ri-settings-3-line"></i><span>系统配置</span>
</a>
</nav>
</aside>
<!-- 主内容 -->
<main class="ml-64 flex-1 p-8">
<!-- 顶部 -->
<div class="mb-8">
<h1 class="text-2xl font-bold text-gray-800">仪表盘</h1>
<p class="text-gray-500 text-sm mt-1">产品参数爬取系统概览</p>
</div>
<!-- 统计卡片 -->
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500 text-sm">产品总数</p>
<p id="statProducts" class="text-3xl font-bold text-gray-800 mt-1">-</p>
</div>
<div class="w-12 h-12 bg-emerald-100 rounded-xl flex items-center justify-center">
<i class="ri-product-hunt-line text-2xl text-emerald-600"></i>
</div>
</div>
</div>
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500 text-sm">爬虫数量</p>
<p id="statSpiders" class="text-3xl font-bold text-gray-800 mt-1">1</p>
</div>
<div class="w-12 h-12 bg-blue-100 rounded-xl flex items-center justify-center">
<i class="ri-spider-line text-2xl text-blue-600"></i>
</div>
</div>
</div>
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500 text-sm">任务总数</p>
<p id="statTasks" class="text-3xl font-bold text-gray-800 mt-1">-</p>
</div>
<div class="w-12 h-12 bg-purple-100 rounded-xl flex items-center justify-center">
<i class="ri-task-line text-2xl text-purple-600"></i>
</div>
</div>
</div>
<div class="bg-white rounded-xl p-6 shadow-sm border border-gray-100">
<div class="flex items-center justify-between">
<div>
<p class="text-gray-500 text-sm">最后更新</p>
<p id="statUpdate" class="text-lg font-bold text-gray-800 mt-1">-</p>
</div>
<div class="w-12 h-12 bg-orange-100 rounded-xl flex items-center justify-center">
<i class="ri-time-line text-2xl text-orange-600"></i>
</div>
</div>
</div>
</div>
<!-- 快速操作 -->
<div class="bg-white rounded-xl shadow-sm border border-gray-100 mb-8">
<div class="p-6 border-b">
<h2 class="font-semibold text-gray-800">快速操作</h2>
</div>
<div class="p-6">
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<a href="/admin/spiders" class="flex items-center gap-4 p-4 border border-gray-200 rounded-xl hover:border-emerald-300 hover:bg-emerald-50 transition">
<div class="w-10 h-10 bg-emerald-100 rounded-lg flex items-center justify-center">
<i class="ri-play-line text-xl text-emerald-600"></i>
</div>
<div>
<div class="font-medium text-gray-800">运行爬虫</div>
<div class="text-sm text-gray-500">执行数据爬取</div>
</div>
</a>
<a href="/admin/products" class="flex items-center gap-4 p-4 border border-gray-200 rounded-xl hover:border-blue-300 hover:bg-blue-50 transition">
<div class="w-10 h-10 bg-blue-100 rounded-lg flex items-center justify-center">
<i class="ri-eye-line text-xl text-blue-600"></i>
</div>
<div>
<div class="font-medium text-gray-800">查看数据</div>
<div class="text-sm text-gray-500">浏览爬取结果</div>
</div>
</a>
<a href="/admin/tasks" class="flex items-center gap-4 p-4 border border-gray-200 rounded-xl hover:border-purple-300 hover:bg-purple-50 transition">
<div class="w-10 h-10 bg-purple-100 rounded-lg flex items-center justify-center">
<i class="ri-history-line text-xl text-purple-600"></i>
</div>
<div>
<div class="font-medium text-gray-800">任务记录</div>
<div class="text-sm text-gray-500">查看执行历史</div>
</div>
</a>
</div>
</div>
</div>
<!-- 最近任务 -->
<div class="bg-white rounded-xl shadow-sm border border-gray-100">
<div class="p-6 border-b flex justify-between items-center">
<h2 class="font-semibold text-gray-800">最近任务</h2>
<a href="/admin/tasks" class="text-sm text-emerald-600 hover:text-emerald-700">查看全部</a>
</div>
<div id="recentTasks" class="p-6">
<p class="text-gray-400 text-center py-4">加载中...</p>
</div>
</div>
</main>
</div>
<script>
async function loadStats() {
const res = await fetch('/api/stats');
const stats = await res.json();
document.getElementById('statProducts').textContent = stats.total_products;
document.getElementById('statTasks').textContent = stats.total_tasks;
document.getElementById('statUpdate').textContent = stats.last_update ?
new Date(stats.last_update).toLocaleString() : '-';
}
async function loadRecentTasks() {
const res = await fetch('/api/tasks');
const tasks = await res.json();
const container = document.getElementById('recentTasks');
if (tasks.length === 0) {
container.innerHTML = '<p class="text-gray-400 text-center py-4">暂无任务记录</p>';
return;
}
container.innerHTML = tasks.slice(0, 5).map(task => `
<div class="flex items-center justify-between py-3 border-b last:border-0">
<div class="flex items-center gap-3">
<div class="w-8 h-8 rounded-full ${task.status === 'completed' ? 'bg-green-100' : task.status === 'failed' ? 'bg-red-100' : 'bg-yellow-100'} flex items-center justify-center">
<i class="ri-${task.status === 'completed' ? 'check text-green-600' : task.status === 'failed' ? 'close text-red-600' : 'loader text-yellow-600'}"></i>
</div>
<div>
<div class="font-medium text-gray-800">${task.spider}</div>
<div class="text-sm text-gray-500">${new Date(task.start_time).toLocaleString()}</div>
</div>
</div>
<span class="px-2 py-1 text-xs rounded ${task.status === 'completed' ? 'bg-green-100 text-green-700' : task.status === 'failed' ? 'bg-red-100 text-red-700' : 'bg-yellow-100 text-yellow-700'}">
${task.status === 'completed' ? '完成' : task.status === 'failed' ? '失败' : '运行中'}
</span>
</div>
`).join('');
}
loadStats();
loadRecentTasks();
</script>
</body>
</html>