Files
upload/templates/admin.html
T
zzy 84f8516c37 feat(upload): 分片断点续传 + 前端静态资源去 CDN 化
1) 分片上传(routes/chunked.py)
   - POST /api/upload/init  建会话,校验表单/字段/扩展名/体积
   - POST /api/upload/chunk 单片上传,幂等可重传,http body 直写磁盘
   - GET  /api/upload/status 查询已收分片
   - POST /api/upload/complete 按序合并 + sha256 校验 + 清理分片
   - /api/submit 新增 field fileTokens 挂载已上传文件(零拷贝 os.replace)
   - 过期会话(24h)由定时任务清理

2) 弱网下的样式可靠性
   - Tailwind Play CDN / GSAP 改为本地自托管(static/js/vendor/)
   - vendor 资源 1 年 immutable 缓存,自家 css/js 1 小时
   - CSS link 失败自动带 ?r= 重试一次
   - status 页加关键内联样式兜底,极端情况下仍可读

3) 大文件落盘沿用流式写入(无 400MB 内存峰值)
2026-11-13 12:06:32 +08:00

504 lines
21 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN" class="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>管理后台</title>
<!-- Tailwind CSS -->
<script src="/static/js/vendor/tailwind-play.js"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
neutral: {
50: '#fafafa',
100: '#f5f5f5',
200: '#e5e5e5',
300: '#d4d4d4',
400: '#a3a3a3',
500: '#737373',
600: '#525252',
700: '#404040',
800: '#262626',
900: '#171717',
}
}
}
}
}
</script>
<!-- GSAP for animations -->
<script src="/static/js/vendor/gsap.min.js"></script>
<script src="/static/js/particles.js"></script>
<link rel="stylesheet" href="/static/css/toast.css" onerror="this.onerror=null;this.href='/static/css/toast.css?r='+Date.now()">
<script src="/static/js/toast.js"></script>
<link rel="stylesheet" href="/static/css/basic.css" onerror="this.onerror=null;this.href='/static/css/basic.css?r='+Date.now()">
<link rel="stylesheet" href="/static/css/common.css" onerror="this.onerror=null;this.href='/static/css/common.css?r='+Date.now()">
<script src="/static/js/common.js"></script>
<style>
/* ── admin 页面专属样式 ── */
.form-card {
background: var(--glass-bg);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid var(--glass-border);
border-radius: 24px;
padding: 24px;
transition: all 0.4s cubic-bezier(0.2, 0, 0, 1);
opacity: 0;
transform: translateY(20px);
}
.form-card:hover {
transform: translateY(-4px);
box-shadow: 0 20px 40px -15px var(--shadow-color);
border-color: rgba(128, 128, 128, 0.3);
background: var(--glass-hover);
}
.btn-manage {
background-color: rgba(99, 102, 241, 0.1);
color: #6366f1;
border: 1px solid rgba(99, 102, 241, 0.2);
}
.btn-manage:hover {
background-color: rgba(99, 102, 241, 0.2);
transform: translateY(-2px);
}
.quick-action {
background: var(--glass-bg);
border: 1px solid var(--glass-border);
border-radius: 16px;
padding: 20px;
transition: all 0.3s ease;
cursor: pointer;
}
.quick-action:hover {
background: var(--glass-hover);
transform: translateY(-2px);
box-shadow: 0 10px 20px -10px var(--shadow-color);
}
</style>
</head>
<body class="antialiased min-h-screen relative">
<!-- Progress Bar -->
<div class="fixed top-0 left-0 w-full h-[2px] z-50 theme-transition" style="background-color: var(--border-color);">
<div id="scrollProgress" class="h-full w-0 transition-all duration-100 ease-out"></div>
</div>
<!-- Header -->
<header class="fixed top-0 w-full z-40 px-4 sm:px-6 py-4 sm:py-5 glass theme-transition border-b">
<div class="max-w-6xl mx-auto flex justify-between items-center">
<!-- 左侧:Logo / 页面标识 -->
<div class="flex items-center gap-3">
<div class="flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
style="color:var(--text-primary)">
<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/>
<rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/>
</svg>
<h1 class="font-serif text-lg sm:text-xl font-semibold tracking-tight theme-transition"
style="color: var(--text-primary);">Admin</h1>
</div>
<span class="hidden sm:inline text-[10px] tracking-[0.2em] uppercase font-medium theme-transition"
style="color: var(--text-muted);">管理后台</span>
</div>
<!-- 右侧:退出登录 -->
<div class="flex items-center gap-2 sm:gap-3">
<button onclick="logout()" class="btn btn-secondary px-4 py-2.5 rounded-full text-xs sm:text-sm font-medium tracking-wide flex items-center gap-2">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>
<polyline points="16 17 21 12 16 7"/>
<line x1="21" y1="12" x2="9" y2="12"/>
</svg>
<span class="hidden sm:inline">退出登录</span>
</button>
</div>
</div>
</header>
<!-- Main Content -->
<main class="relative pt-32 pb-24 px-6">
<div class="max-w-6xl mx-auto">
<!-- Header Section -->
<div class="mb-12 opacity-0" id="headerSection">
<h2 class="font-serif text-4xl sm:text-5xl leading-[1.1] font-medium tracking-tight mb-4 theme-transition"
style="color: var(--text-primary);">
管理后台
</h2>
<p class="text-sm leading-relaxed max-w-md tracking-wide font-light theme-transition"
style="color: var(--text-secondary);">
创建和管理表单,查看提交状态,管理用户权限。
</p>
</div>
<!-- Quick Actions -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-12">
<a href="/create" class="quick-action stagger-item group">
<div class="w-12 h-12 rounded-xl flex items-center justify-center mb-4 theme-transition"
style="background: var(--bg-primary);">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
class="theme-transition group-hover:scale-110 transition-transform" style="color: var(--text-primary);">
<line x1="12" y1="5" x2="12" y2="19"></line>
<line x1="5" y1="12" x2="19" y2="12"></line>
</svg>
</div>
<h3 class="font-medium text-base mb-1 theme-transition" style="color: var(--text-primary);">新建表单</h3>
<p class="text-xs theme-transition" style="color: var(--text-muted);">创建数据收集表单</p>
</a>
<a href="/preset_manage" class="quick-action stagger-item group">
<div class="w-12 h-12 rounded-xl flex items-center justify-center mb-4 theme-transition"
style="background: var(--info-bg);">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
class="theme-transition group-hover:scale-110 transition-transform" style="color: var(--info-text);">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
</div>
<h3 class="font-medium text-base mb-1 theme-transition" style="color: var(--text-primary);">名单预设</h3>
<p class="text-xs theme-transition" style="color: var(--text-muted);">管理学生名单预设</p>
</a>
<a href="/user_manage" class="quick-action stagger-item group" id="userManageLink" style="display: none;">
<div class="w-12 h-12 rounded-xl flex items-center justify-center mb-4 theme-transition"
style="background: var(--success-bg);">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
class="theme-transition group-hover:scale-110 transition-transform" style="color: var(--success-text);">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
<circle cx="9" cy="7" r="4"></circle>
<path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
<path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
</svg>
</div>
<h3 class="font-medium text-base mb-1 theme-transition" style="color: var(--text-primary);">用户管理</h3>
<p class="text-xs theme-transition" style="color: var(--text-muted);">管理用户权限</p>
</a>
<a href="/db_manage" class="quick-action stagger-item group" id="dbManageLink" style="display: none;">
<div class="w-12 h-12 rounded-xl flex items-center justify-center mb-4 theme-transition"
style="background: var(--warning-bg);">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
class="theme-transition group-hover:scale-110 transition-transform" style="color: var(--warning-text);">
<ellipse cx="12" cy="5" rx="9" ry="3"></ellipse>
<path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"></path>
<path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"></path>
</svg>
</div>
<h3 class="font-medium text-base mb-1 theme-transition" style="color: var(--text-primary);">数据库管理</h3>
<p class="text-xs theme-transition" style="color: var(--text-muted);">查看状态/执行SQL/优化</p>
</a>
<a href="/monitor" class="quick-action stagger-item group" id="monitorLink" style="display: none;">
<div class="w-12 h-12 rounded-xl flex items-center justify-center mb-4 theme-transition"
style="background: var(--info-bg);">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
class="theme-transition group-hover:scale-110 transition-transform" style="color: var(--info-text);">
<path d="M3 3v18h18"/>
<path d="m19 9-5 5-4-4-3 3"/>
</svg>
</div>
<h3 class="font-medium text-base mb-1 theme-transition" style="color: var(--text-primary);">系统监控</h3>
<p class="text-xs theme-transition" style="color: var(--text-muted);">性能指标/趋势图表</p>
</a>
<a href="http://47.112.187.172:4567/share/1n5ih0p3s0/p/-9DQeaLVvLs" class="quick-action stagger-item group">
<div class="w-12 h-12 rounded-xl flex items-center justify-center mb-4 theme-transition"
style="background: var(--warning-bg);">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
class="theme-transition group-hover:scale-110 transition-transform" style="color: var(--warning-text);">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg>
</div>
<h3 class="font-medium text-base mb-1 theme-transition" style="color: var(--text-primary);">帮助文档</h3>
<p class="text-xs theme-transition" style="color: var(--text-muted);">查看使用指南</p>
</a>
</div>
<!-- Loading State -->
<div id="loadingState" class="flex justify-center items-center h-32">
<div class="loading-spinner"></div>
</div>
<!-- Forms List -->
<div id="formsContainer" class="hidden">
<div class="flex justify-between items-center mb-6">
<h3 class="font-serif text-2xl font-medium theme-transition" style="color: var(--text-primary);">表单列表</h3>
<span class="text-sm theme-transition" style="color: var(--text-muted);" id="formCount">0 个表单</span>
</div>
<div id="formsList" class="grid grid-cols-1 lg:grid-cols-2 gap-4">
<!-- Forms will be inserted here -->
</div>
</div>
<!-- Empty State -->
<div id="emptyState" class="hidden text-center py-16">
<div class="w-16 h-16 mx-auto mb-6 rounded-full flex items-center justify-center theme-transition"
style="background: var(--bg-primary);">
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"
style="color: var(--text-muted);">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
<line x1="16" y1="13" x2="8" y2="13"></line>
<line x1="16" y1="17" x2="8" y2="17"></line>
<polyline points="10 9 9 9 8 9"></polyline>
</svg>
</div>
<h3 class="font-serif text-2xl font-medium mb-2 theme-transition" style="color: var(--text-primary);">暂无表单</h3>
<p class="text-sm mb-6 theme-transition" style="color: var(--text-muted);">点击上方"新建表单"创建第一个表单</p>
<a href="/create"
class="btn btn-primary inline-flex items-center gap-2 px-6 py-3 rounded-xl text-sm font-medium">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="12" y1="5" x2="12" y2="19"></line>
<line x1="5" y1="12" x2="19" y2="12"></line>
</svg>
新建表单
</a>
</div>
</div>
</main>
<!-- Footer -->
<footer class="fixed bottom-6 w-full text-center pointer-events-none">
<p class="text-[10px] tracking-[0.3em] uppercase font-medium theme-transition" style="color: var(--text-muted);">
Secure Admin Panel</p>
</footer>
<script>
// Page init
let currentUser = null;
// Check auth and load data
async function init() {
try {
const response = await fetch('/api/current_user');
const data = await response.json();
if (!data.logged_in) {
window.location.href = '/login?redirect=/admin';
return;
}
currentUser = data;
// Show user management and database management links for admin
if (data.role === 'admin') {
document.getElementById('userManageLink').style.display = 'block';
document.getElementById('dbManageLink').style.display = 'block';
document.getElementById('monitorLink').style.display = 'block';
}
loadForms();
} catch (error) {
showToast('认证失败', 'error');
setTimeout(() => {
window.location.href = '/login?redirect=/admin';
}, 1500);
}
}
async function loadForms() {
try {
const response = await fetch('/api/admin/forms');
const forms = await response.json();
document.getElementById('loadingState').style.display = 'none';
if (forms.length === 0) {
document.getElementById('emptyState').classList.remove('hidden');
return;
}
document.getElementById('formsContainer').classList.remove('hidden');
document.getElementById('formCount').textContent = `${forms.length} 个表单`;
renderForms(forms);
} catch (error) {
showToast('加载表单失败', 'error');
}
}
function renderForms(forms) {
const container = document.getElementById('formsList');
container.innerHTML = forms.map((form, index) => {
const expiryInfo = form.expiryInfo || {};
const remainingDays = expiryInfo.remaining_days || 0;
const remainingHours = expiryInfo.remaining_hours || 0;
const isExpired = expiryInfo.is_expired || false;
let expiryText = '';
if (expiryInfo.never_expires) {
expiryText = '<span class="text-xs px-2 py-1 rounded-full theme-transition" style="background: var(--success-bg); color: var(--success-text);">永不过期</span>';
} else if (isExpired) {
expiryText = '<span class="text-xs px-2 py-1 rounded-full" style="background: var(--error-bg); color: var(--error-text);">已过期</span>';
} else if (remainingDays > 0) {
expiryText = `<span class="text-xs px-2 py-1 rounded-full theme-transition" style="background: var(--warning-bg); color: var(--warning-text);">${remainingDays}天${remainingHours}小时后过期</span>`;
} else {
expiryText = `<span class="text-xs px-2 py-1 rounded-full" style="background: var(--error-bg); color: var(--error-text);">${remainingHours}小时后过期</span>`;
}
return `
<div class="form-card" style="animation-delay: ${index * 0.05}s">
<div class="flex justify-between items-start mb-4">
<div>
<h4 class="font-medium text-lg mb-1 theme-transition" style="color: var(--text-primary);">${form.title}</h4>
<p class="text-xs theme-transition" style="color: var(--text-muted);">
${form.presetName ? `使用预设: ${form.presetName}` : '使用默认名单'}
</p>
</div>
<div class="flex gap-2 items-center">
<button type="button"
onclick="toggleCollect('${form.id}')"
data-toggle-collect="${form.id}"
data-collecting="${form.collecting !== false ? '1' : '0'}"
title="点击切换收集状态"
class="text-xs px-2.5 py-1 rounded-full inline-flex items-center gap-1.5 font-medium theme-transition"
style="border:1px solid ${form.collecting !== false ? 'var(--success-text)' : 'var(--error-text)'}; color:${form.collecting !== false ? 'var(--success-text)' : 'var(--error-text)'}; background:${form.collecting !== false ? 'var(--success-bg)' : 'var(--error-bg)'}; cursor:pointer;">
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:${form.collecting !== false ? 'var(--success-text)' : 'var(--error-text)'};"></span>
${form.collecting !== false ? '收集中' : '已停止'}
</button>
${expiryText}
</div>
</div>
<div class="grid grid-cols-3 gap-4 mb-4 py-4 border-y theme-transition" style="border-color: var(--border-color);">
<div class="text-center">
<div class="text-2xl font-semibold theme-transition" style="color: var(--text-primary);">${form.submittedCount}</div>
<div class="text-xs theme-transition" style="color: var(--text-muted);">已提交</div>
</div>
<div class="text-center">
<div class="text-2xl font-semibold theme-transition" style="color: var(--text-primary);">${form.totalStudents}</div>
<div class="text-xs theme-transition" style="color: var(--text-muted);">总人数</div>
</div>
<div class="text-center">
<div class="text-2xl font-semibold theme-transition" style="color: var(--text-primary);">${form.fileCount}</div>
<div class="text-xs theme-transition" style="color: var(--text-muted);">文件数</div>
</div>
</div>
<div class="flex gap-2">
<a href="/status?formId=${form.id}" class="btn btn-manage flex-1 py-2.5 rounded-xl text-xs font-medium text-center">
查看状态
</a>
<a href="/edit/${form.id}" class="btn btn-secondary px-4 py-2.5 rounded-xl text-xs font-medium">
编辑
</a>
<button onclick="deleteForm('${form.id}')" class="btn btn-danger px-4 py-2.5 rounded-xl text-xs font-medium">
删除
</button>
</div>
</div>
`;
}).join('');
// Animate cards
gsap.to(".form-card", {
opacity: 1,
y: 0,
duration: 0.5,
stagger: 0.05,
ease: "power2.out"
});
}
async function deleteForm(formId) {
if (!confirm('确定要删除此表单吗?此操作不可恢复。')) {
return;
}
try {
const response = await fetch(`/api/admin/delete_form/${formId}`, {
method: 'POST'
});
const data = await response.json();
if (data.success) {
showToast('表单已删除', 'success');
loadForms();
} else {
showToast(data.message || '删除失败', 'error');
}
} catch (error) {
showToast('删除失败', 'error');
}
}
async function toggleCollect(formId) {
const btn = document.querySelector(`[data-toggle-collect="${formId}"]`);
const current = btn ? btn.dataset.collecting === '1' : true;
const next = !current;
try {
const response = await fetch(`/api/admin/toggle_collect/${formId}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ collecting: next })
});
const data = await response.json();
if (data.success) {
showToast(data.message || (next ? '已恢复收集' : '已停止收集'), 'success');
loadForms();
} else {
showToast(data.message || '切换失败', 'error');
}
} catch (error) {
showToast('切换失败', 'error');
}
}
// Initial Animation
window.addEventListener('load', () => {
gsap.to("#headerSection", {
opacity: 1,
y: 0,
duration: 0.8,
ease: "power2.out",
delay: 0.1
});
gsap.to(".stagger-item", {
opacity: 1,
y: 0,
duration: 0.6,
stagger: 0.1,
ease: "power2.out",
delay: 0.3
});
init();
});
</script>
</body>
</html>