2972 lines
104 KiB
HTML
2972 lines
104 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN" class="light">
|
||
|
||
<head>
|
||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
||
<meta http-equiv="Pragma" content="no-cache">
|
||
<meta http-equiv="Expires" content="0">
|
||
<meta name="version" content="20260307142512">
|
||
<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="https://cdn.tailwindcss.com"></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>
|
||
|
||
<!-- ECharts for data visualization -->
|
||
<script src="/static/js/echart.js"></script>
|
||
<!-- GSAP for animations -->
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
||
<script src="/static/js/particles.js"></script>
|
||
<script src="/static/js/toast.js"></script>
|
||
<link rel="stylesheet" href="/static/css/basic.css">
|
||
<link rel="stylesheet" href="/static/css/common.css">
|
||
<script src="/static/js/common.js"></script>
|
||
|
||
<style>
|
||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:ital,wght@0,400;0,600;1,400&display=swap');
|
||
|
||
@import url('/static/css/toast.css');
|
||
|
||
|
||
|
||
body {
|
||
font-family: 'Inter', sans-serif;
|
||
background-color: var(--bg-primary);
|
||
background-image:
|
||
radial-gradient(at 0% 0%, rgba(128, 128, 128, 0.03) 0px, transparent 50%),
|
||
radial-gradient(at 100% 100%, rgba(128, 128, 128, 0.03) 0px, transparent 50%);
|
||
color: var(--text-primary);
|
||
margin: 0;
|
||
min-height: 100vh;
|
||
overflow-x: hidden;
|
||
transition: background-color 0.5s ease, color 0.5s ease;
|
||
}
|
||
|
||
.dark body {
|
||
background-image:
|
||
radial-gradient(at 0% 0%, rgba(255, 255, 255, 0.02) 0px, transparent 50%),
|
||
radial-gradient(at 100% 100%, rgba(255, 255, 255, 0.02) 0px, transparent 50%);
|
||
}
|
||
|
||
.font-serif {
|
||
font-family: 'Playfair Display', serif;
|
||
}
|
||
|
||
html {
|
||
scroll-behavior: smooth;
|
||
}
|
||
|
||
::selection {
|
||
background: rgba(128, 128, 128, 0.2);
|
||
color: var(--text-primary);
|
||
}
|
||
|
||
/* Scrollbar */
|
||
body::-webkit-scrollbar {
|
||
width: 6px;
|
||
}
|
||
|
||
body::-webkit-scrollbar-track {
|
||
background: transparent;
|
||
}
|
||
|
||
body::-webkit-scrollbar-thumb {
|
||
background: var(--border-color);
|
||
border-radius: 3px;
|
||
}
|
||
|
||
body::-webkit-scrollbar-thumb:hover {
|
||
background: var(--text-muted);
|
||
}
|
||
|
||
.glass {
|
||
background: var(--glass-bg);
|
||
backdrop-filter: blur(20px);
|
||
-webkit-backdrop-filter: blur(20px);
|
||
border: 1px solid var(--glass-border);
|
||
transition: all 0.3s ease;
|
||
}
|
||
|
||
.theme-transition {
|
||
transition: background-color 0.5s ease, color 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
|
||
}
|
||
|
||
/* Card Styles */
|
||
.stat-card {
|
||
background: var(--glass-bg);
|
||
backdrop-filter: blur(20px);
|
||
-webkit-backdrop-filter: blur(20px);
|
||
border: 1px solid var(--glass-border);
|
||
border-radius: 20px;
|
||
padding: 24px;
|
||
transition: all 0.4s cubic-bezier(0.2, 0, 0, 1);
|
||
}
|
||
|
||
.stat-card:hover {
|
||
transform: translateY(-4px);
|
||
box-shadow: 0 20px 40px -15px var(--shadow-color);
|
||
|
||
background: var(--glass-hover);
|
||
}
|
||
|
||
/* Progress Bar */
|
||
#scrollProgress {
|
||
background: linear-gradient(90deg, var(--text-muted), var(--text-primary));
|
||
}
|
||
|
||
/* Buttons */
|
||
.btn {
|
||
position: relative;
|
||
overflow: hidden;
|
||
transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
|
||
}
|
||
|
||
.btn::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0;
|
||
left: -100%;
|
||
width: 100%;
|
||
height: 100%;
|
||
background: linear-gradient(90deg, transparent, rgba(128, 128, 128, 0.1), transparent);
|
||
transition: left 0.5s;
|
||
}
|
||
|
||
.btn:hover::before {
|
||
left: 100%;
|
||
}
|
||
|
||
.btn-primary {
|
||
background-color: var(--accent-bg);
|
||
color: var(--accent-text);
|
||
}
|
||
|
||
.btn-primary:hover {
|
||
transform: translateY(-2px);
|
||
box-shadow: 0 10px 20px -5px var(--shadow-color);
|
||
}
|
||
|
||
.btn-secondary {
|
||
background-color: var(--bg-primary);
|
||
color: var(--text-secondary);
|
||
border: 1px solid var(--border-color);
|
||
}
|
||
|
||
.btn-secondary:hover {
|
||
background-color: var(--bg-secondary);
|
||
transform: translateY(-2px);
|
||
}
|
||
|
||
/* Student List */
|
||
.student-item {
|
||
transition: all 0.3s ease;
|
||
}
|
||
|
||
.student-item:hover {
|
||
background: var(--bg-primary);
|
||
}
|
||
|
||
/* Chart Container */
|
||
.chart-container {
|
||
background: var(--glass-bg);
|
||
border: 1px solid var(--glass-border);
|
||
border-radius: 20px;
|
||
padding: 20px;
|
||
height: 300px;
|
||
}
|
||
|
||
/* Accordion */
|
||
.accordion-content {
|
||
max-height: 0;
|
||
overflow: hidden;
|
||
transition: max-height 0.4s ease;
|
||
}
|
||
|
||
.accordion-content.open {
|
||
max-height: 1000px;
|
||
}
|
||
|
||
.accordion-arrow {
|
||
transition: transform 0.3s ease;
|
||
}
|
||
|
||
.accordion-arrow.open {
|
||
transform: rotate(180deg);
|
||
}
|
||
|
||
/* Loading */
|
||
.loading-spinner {
|
||
width: 40px;
|
||
height: 40px;
|
||
border: 3px solid var(--border-color);
|
||
border-top-color: var(--text-primary);
|
||
border-radius: 50%;
|
||
animation: spin 0.8s linear infinite;
|
||
}
|
||
|
||
@keyframes spin {
|
||
to {
|
||
transform: rotate(360deg);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/* Mobile Touch Optimizations */
|
||
@media (max-width: 768px) {
|
||
/* 移动端控件间距 */
|
||
.chart-container {
|
||
margin-bottom: 24px;
|
||
}
|
||
|
||
.chart-container:last-child {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
/* 进度条移动端间距 */
|
||
.glass.my-6 {
|
||
margin-top: 24px !important;
|
||
margin-bottom: 24px !important;
|
||
}
|
||
|
||
/* 按钮组移动端间距 */
|
||
.flex.flex-wrap.gap-4.my-6 {
|
||
margin-top: 24px !important;
|
||
margin-bottom: 24px !important;
|
||
gap: 12px !important;
|
||
}
|
||
|
||
/* 提交详情表移动端间距 */
|
||
.glass.mt-8 {
|
||
margin-top: 32px !important;
|
||
}
|
||
|
||
.field-tag {
|
||
padding: 10px 16px;
|
||
font-size: 15px;
|
||
min-height: 44px;
|
||
border-radius: 10px;
|
||
}
|
||
|
||
.field-tag .remove-btn {
|
||
width: 22px;
|
||
height: 22px;
|
||
font-size: 14px;
|
||
margin-left: 8px;
|
||
}
|
||
|
||
/* Mobile sort controls */
|
||
.mobile-sort-controls {
|
||
display: flex !important;
|
||
flex-direction: column;
|
||
gap: 2px;
|
||
margin-left: 8px;
|
||
margin-right: 4px;
|
||
}
|
||
|
||
.sort-btn {
|
||
width: 32px;
|
||
height: 32px;
|
||
border-radius: 6px;
|
||
border: 1px solid var(--border-color);
|
||
background: var(--bg-secondary);
|
||
color: var(--text-secondary);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
cursor: pointer;
|
||
transition: all 0.15s;
|
||
touch-action: manipulation;
|
||
-webkit-tap-highlight-color: transparent;
|
||
}
|
||
|
||
.sort-btn:active:not(:disabled) {
|
||
background: var(--accent-bg);
|
||
color: var(--accent-text);
|
||
transform: scale(0.92);
|
||
}
|
||
|
||
.sort-btn:disabled {
|
||
opacity: 0.3;
|
||
cursor: not-allowed;
|
||
}
|
||
|
||
/* Mobile separator input */
|
||
.sep-input {
|
||
width: 60px;
|
||
height: 44px;
|
||
font-size: 17px;
|
||
border: 2px solid var(--border-color);
|
||
border-radius: 8px;
|
||
background: var(--bg-secondary);
|
||
margin: 0 6px;
|
||
}
|
||
|
||
.sep-input:focus {
|
||
border-color: var(--accent-bg);
|
||
border-width: 2px;
|
||
outline: none;
|
||
}
|
||
|
||
/* Selected fields container */
|
||
#selectedFields {
|
||
gap: 8px;
|
||
padding: 16px;
|
||
min-height: 80px;
|
||
}
|
||
|
||
/* Available fields grid */
|
||
#availableFields {
|
||
grid-template-columns: 1fr !important;
|
||
gap: 8px;
|
||
}
|
||
|
||
#availableFields .field-tag {
|
||
width: 100%;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
/* Modal adjustments for mobile */
|
||
#filenameModal .glass {
|
||
border-radius: 20px 20px 0 0;
|
||
margin: 0;
|
||
max-height: 90vh;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
#filenameModal.show .glass {
|
||
transform: translateY(0) !important;
|
||
}
|
||
|
||
#filenameModal .glass {
|
||
transform: translateY(100%);
|
||
transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
/* Touch device optimizations (regardless of screen size) */
|
||
@media (pointer: coarse) {
|
||
.btn, .field-tag, .sort-btn {
|
||
min-height: 44px;
|
||
}
|
||
|
||
.btn:active, .field-tag.available:active {
|
||
transform: scale(0.98);
|
||
}
|
||
}
|
||
|
||
/* Hide mobile controls on desktop by default */
|
||
.mobile-sort-controls {
|
||
display: none;
|
||
}
|
||
/* 时间粒度选择器样式 */
|
||
.granularity-btn {
|
||
background: var(--bg-secondary);
|
||
color: var(--text-secondary);
|
||
border: 1px solid var(--border-color);
|
||
}
|
||
|
||
.granularity-btn:hover {
|
||
background: var(--bg-primary);
|
||
border-color: var(--text-muted);
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.granularity-btn.active {
|
||
background: var(--accent-bg);
|
||
color: var(--accent-text);
|
||
border-color: var(--accent-bg);
|
||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||
}
|
||
|
||
/* 图表区域标记样式 */
|
||
.date-marker-legend {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.date-marker-dot {
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 50%;
|
||
background: #facc15;
|
||
}
|
||
/* 时间范围选择器样式 */
|
||
.time-range-input {
|
||
background: var(--bg-secondary);
|
||
border: 1px solid var(--border-color);
|
||
border-radius: 6px;
|
||
padding: 4px 8px;
|
||
font-size: 12px;
|
||
color: var(--text-primary);
|
||
outline: none;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
.time-range-input:focus {
|
||
border-color: var(--accent-bg);
|
||
box-shadow: 0 0 0 2px rgba(128, 128, 128, 0.1);
|
||
}
|
||
|
||
.time-range-input::-webkit-calendar-picker-indicator {
|
||
filter: var(--calendar-icon-filter, invert(0.5));
|
||
cursor: pointer;
|
||
}
|
||
|
||
.dark .time-range-input::-webkit-calendar-picker-indicator {
|
||
filter: invert(0.7);
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
|
||
<script>
|
||
// 强制清除缓存检查(版本: 99965)
|
||
if (!window.__cacheCleared_99965) {
|
||
window.__cacheCleared_99965 = true;
|
||
console.log('Status Page Version: 99965');
|
||
}
|
||
</script>
|
||
|
||
<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">
|
||
<!-- 左侧:面包屑 -->
|
||
<div class="flex items-center gap-2">
|
||
<a href="/admin" class="nav-link flex items-center gap-1.5">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
|
||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||
<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>
|
||
<span class="hidden sm:inline text-sm">管理后台</span>
|
||
</a>
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none"
|
||
stroke="currentColor" stroke-width="2" style="color:var(--text-muted);opacity:0.4">
|
||
<path d="m9 18 6-6-6-6"/>
|
||
</svg>
|
||
<span class="text-sm font-medium" style="color:var(--text-primary)">表单状态</span>
|
||
</div>
|
||
<!-- 右侧 -->
|
||
<div class="flex items-center gap-2 sm:gap-3">
|
||
<button onclick="copyFormLink()"
|
||
class="btn btn-primary px-4 py-2.5 rounded-full text-xs sm:text-sm font-medium tracking-wide flex items-center gap-2"
|
||
title="复制表单填写链接">
|
||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
||
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
||
</svg>
|
||
<span class="hidden sm:inline">复制链接</span>
|
||
</button>
|
||
<a href="/admin" 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="M19 12H5M12 19l-7-7 7-7"/>
|
||
</svg>
|
||
<span class="hidden sm:inline">返回</span>
|
||
</a>
|
||
</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);">
|
||
<span id="formTitle">加载中...</span>
|
||
</h2>
|
||
<p class="text-sm leading-relaxed max-w-md tracking-wide font-light theme-transition"
|
||
style="color: var(--text-secondary);">
|
||
实时查看表单提交状态,下载文件,导出数据。
|
||
</p>
|
||
</div>
|
||
|
||
<!-- Loading State -->
|
||
<div id="loadingState" class="flex justify-center items-center h-64">
|
||
<div class="loading-spinner"></div>
|
||
</div>
|
||
|
||
<!-- Content (hidden initially) -->
|
||
<div id="contentArea" class="hidden space-y-8">
|
||
|
||
<!-- Stats Cards -->
|
||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
|
||
<div class="stat-card stagger-item">
|
||
<div class="text-[10px] tracking-[0.2em] uppercase mb-2 theme-transition" style="color: var(--text-muted);">
|
||
总人数</div>
|
||
<div class="text-3xl font-semibold theme-transition" style="color: var(--text-primary);" id="totalCount">0
|
||
</div>
|
||
</div>
|
||
<div class="stat-card stagger-item">
|
||
<div class="text-[10px] tracking-[0.2em] uppercase mb-2 theme-transition" style="color: var(--text-muted);">
|
||
已提交</div>
|
||
<div class="text-3xl font-semibold theme-transition" style="color: var(--success-text);"
|
||
id="submittedCount">0</div>
|
||
</div>
|
||
<div class="stat-card stagger-item">
|
||
<div class="text-[10px] tracking-[0.2em] uppercase mb-2 theme-transition" style="color: var(--text-muted);">
|
||
未提交</div>
|
||
<div class="text-3xl font-semibold theme-transition" style="color: var(--warning-text);" id="pendingCount">0
|
||
</div>
|
||
</div>
|
||
<div class="stat-card stagger-item">
|
||
<div class="text-[10px] tracking-[0.2em] uppercase mb-2 theme-transition" style="color: var(--text-muted);">
|
||
完成率</div>
|
||
<div class="text-3xl font-semibold theme-transition" style="color: var(--info-text);" id="completionRate">0%
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Charts Row -->
|
||
<!-- Time Granularity Selector -->
|
||
<div class="glass rounded-2xl p-4 stagger-item flex flex-wrap items-center gap-4 mb-6">
|
||
<span class="text-sm font-medium theme-transition" style="color: var(--text-secondary);">时间粒度:</span>
|
||
<div class="flex flex-wrap gap-2" id="timeGranularity">
|
||
<button onclick="setGranularity('minute')" class="granularity-btn px-3 py-1.5 rounded-lg text-xs font-medium transition-all" data-granularity="minute">分钟</button>
|
||
<button onclick="setGranularity('hour')" class="granularity-btn px-3 py-1.5 rounded-lg text-xs font-medium transition-all" data-granularity="hour">小时</button>
|
||
<button onclick="setGranularity('day')" class="granularity-btn px-3 py-1.5 rounded-lg text-xs font-medium transition-all active" data-granularity="day">天</button>
|
||
<button onclick="setGranularity('week')" class="granularity-btn px-3 py-1.5 rounded-lg text-xs font-medium transition-all" data-granularity="week">周</button>
|
||
<button onclick="setGranularity('month')" class="granularity-btn px-3 py-1.5 rounded-lg text-xs font-medium transition-all" data-granularity="month">月</button>
|
||
<button onclick="setGranularity('quarter')" class="granularity-btn px-3 py-1.5 rounded-lg text-xs font-medium transition-all" data-granularity="quarter">季度</button>
|
||
<button onclick="setGranularity('year')" class="granularity-btn px-3 py-1.5 rounded-lg text-xs font-medium transition-all" data-granularity="year">年</button>
|
||
</div>
|
||
|
||
<!-- 时间范围选择器(非总时长模式显示) -->
|
||
<div id="timeRangeSelector" class="flex flex-wrap items-center gap-2 ml-0 sm:ml-4 pl-0 sm:pl-4 border-l-0 sm:border-l mt-2 sm:mt-0" style="border-color: var(--border-color);">
|
||
<div class="flex items-center gap-2 flex-wrap">
|
||
<span class="text-xs" style="color: var(--text-muted);">从</span>
|
||
<input type="datetime-local" id="startTime" class="time-range-input" onchange="updateTimeRange()">
|
||
<span class="text-xs" style="color: var(--text-muted);">至</span>
|
||
<input type="datetime-local" id="endTime" class="time-range-input" onchange="updateTimeRange()">
|
||
</div>
|
||
<button onclick="resetTimeRange()" class="text-xs px-3 py-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors border" style="color: var(--text-muted); border-color: var(--border-color);">重置</button>
|
||
</div>
|
||
<div class="ml-auto flex items-center gap-2 text-xs" style="color: var(--text-muted);">
|
||
<span class="w-3 h-3 rounded-full" style="background: linear-gradient(135deg, #22c55e, #16a34a);"></span>
|
||
<span id="dateRangeDisplay">加载中...</span>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Charts Row -->
|
||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||
<div class="chart-container stagger-item">
|
||
<div class="flex justify-between items-center mb-4">
|
||
<h3 class="text-sm font-semibold theme-transition" style="color: var(--text-primary);">提交趋势</h3>
|
||
<div id="trendLegend" class="flex items-center gap-3 text-xs" style="color: var(--text-muted);">
|
||
<span class="flex items-center gap-1">
|
||
<span class="w-2 h-2 rounded-sm" style="background:#22c55e;"></span>首次提交
|
||
</span>
|
||
<span class="flex items-center gap-1">
|
||
<span class="w-2 h-2 rounded-sm" style="background:#f97316;"></span>覆盖提交
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<div id="trendChart" style="height: 240px;"></div>
|
||
</div>
|
||
<div class="chart-container stagger-item">
|
||
<h3 class="text-sm font-semibold mb-4 theme-transition" style="color: var(--text-primary);">提交时段分布</h3>
|
||
<div id="timeDistributionChart" style="height: 240px;"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Progress Bar -->
|
||
<div class="glass rounded-2xl p-6 stagger-item my-6">
|
||
<div class="flex justify-between items-center mb-4">
|
||
<span class="text-sm font-medium theme-transition" style="color: var(--text-primary);">总体进度</span>
|
||
<span class="text-sm font-semibold theme-transition" style="color: var(--info-text);"
|
||
id="progressPercent">0%</span>
|
||
</div>
|
||
<div class="h-3 rounded-full overflow-hidden theme-transition" style="background: var(--border-color);">
|
||
<div id="progressBar" class="h-full rounded-full transition-all duration-1000"
|
||
style="background: linear-gradient(90deg, var(--success-text), #4ade80); width: 0%;"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Action Buttons -->
|
||
<div class="flex flex-wrap gap-4 stagger-item my-6">
|
||
<button onclick="createZip()"
|
||
class="btn btn-primary px-6 py-3 rounded-xl text-sm font-medium flex items-center gap-2">
|
||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
||
<polyline points="7 10 12 15 17 10"></polyline>
|
||
<line x1="12" y1="15" x2="12" y2="3"></line>
|
||
</svg>
|
||
导出附件
|
||
</button>
|
||
<button onclick="exportData('xlsx')"
|
||
class="btn btn-secondary px-6 py-3 rounded-xl text-sm font-medium flex items-center gap-2">
|
||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||
<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>
|
||
导出表格 (Excel)
|
||
</button>
|
||
<button onclick="previewTable()"
|
||
class="btn btn-secondary px-6 py-3 rounded-xl text-sm font-medium flex items-center gap-2">
|
||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
|
||
<circle cx="12" cy="12" r="3"></circle>
|
||
</svg>
|
||
预览表格
|
||
</button>
|
||
</div>
|
||
|
||
<!-- Student List -->
|
||
<div class="glass rounded-2xl overflow-hidden stagger-item mt-8">
|
||
<div class="p-6 border-b theme-transition" style="border-color: var(--glass-border);">
|
||
<h3 class="text-lg font-semibold theme-transition" style="color: var(--text-primary);">提交详情</h3>
|
||
</div>
|
||
<div class="overflow-x-auto">
|
||
<table class="w-full">
|
||
<thead>
|
||
<tr class="text-left text-xs tracking-[0.1em] uppercase theme-transition"
|
||
style="color: var(--text-muted); background: var(--bg-primary);">
|
||
<th class="p-4 font-medium">学号</th>
|
||
<th class="p-4 font-medium">姓名</th>
|
||
<th class="p-4 font-medium">状态</th>
|
||
<th class="p-4 font-medium">文件</th>
|
||
<th class="p-4 font-medium">操作</th>
|
||
<th class="p-4 font-medium">提交记录</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="studentList" class="text-sm">
|
||
<!-- Students will be inserted here -->
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</main>
|
||
|
||
|
||
<script>
|
||
// Global variables
|
||
let formId = '';
|
||
let statusData = null;
|
||
let trendChart = null;
|
||
let timeDistributionChart = null;
|
||
let isTouchDevice = false;
|
||
let currentGranularity = 'day'; // 默认按天显示
|
||
let submissionTimesCache = []; // 缓存首次提交时间数据
|
||
let overwriteTimesCache = []; // 缓存覆盖提交时间数据
|
||
let timeRangeStart = null; // 时间范围开始
|
||
let timeRangeEnd = null; // 时间范围结束
|
||
|
||
// 主题切换时重绘图表(common.js 已负责初始化主题)
|
||
new MutationObserver(function() {
|
||
if (statusData) {
|
||
if (trendChart) trendChart.dispose();
|
||
if (timeDistributionChart) timeDistributionChart.dispose();
|
||
initCharts().catch(console.error);
|
||
}
|
||
}).observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
||
|
||
// Load data
|
||
async function loadData() {
|
||
console.log('loadData started');
|
||
const urlParams = new URLSearchParams(window.location.search);
|
||
formId = urlParams.get('formId');
|
||
|
||
if (!formId) {
|
||
document.getElementById('loadingState').innerHTML =
|
||
'<div class="text-center"><p class="text-red-500">缺少表单ID</p><p class="text-sm text-gray-500 mt-2">请检查URL是否正确</p></div>';
|
||
showToast('缺少表单ID', 'error');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
console.log('Fetching API:', `/api/status_data?formId=${formId}`);
|
||
const response = await fetch(`/api/status_data?formId=${formId}`);
|
||
const data = await response.json();
|
||
|
||
if (!response.ok) {
|
||
throw new Error(data.error || `HTTP ${response.status}`);
|
||
}
|
||
|
||
if (data.error) {
|
||
throw new Error(data.error);
|
||
}
|
||
|
||
statusData = data;
|
||
await renderData();
|
||
} catch (error) {
|
||
console.error('加载数据失败:', error);
|
||
document.getElementById('loadingState').innerHTML =
|
||
`<div class="text-center">
|
||
<p class="text-red-500 mb-2">加载失败</p>
|
||
<p class="text-sm text-gray-500">${error.message}</p>
|
||
<button onclick="location.reload(true)" class="mt-4 px-4 py-2 bg-gray-100 rounded-lg text-sm hover:bg-gray-200">重试</button>
|
||
</div>`;
|
||
showToast('加载数据失败: ' + error.message, 'error');
|
||
}
|
||
}
|
||
|
||
async function renderData() {
|
||
// 验证数据完整性
|
||
if (!statusData || !statusData.students) {
|
||
document.getElementById('loadingState').innerHTML =
|
||
'<div class="text-center text-red-500">数据格式错误</div>';
|
||
return;
|
||
}
|
||
|
||
// Hide loading, show content
|
||
document.getElementById('loadingState').style.display = 'none';
|
||
document.getElementById('contentArea').classList.remove('hidden');
|
||
|
||
// Update title
|
||
document.getElementById('formTitle').textContent = statusData.formTitle || '未命名表单';
|
||
|
||
// Update stats
|
||
const total = statusData.total;
|
||
const submitted = statusData.submitted;
|
||
const pending = total - submitted;
|
||
const rate = total > 0 ? Math.round((submitted / total) * 100) : 0;
|
||
|
||
document.getElementById('totalCount').textContent = total;
|
||
document.getElementById('submittedCount').textContent = submitted;
|
||
document.getElementById('pendingCount').textContent = pending;
|
||
document.getElementById('completionRate').textContent = rate + '%';
|
||
document.getElementById('progressPercent').textContent = rate + '%';
|
||
|
||
// Animate progress bar
|
||
setTimeout(() => {
|
||
document.getElementById('progressBar').style.width = rate + '%';
|
||
}, 300);
|
||
|
||
// Render student list
|
||
renderStudentList();
|
||
|
||
// Initialize charts
|
||
await initCharts();
|
||
|
||
// Animate elements
|
||
gsap.to("#headerSection", { opacity: 1, y: 0, duration: 0.6, ease: "power2.out" });
|
||
gsap.to(".stagger-item", {
|
||
opacity: 1,
|
||
y: 0,
|
||
duration: 0.5,
|
||
stagger: 0.1,
|
||
ease: "power2.out",
|
||
delay: 0.2
|
||
});
|
||
}
|
||
|
||
function renderStudentList() {
|
||
const tbody = document.getElementById('studentList');
|
||
const students = statusData.students;
|
||
|
||
tbody.innerHTML = students.map((student, idx) => {
|
||
const hasFiles = student.files && student.files.length > 0;
|
||
const fileCount = hasFiles ? student.files.length : 0;
|
||
|
||
return `
|
||
<tr class="student-item border-b theme-transition" style="border-color: var(--glass-border);">
|
||
<td class="p-4 font-mono text-xs theme-transition" style="color: var(--text-secondary);">${student.anonymous ? (student.shortId || '匿名') : student.id}</td>
|
||
<td class="p-4 theme-transition" style="color: var(--text-primary);">${student.name}</td>
|
||
<td class="p-4">
|
||
${student.submitted
|
||
? `<span class="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium" style="background: var(--success-bg); color: var(--success-text);">
|
||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
||
<polyline points="20 6 9 17 4 12"></polyline>
|
||
</svg>
|
||
已提交
|
||
</span>`
|
||
: `<span class="inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium" style="background: var(--warning-bg); color: var(--warning-text);">
|
||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
||
<circle cx="12" cy="12" r="10"></circle>
|
||
<line x1="12" y1="8" x2="12" y2="12"></line>
|
||
<line x1="12" y1="16" x2="12.01" y2="16"></line>
|
||
</svg>
|
||
未提交
|
||
</span>`
|
||
}
|
||
</td>
|
||
<td class="p-4 theme-transition" style="color: var(--text-muted);">
|
||
${hasFiles ? `${fileCount} 个文件` : '-'}
|
||
</td>
|
||
<td class="p-4">
|
||
${hasFiles
|
||
? `<button onclick="downloadFile('${student.files[0].download_url}')" class="text-xs px-3 py-1.5 rounded-lg border hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors theme-transition" style="border-color: var(--border-color); color: var(--text-secondary);">
|
||
下载
|
||
</button>`
|
||
: '-'
|
||
}
|
||
</td>
|
||
<td class="p-4">
|
||
${student.submitted
|
||
? `<button onclick="openHistoryModal(${idx})" class="text-xs px-3 py-1.5 rounded-lg border hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors theme-transition" style="border-color: var(--border-color); color: var(--text-secondary);">
|
||
查看历史
|
||
</button>`
|
||
: '-'
|
||
}
|
||
</td>
|
||
</tr>
|
||
`;
|
||
}).join('');
|
||
}
|
||
|
||
// 设置时间粒度
|
||
function setGranularity(granularity) {
|
||
currentGranularity = granularity;
|
||
|
||
// 更新按钮样式
|
||
document.querySelectorAll('.granularity-btn').forEach(btn => {
|
||
btn.classList.remove('active');
|
||
if (btn.dataset.granularity === granularity) {
|
||
btn.classList.add('active');
|
||
}
|
||
});
|
||
|
||
// 确保时间范围选择器显示并初始化
|
||
const rangeSelector = document.getElementById('timeRangeSelector');
|
||
if (rangeSelector) {
|
||
rangeSelector.style.display = 'flex';
|
||
initTimeRangeInputs();
|
||
}
|
||
|
||
// 重新渲染趋势图
|
||
updateTrendChart();
|
||
}
|
||
|
||
// 初始化时间范围输入框
|
||
function initTimeRangeInputs() {
|
||
if (!submissionTimesCache || submissionTimesCache.length === 0) return;
|
||
|
||
// 转换为本地时间并排序
|
||
const sortedTimes = submissionTimesCache.map(t => {
|
||
const d = new Date(t);
|
||
return new Date(d.getFullYear(), d.getMonth(), d.getDate(),
|
||
d.getHours(), d.getMinutes(), d.getSeconds());
|
||
}).sort((a, b) => a - b);
|
||
|
||
// 获取完整的日期范围(包含边界)
|
||
const startTime = new Date(sortedTimes[0]);
|
||
startTime.setHours(0, 0, 0, 0); // 开始于当天的开始
|
||
|
||
const endTime = new Date(sortedTimes[sortedTimes.length - 1]);
|
||
endTime.setHours(23, 59, 59, 999); // 结束于当天的结束
|
||
|
||
const startInput = document.getElementById('startTime');
|
||
const endInput = document.getElementById('endTime');
|
||
|
||
if (startInput && !startInput.value) {
|
||
startInput.value = formatDateTimeLocal(startTime);
|
||
timeRangeStart = startTime;
|
||
}
|
||
if (endInput && !endInput.value) {
|
||
endInput.value = formatDateTimeLocal(endTime);
|
||
timeRangeEnd = endTime;
|
||
}
|
||
}
|
||
|
||
// 格式化日期为 datetime-local 格式
|
||
function formatDateTimeLocal(date) {
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||
const day = String(date.getDate()).padStart(2, '0');
|
||
const hours = String(date.getHours()).padStart(2, '0');
|
||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||
return `${year}-${month}-${day}T${hours}:${minutes}`;
|
||
}
|
||
|
||
// 更新时间范围
|
||
function updateTimeRange() {
|
||
const startInput = document.getElementById('startTime');
|
||
const endInput = document.getElementById('endTime');
|
||
|
||
if (startInput && startInput.value) {
|
||
// 将输入的本地时间转换为完整的日期对象
|
||
const d = new Date(startInput.value);
|
||
timeRangeStart = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
|
||
} else {
|
||
timeRangeStart = null;
|
||
}
|
||
|
||
if (endInput && endInput.value) {
|
||
// 将输入的本地时间转换为完整的日期对象(包含当天结束)
|
||
const d = new Date(endInput.value);
|
||
timeRangeEnd = new Date(d.getFullYear(), d.getMonth(), d.getDate(), 23, 59, 59, 999);
|
||
} else {
|
||
timeRangeEnd = null;
|
||
}
|
||
|
||
// 验证时间范围有效性
|
||
if (timeRangeStart && timeRangeEnd && timeRangeStart > timeRangeEnd) {
|
||
showToast('开始时间不能晚于结束时间', 'error');
|
||
return;
|
||
}
|
||
|
||
updateTrendChart();
|
||
}
|
||
|
||
// 重置时间范围
|
||
function resetTimeRange() {
|
||
const startInput = document.getElementById('startTime');
|
||
const endInput = document.getElementById('endTime');
|
||
|
||
if (startInput) startInput.value = '';
|
||
if (endInput) endInput.value = '';
|
||
|
||
timeRangeStart = null;
|
||
timeRangeEnd = null;
|
||
|
||
// 重新初始化
|
||
initTimeRangeInputs();
|
||
updateTrendChart();
|
||
}
|
||
|
||
// 根据粒度聚合数据(同时处理首次提交和覆盖提交)
|
||
function aggregateDataByGranularity(times, granularity, overwriteTimes) {
|
||
// 确保 granularity 有默认值
|
||
const effectiveGranularity = granularity || 'day';
|
||
|
||
if (!times || times.length === 0) {
|
||
return { labels: [], counts: [], overwriteCounts: [], dateMarkers: [] };
|
||
}
|
||
|
||
// 转换为本地时间并排序
|
||
let sortedTimes = times.map(t => {
|
||
const d = new Date(t);
|
||
return new Date(d.getFullYear(), d.getMonth(), d.getDate(),
|
||
d.getHours(), d.getMinutes(), d.getSeconds());
|
||
}).sort((a, b) => a - b);
|
||
|
||
// 应用时间范围过滤(使用本地时间)
|
||
if (timeRangeStart) {
|
||
const startLocal = new Date(timeRangeStart.getFullYear(), timeRangeStart.getMonth(),
|
||
timeRangeStart.getDate(), timeRangeStart.getHours(),
|
||
timeRangeStart.getMinutes());
|
||
sortedTimes = sortedTimes.filter(t => {
|
||
const tLocal = new Date(t.getFullYear(), t.getMonth(), t.getDate(),
|
||
t.getHours(), t.getMinutes());
|
||
return tLocal >= startLocal;
|
||
});
|
||
}
|
||
if (timeRangeEnd) {
|
||
const endLocal = new Date(timeRangeEnd.getFullYear(), timeRangeEnd.getMonth(),
|
||
timeRangeEnd.getDate(), timeRangeEnd.getHours(),
|
||
timeRangeEnd.getMinutes(), 59, 999);
|
||
sortedTimes = sortedTimes.filter(t => {
|
||
const tLocal = new Date(t.getFullYear(), t.getMonth(), t.getDate(),
|
||
t.getHours(), t.getMinutes());
|
||
return tLocal <= endLocal;
|
||
});
|
||
}
|
||
|
||
if (sortedTimes.length === 0) {
|
||
return { labels: [], counts: [], dateMarkers: [], dateRange: '无数据' };
|
||
}
|
||
|
||
// 获取时间范围,并扩展到完整的开始和结束边界
|
||
let startTime = new Date(sortedTimes[0]);
|
||
let endTime = new Date(sortedTimes[sortedTimes.length - 1]);
|
||
|
||
// 根据粒度调整时间边界
|
||
switch(effectiveGranularity) {
|
||
case 'minute':
|
||
startTime.setSeconds(0, 0);
|
||
endTime.setSeconds(59, 999);
|
||
break;
|
||
case 'hour':
|
||
startTime.setMinutes(0, 0, 0);
|
||
endTime.setMinutes(59, 59, 999);
|
||
break;
|
||
case 'day':
|
||
startTime.setHours(0, 0, 0, 0);
|
||
endTime.setHours(23, 59, 59, 999);
|
||
break;
|
||
case 'week':
|
||
const startDay = startTime.getDay();
|
||
startTime.setDate(startTime.getDate() - startDay);
|
||
startTime.setHours(0, 0, 0, 0);
|
||
const endDay = endTime.getDay();
|
||
endTime.setDate(endTime.getDate() + (6 - endDay));
|
||
endTime.setHours(23, 59, 59, 999);
|
||
break;
|
||
case 'month':
|
||
startTime.setDate(1);
|
||
startTime.setHours(0, 0, 0, 0);
|
||
endTime.setMonth(endTime.getMonth() + 1, 0);
|
||
endTime.setHours(23, 59, 59, 999);
|
||
break;
|
||
case 'quarter':
|
||
const startQuarter = Math.floor(startTime.getMonth() / 3);
|
||
startTime.setMonth(startQuarter * 3, 1);
|
||
startTime.setHours(0, 0, 0, 0);
|
||
const endQuarter = Math.floor(endTime.getMonth() / 3);
|
||
endTime.setMonth((endQuarter + 1) * 3, 0);
|
||
endTime.setHours(23, 59, 59, 999);
|
||
break;
|
||
case 'year':
|
||
startTime.setMonth(0, 1);
|
||
startTime.setHours(0, 0, 0, 0);
|
||
endTime.setMonth(11, 31);
|
||
endTime.setHours(23, 59, 59, 999);
|
||
break;
|
||
}
|
||
|
||
let intervals = [];
|
||
let labels = [];
|
||
let dateMarkers = []; // 标记新日期的索引
|
||
|
||
const formatDate = (date) => {
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||
const day = String(date.getDate()).padStart(2, '0');
|
||
const hour = String(date.getHours()).padStart(2, '0');
|
||
const minute = String(date.getMinutes()).padStart(2, '0');
|
||
|
||
switch(effectiveGranularity) {
|
||
case 'minute': return `${hour}:${minute}`;
|
||
case 'hour': return `${day}日 ${hour}:00`;
|
||
case 'day': return `${month}-${day}`;
|
||
case 'week': return `${year}-W${getWeekNumber(date)}`;
|
||
case 'month': return `${year}-${month}`;
|
||
case 'quarter': return `${year}Q${Math.floor(date.getMonth() / 3) + 1}`;
|
||
case 'year': return `${year}年`;
|
||
default: return `${month}-${day}`;
|
||
}
|
||
};
|
||
|
||
const getWeekNumber = (date) => {
|
||
const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
||
const dayNum = d.getUTCDay() || 7;
|
||
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
||
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
||
return Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
|
||
};
|
||
|
||
const getIntervalKey = (date) => {
|
||
const year = date.getFullYear();
|
||
const month = date.getMonth();
|
||
const day = date.getDate();
|
||
const hour = date.getHours();
|
||
const minute = date.getMinutes();
|
||
|
||
// 格式化辅助函数
|
||
const pad = (n) => n < 10 ? `0${n}` : n;
|
||
|
||
switch(effectiveGranularity) {
|
||
case 'minute': return `${year}-${pad(month+1)}-${pad(day)}-${pad(hour)}-${pad(minute)}`;
|
||
case 'hour': return `${year}-${pad(month+1)}-${pad(day)}-${pad(hour)}`;
|
||
case 'day': return `${year}-${pad(month+1)}-${pad(day)}`;
|
||
case 'week': return `${year}-W${pad(getWeekNumber(date))}`;
|
||
case 'month': return `${year}-${pad(month+1)}`;
|
||
case 'quarter': return `${year}-Q${Math.floor(month / 3) + 1}`;
|
||
case 'year': return `${year}`;
|
||
default: return `${year}-${pad(month+1)}-${pad(day)}`;
|
||
}
|
||
};
|
||
|
||
// 统计每个时间段的提交数
|
||
const counts = {};
|
||
const overwriteCountsMap = {};
|
||
const intervalDates = {};
|
||
|
||
sortedTimes.forEach(time => {
|
||
const key = getIntervalKey(time);
|
||
if (!counts[key]) {
|
||
counts[key] = 0;
|
||
intervalDates[key] = time;
|
||
}
|
||
counts[key]++;
|
||
});
|
||
|
||
// 统计覆盖提交(同样过滤时间范围,按相同粒度聚合)
|
||
const rawOverwrite = overwriteTimes || [];
|
||
rawOverwrite.forEach(t => {
|
||
const d = new Date(t);
|
||
const local = new Date(d.getFullYear(), d.getMonth(), d.getDate(),
|
||
d.getHours(), d.getMinutes(), d.getSeconds());
|
||
// 应用时间范围过滤
|
||
if (timeRangeStart) {
|
||
const s = new Date(timeRangeStart.getFullYear(), timeRangeStart.getMonth(),
|
||
timeRangeStart.getDate(), timeRangeStart.getHours(),
|
||
timeRangeStart.getMinutes());
|
||
if (local < s) return;
|
||
}
|
||
if (timeRangeEnd) {
|
||
const e = new Date(timeRangeEnd.getFullYear(), timeRangeEnd.getMonth(),
|
||
timeRangeEnd.getDate(), timeRangeEnd.getHours(),
|
||
timeRangeEnd.getMinutes(), 59, 999);
|
||
if (local > e) return;
|
||
}
|
||
const key = getIntervalKey(local);
|
||
overwriteCountsMap[key] = (overwriteCountsMap[key] || 0) + 1;
|
||
});
|
||
|
||
// 生成完整的时间序列(填充空缺)
|
||
let current = new Date(startTime);
|
||
let lastDate = null;
|
||
let index = 0;
|
||
const overwriteIntervals = [];
|
||
|
||
while (current <= endTime) {
|
||
const key = getIntervalKey(current);
|
||
const count = counts[key] || 0;
|
||
|
||
labels.push(formatDate(current));
|
||
intervals.push(count);
|
||
overwriteIntervals.push(overwriteCountsMap[key] || 0);
|
||
|
||
// 检查是否为新的一天(用于视觉标记,使用本地时间)
|
||
if (effectiveGranularity === 'minute' || effectiveGranularity === 'hour') {
|
||
const currentDate = new Date(current.getFullYear(), current.getMonth(), current.getDate()).getTime();
|
||
if (lastDate !== null && currentDate !== lastDate) {
|
||
dateMarkers.push(index);
|
||
}
|
||
lastDate = currentDate;
|
||
} else if (effectiveGranularity === 'day' || effectiveGranularity === 'week') {
|
||
// 按月标记
|
||
const currentMonth = current.getMonth();
|
||
if (lastDate !== null && currentMonth !== lastDate) {
|
||
dateMarkers.push(index);
|
||
}
|
||
lastDate = currentMonth;
|
||
}
|
||
|
||
// 增加时间
|
||
switch(effectiveGranularity) {
|
||
case 'minute': current.setMinutes(current.getMinutes() + 1); break;
|
||
case 'hour': current.setHours(current.getHours() + 1); break;
|
||
case 'day': current.setDate(current.getDate() + 1); break;
|
||
case 'week': current.setDate(current.getDate() + 7); break;
|
||
case 'month': current.setMonth(current.getMonth() + 1); break;
|
||
case 'quarter': current.setMonth(current.getMonth() + 3); break;
|
||
case 'year': current.setFullYear(current.getFullYear() + 1); break;
|
||
}
|
||
index++;
|
||
}
|
||
|
||
return {
|
||
labels,
|
||
counts: intervals, // 每个时段首次提交数(非累积)
|
||
overwriteCounts: overwriteIntervals, // 每个时段覆盖提交数
|
||
dateMarkers,
|
||
dateRange: `${formatDate(startTime)} ~ ${formatDate(endTime)}`
|
||
};
|
||
}
|
||
|
||
// 更新趋势图
|
||
async function updateTrendChart() {
|
||
if (!submissionTimesCache || submissionTimesCache.length === 0) {
|
||
// 尝试重新获取数据
|
||
try {
|
||
const timeResponse = await fetch(`/api/submission_times/${formId}`);
|
||
if (timeResponse.ok) {
|
||
const timeData = await timeResponse.json();
|
||
if (!timeData.error && timeData.rawTimes) {
|
||
submissionTimesCache = timeData.rawTimes;
|
||
overwriteTimesCache = timeData.overwriteTimes || [];
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error('获取时间数据失败:', e);
|
||
return;
|
||
}
|
||
}
|
||
|
||
// 确保时间范围选择器显示并初始化
|
||
const rangeSelector = document.getElementById('timeRangeSelector');
|
||
if (rangeSelector) {
|
||
rangeSelector.style.display = 'flex';
|
||
initTimeRangeInputs();
|
||
}
|
||
|
||
const aggregated = aggregateDataByGranularity(submissionTimesCache, currentGranularity, overwriteTimesCache);
|
||
|
||
// 更新日期范围显示
|
||
const dateRangeDisplay = document.getElementById('dateRangeDisplay');
|
||
if (dateRangeDisplay && aggregated.dateRange) {
|
||
dateRangeDisplay.textContent = aggregated.dateRange;
|
||
}
|
||
|
||
renderTrendChart(aggregated.labels, aggregated.counts, aggregated.overwriteCounts, aggregated.dateMarkers);
|
||
}
|
||
|
||
// 渲染趋势图(堆叠柱状图:首次提交 + 覆盖提交)
|
||
function renderTrendChart(labels, data, overwriteData, dateMarkers) {
|
||
const isDark = document.documentElement.classList.contains('dark');
|
||
const textColor = isDark ? '#fafafa' : '#171717';
|
||
const gridColor = isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.1)';
|
||
const markerColor = isDark ? 'rgba(250, 204, 21, 0.3)' : 'rgba(250, 204, 21, 0.5)';
|
||
|
||
const trendChartEl = document.getElementById('trendChart');
|
||
if (trendChart) trendChart.dispose();
|
||
trendChart = echarts.init(trendChartEl);
|
||
|
||
const hasAnyData = (data && data.some(v => v > 0)) || (overwriteData && overwriteData.some(v => v > 0));
|
||
if (labels.length === 0 || !hasAnyData) {
|
||
trendChart.setOption({
|
||
title: {
|
||
text: '暂无提交数据',
|
||
left: 'center',
|
||
top: 'center',
|
||
textStyle: { color: textColor, fontSize: 14 }
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
|
||
// 构建标记区域(新日期背景)
|
||
const markAreas = [];
|
||
if (dateMarkers && dateMarkers.length > 0) {
|
||
dateMarkers.forEach((markerIndex, i) => {
|
||
if (i % 2 === 0) {
|
||
markAreas.push([{
|
||
xAxis: labels[markerIndex],
|
||
itemStyle: { color: markerColor }
|
||
}, {
|
||
xAxis: labels[markerIndex + 1] || labels[labels.length - 1]
|
||
}]);
|
||
}
|
||
});
|
||
}
|
||
|
||
const option = {
|
||
tooltip: {
|
||
trigger: 'axis',
|
||
axisPointer: { type: 'shadow' },
|
||
backgroundColor: isDark ? 'rgba(23,23,23,0.9)' : 'rgba(255,255,255,0.9)',
|
||
borderColor: isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.1)',
|
||
textStyle: { color: textColor },
|
||
formatter: function (params) {
|
||
const first = params.find(p => p.seriesName === '首次提交');
|
||
const over = params.find(p => p.seriesName === '覆盖提交');
|
||
const firstVal = first ? first.value : 0;
|
||
const overVal = over ? over.value : 0;
|
||
const total = firstVal + overVal;
|
||
const marker = dateMarkers && dateMarkers.includes(params[0].dataIndex)
|
||
? ' <span style="color:#facc15">●</span> 新日期' : '';
|
||
return `${params[0].name}${marker}<br/>`
|
||
+ `<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#22c55e;margin-right:4px;"></span>首次提交: <strong>${firstVal}</strong><br/>`
|
||
+ `<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#f97316;margin-right:4px;"></span>覆盖提交: <strong>${overVal}</strong><br/>`
|
||
+ `合计: <strong>${total}</strong>`;
|
||
}
|
||
},
|
||
legend: {
|
||
show: false // 用顶部自定义 legend
|
||
},
|
||
grid: {
|
||
left: '3%',
|
||
right: '4%',
|
||
bottom: '15%',
|
||
top: '10%',
|
||
containLabel: true
|
||
},
|
||
dataZoom: labels.length > 20 ? [{
|
||
type: 'inside',
|
||
start: 0,
|
||
end: 100
|
||
}, {
|
||
type: 'slider',
|
||
start: 0,
|
||
end: 100,
|
||
bottom: 10,
|
||
height: 20,
|
||
borderColor: 'transparent',
|
||
backgroundColor: isDark ? 'rgba(255,255,255,0.05)' : 'rgba(0,0,0,0.05)',
|
||
fillerColor: isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.1)',
|
||
handleStyle: { color: textColor }
|
||
}] : undefined,
|
||
xAxis: {
|
||
type: 'category',
|
||
data: labels,
|
||
axisLine: { lineStyle: { color: gridColor } },
|
||
axisLabel: {
|
||
color: textColor,
|
||
rotate: labels.length > 12 ? 45 : 0,
|
||
interval: labels.length > 30 ? 'auto' : 0,
|
||
fontSize: 11
|
||
}
|
||
},
|
||
yAxis: {
|
||
type: 'value',
|
||
minInterval: 1,
|
||
axisLine: { lineStyle: { color: gridColor } },
|
||
axisLabel: { color: textColor },
|
||
splitLine: { lineStyle: { color: gridColor } }
|
||
},
|
||
series: [
|
||
{
|
||
name: '首次提交',
|
||
type: 'bar',
|
||
stack: 'total',
|
||
data: data,
|
||
barMaxWidth: 40,
|
||
itemStyle: {
|
||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||
{ offset: 0, color: '#4ade80' },
|
||
{ offset: 1, color: '#16a34a' }
|
||
]),
|
||
borderRadius: [0, 0, 0, 0]
|
||
},
|
||
emphasis: { itemStyle: { color: '#22c55e' } },
|
||
markArea: {
|
||
silent: true,
|
||
data: markAreas
|
||
}
|
||
},
|
||
{
|
||
name: '覆盖提交',
|
||
type: 'bar',
|
||
stack: 'total',
|
||
data: overwriteData || [],
|
||
barMaxWidth: 40,
|
||
itemStyle: {
|
||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||
{ offset: 0, color: '#fb923c' },
|
||
{ offset: 1, color: '#ea580c' }
|
||
]),
|
||
borderRadius: [3, 3, 0, 0]
|
||
},
|
||
emphasis: { itemStyle: { color: '#f97316' } }
|
||
}
|
||
]
|
||
};
|
||
|
||
trendChart.setOption(option);
|
||
}
|
||
|
||
async function initCharts() {
|
||
const isDark = document.documentElement.classList.contains('dark');
|
||
const textColor = isDark ? '#fafafa' : '#171717';
|
||
const gridColor = isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.1)';
|
||
|
||
// 获取提交时间数据
|
||
submissionTimesCache = [];
|
||
overwriteTimesCache = [];
|
||
|
||
try {
|
||
const timeResponse = await fetch(`/api/submission_times/${formId}`);
|
||
if (timeResponse.ok) {
|
||
const timeData = await timeResponse.json();
|
||
if (!timeData.error) {
|
||
submissionTimesCache = timeData.rawTimes || [];
|
||
overwriteTimesCache = timeData.overwriteTimes || [];
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error('获取时间数据失败:', e);
|
||
}
|
||
|
||
// ========== 1. 提交趋势图 ==========
|
||
// 确保时间范围已初始化后再渲染
|
||
initTimeRangeInputs();
|
||
await updateTrendChart();
|
||
|
||
// ========== 2. 提交时段分布(24小时) ==========
|
||
const timeDistChartEl = document.getElementById('timeDistributionChart');
|
||
if (timeDistributionChart) timeDistributionChart.dispose();
|
||
timeDistributionChart = echarts.init(timeDistChartEl);
|
||
|
||
// 分析时段分布(使用本地时间)
|
||
const hourDistribution = new Array(24).fill(0);
|
||
submissionTimesCache.forEach(timeStr => {
|
||
try {
|
||
const date = new Date(timeStr);
|
||
// 使用本地时间的小时数
|
||
const hour = date.getHours();
|
||
hourDistribution[hour]++;
|
||
} catch (e) {}
|
||
});
|
||
|
||
const hasTimeData = submissionTimesCache.length > 0;
|
||
|
||
if (!hasTimeData) {
|
||
timeDistributionChart.setOption({
|
||
title: {
|
||
text: '暂无时段数据',
|
||
left: 'center',
|
||
top: 'center',
|
||
textStyle: { color: textColor, fontSize: 14 }
|
||
}
|
||
});
|
||
} else {
|
||
const hours = Array.from({length: 24}, (_, i) => `${i}:00`);
|
||
const maxCount = Math.max(...hourDistribution);
|
||
const peakHour = hourDistribution.indexOf(maxCount);
|
||
|
||
const timeDistOption = {
|
||
tooltip: {
|
||
trigger: 'axis',
|
||
backgroundColor: isDark ? 'rgba(23,23,23,0.9)' : 'rgba(255,255,255,0.9)',
|
||
borderColor: isDark ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.1)',
|
||
textStyle: { color: textColor },
|
||
formatter: function(params) {
|
||
const hour = params[0].dataIndex;
|
||
const count = params[0].value;
|
||
const percentage = submissionTimesCache.length > 0
|
||
? ((count / submissionTimesCache.length) * 100).toFixed(1)
|
||
: 0;
|
||
return `<strong>${hour}:00 - ${hour}:59</strong><br/>提交人数: ${count}<br/>占比: ${percentage}%`;
|
||
}
|
||
},
|
||
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
|
||
xAxis: {
|
||
type: 'category',
|
||
data: hours,
|
||
axisLine: { lineStyle: { color: gridColor } },
|
||
axisLabel: {
|
||
color: textColor,
|
||
interval: 2
|
||
}
|
||
},
|
||
yAxis: {
|
||
type: 'value',
|
||
minInterval: 1,
|
||
axisLine: { lineStyle: { color: gridColor } },
|
||
axisLabel: { color: textColor },
|
||
splitLine: { lineStyle: { color: gridColor } }
|
||
},
|
||
series: [{
|
||
data: hourDistribution,
|
||
type: 'bar',
|
||
itemStyle: {
|
||
color: function(params) {
|
||
// 高峰时段用更亮的颜色
|
||
if (params.value === maxCount) {
|
||
return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||
{ offset: 0, color: '#f59e0b' },
|
||
{ offset: 1, color: '#d97706' }
|
||
]);
|
||
}
|
||
return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||
{ offset: 0, color: '#3b82f6' },
|
||
{ offset: 1, color: '#2563eb' }
|
||
]);
|
||
},
|
||
borderRadius: [4, 4, 0, 0]
|
||
},
|
||
emphasis: {
|
||
itemStyle: {
|
||
color: '#f59e0b'
|
||
}
|
||
}
|
||
}],
|
||
graphic: [
|
||
{
|
||
type: 'text',
|
||
left: 'center',
|
||
top: 10,
|
||
style: {
|
||
text: `高峰时段: ${peakHour}:00 (${maxCount}人)`,
|
||
fill: textColor,
|
||
fontSize: 12
|
||
}
|
||
}
|
||
]
|
||
};
|
||
timeDistributionChart.setOption(timeDistOption);
|
||
}
|
||
|
||
// Handle resize
|
||
if (!window._chartResizeHandler) {
|
||
window._chartResizeHandler = () => {
|
||
if (trendChart) trendChart.resize();
|
||
if (timeDistributionChart) timeDistributionChart.resize();
|
||
};
|
||
window.addEventListener('resize', window._chartResizeHandler);
|
||
}
|
||
}
|
||
|
||
async function createZip() {
|
||
openFilenameModal();
|
||
}
|
||
|
||
// 文件名模板配置
|
||
let selectedFields = [];
|
||
let separators = [];
|
||
let availableFieldsList = [];
|
||
|
||
// 打开弹窗
|
||
async function openFilenameModal() {
|
||
// 检测是否为触摸设备
|
||
isTouchDevice = window.matchMedia('(pointer: coarse)').matches || 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
||
|
||
// 获取表单配置中的所有字段
|
||
let formConfigFields = [];
|
||
try {
|
||
const response = await fetch(`/api/get_form/${formId}`);
|
||
if (response.ok) {
|
||
const formData = await response.json();
|
||
if (formData.fields && Array.isArray(formData.fields)) {
|
||
formConfigFields = formData.fields
|
||
.filter(f => f.type !== 'page_break' && f.name !== 'tail' && f.name !== 'name')
|
||
.map(f => ({
|
||
key: f.name,
|
||
label: f.placeholder || f.name,
|
||
type: f.type === 'file' ? 'file' : 'form'
|
||
}));
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error('获取表单配置失败:', e);
|
||
}
|
||
|
||
availableFieldsList = [
|
||
{ key: '学号', label: '学号', type: 'preset' },
|
||
{ key: '姓名', label: '姓名', type: 'preset' },
|
||
{ key: '尾号', label: '尾号', type: 'preset' },
|
||
...formConfigFields
|
||
];
|
||
|
||
selectedFields = [];
|
||
separators = [];
|
||
renderAvailableFields();
|
||
renderSelectedFields();
|
||
updatePreview();
|
||
|
||
document.getElementById('filenameModal').classList.remove('hidden');
|
||
document.body.style.overflow = 'hidden'; // 阻止背景滚动
|
||
setTimeout(() => {
|
||
document.getElementById('filenameModal').classList.add('show');
|
||
}, 10);
|
||
}
|
||
|
||
// 关闭弹窗
|
||
function closeFilenameModal() {
|
||
document.getElementById('filenameModal').classList.remove('show');
|
||
document.body.style.overflow = ''; // 恢复背景滚动
|
||
setTimeout(() => {
|
||
document.getElementById('filenameModal').classList.add('hidden');
|
||
}, 300);
|
||
}
|
||
|
||
// 渲染可用字段
|
||
|
||
// 移动字段位置(移动端用)
|
||
function moveField(index, direction) {
|
||
if (direction === 'up' && index > 0) {
|
||
// 交换与前一个位置
|
||
const temp = selectedFields[index];
|
||
selectedFields[index] = selectedFields[index - 1];
|
||
selectedFields[index - 1] = temp;
|
||
|
||
// 同步交换分隔符
|
||
if (index > 0 && index <= separators.length) {
|
||
const sepTemp = separators[index - 1];
|
||
if (index < separators.length) {
|
||
separators[index - 1] = separators[index];
|
||
separators[index] = sepTemp;
|
||
}
|
||
}
|
||
} else if (direction === 'down' && index < selectedFields.length - 1) {
|
||
// 交换与后一个位置
|
||
const temp = selectedFields[index];
|
||
selectedFields[index] = selectedFields[index + 1];
|
||
selectedFields[index + 1] = temp;
|
||
|
||
// 同步交换分隔符
|
||
if (index < separators.length) {
|
||
const sepTemp = separators[index];
|
||
if (index + 1 < separators.length) {
|
||
separators[index] = separators[index + 1];
|
||
separators[index + 1] = sepTemp;
|
||
}
|
||
}
|
||
}
|
||
renderSelectedFields();
|
||
updatePreview();
|
||
}
|
||
|
||
function renderAvailableFields() {
|
||
const container = document.getElementById('availableFields');
|
||
container.innerHTML = availableFieldsList.map(field => {
|
||
const isSelected = selectedFields.find(f => f.key === field.key);
|
||
const typeLabel = field.type === 'preset' ? '预设' :
|
||
field.type === 'file' ? '文件' : '字段';
|
||
const typeColor = field.type === 'preset' ? 'opacity-60' :
|
||
field.type === 'file' ? 'text-blue-400' : 'text-green-400';
|
||
|
||
return `
|
||
<button onclick="addField('${field.key}')"
|
||
class="field-tag available text-left"
|
||
${isSelected ? 'disabled style="opacity:0.3;cursor:not-allowed;"' : ''}>
|
||
<span class="truncate">${field.label}</span>
|
||
<span class="text-[10px] ${typeColor} ml-auto">${typeLabel}</span>
|
||
</button>
|
||
`}).join('');
|
||
}
|
||
|
||
// 添加字段
|
||
function addField(key) {
|
||
if (selectedFields.find(f => f.key === key)) return;
|
||
|
||
const field = availableFieldsList.find(f => f.key === key);
|
||
if (field) {
|
||
selectedFields.push(field);
|
||
if (selectedFields.length > 1) {
|
||
separators.push('');
|
||
}
|
||
renderSelectedFields();
|
||
renderAvailableFields();
|
||
updatePreview();
|
||
}
|
||
}
|
||
|
||
// 移除字段
|
||
function removeField(key) {
|
||
const index = selectedFields.findIndex(f => f.key === key);
|
||
if (index === -1) return;
|
||
|
||
selectedFields.splice(index, 1);
|
||
if (separators.length > 0) {
|
||
if (index === 0) {
|
||
separators.shift();
|
||
} else if (index === selectedFields.length + 1) {
|
||
separators.pop();
|
||
} else {
|
||
separators.splice(index - 1, 1);
|
||
}
|
||
}
|
||
|
||
renderSelectedFields();
|
||
renderAvailableFields();
|
||
updatePreview();
|
||
}
|
||
|
||
// 清空字段
|
||
function clearSelectedFields() {
|
||
selectedFields = [];
|
||
separators = [];
|
||
renderSelectedFields();
|
||
renderAvailableFields();
|
||
updatePreview();
|
||
}
|
||
|
||
// 更新分隔符
|
||
function updateSeparator(index, value) {
|
||
separators[index] = value;
|
||
updatePreview();
|
||
}
|
||
|
||
// 渲染已选字段
|
||
function renderSelectedFields() {
|
||
const container = document.getElementById('selectedFields');
|
||
|
||
if (selectedFields.length === 0) {
|
||
container.innerHTML = '<span class="text-sm italic" style="color: var(--text-muted);">暂无字段</span>';
|
||
return;
|
||
}
|
||
|
||
let html = '';
|
||
selectedFields.forEach((field, index) => {
|
||
html += `
|
||
<div class="field-tag selected" ${!isTouchDevice ? 'draggable="true"' : ''} data-index="${index}" data-key="${field.key}">
|
||
${!isTouchDevice ? `<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="opacity:0.6;cursor:move;">
|
||
<line x1="8" y1="6" x2="21" y2="6"></line>
|
||
<line x1="8" y1="12" x2="21" y2="12"></line>
|
||
<line x1="8" y1="18" x2="21" y2="18"></line>
|
||
<line x1="3" y1="6" x2="3.01" y2="6"></line>
|
||
<line x1="3" y1="12" x2="3.01" y2="12"></line>
|
||
<line x1="3" y1="18" x2="3.01" y2="18"></line>
|
||
</svg>` : ''}
|
||
<span>${field.label}</span>
|
||
<span class="remove-btn" onclick="event.stopPropagation(); removeField('${field.key}')">×</span>
|
||
|
||
${isTouchDevice ? `
|
||
<div class="mobile-sort-controls">
|
||
<button class="sort-btn" onclick="event.stopPropagation(); moveField(${index}, 'up')" ${index === 0 ? 'disabled' : ''}>
|
||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
||
<polyline points="18 15 12 9 6 15"></polyline>
|
||
</svg>
|
||
</button>
|
||
<button class="sort-btn" onclick="event.stopPropagation(); moveField(${index}, 'down')" ${index === selectedFields.length - 1 ? 'disabled' : ''}>
|
||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
||
<polyline points="6 9 12 15 18 9"></polyline>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
` : ''}
|
||
</div>
|
||
`;
|
||
|
||
if (index < selectedFields.length - 1) {
|
||
const sepValue = separators[index] || '';
|
||
html += `<input type="text" class="sep-input" placeholder="_" value="${sepValue}" oninput="updateSeparator(${index}, this.value)" title="输入分隔符">`;
|
||
}
|
||
});
|
||
|
||
container.innerHTML = html;
|
||
if (!isTouchDevice) {
|
||
setupDragAndDrop();
|
||
}
|
||
}
|
||
|
||
// 设置拖拽排序
|
||
function setupDragAndDrop() {
|
||
// 触摸设备使用按钮排序,不启用拖拽
|
||
if (isTouchDevice) return;
|
||
|
||
const container = document.getElementById('selectedFields');
|
||
const tags = container.querySelectorAll('.field-tag');
|
||
|
||
tags.forEach(tag => {
|
||
tag.addEventListener('dragstart', (e) => {
|
||
e.dataTransfer.setData('text/plain', tag.dataset.index);
|
||
tag.classList.add('dragging');
|
||
});
|
||
|
||
tag.addEventListener('dragend', () => {
|
||
tag.classList.remove('dragging');
|
||
});
|
||
|
||
tag.addEventListener('dragover', (e) => {
|
||
e.preventDefault();
|
||
});
|
||
|
||
tag.addEventListener('drop', (e) => {
|
||
e.preventDefault();
|
||
const fromIndex = parseInt(e.dataTransfer.getData('text/plain'));
|
||
const toIndex = parseInt(tag.dataset.index);
|
||
|
||
if (fromIndex !== toIndex) {
|
||
const item = selectedFields.splice(fromIndex, 1)[0];
|
||
selectedFields.splice(toIndex, 0, item);
|
||
|
||
if (separators.length > 0) {
|
||
let sepIndex = fromIndex < selectedFields.length - 1 ? fromIndex : fromIndex - 1;
|
||
if (sepIndex >= 0 && sepIndex < separators.length) {
|
||
const sep = separators.splice(sepIndex, 1)[0];
|
||
let newSepIndex = toIndex < selectedFields.length - 1 ? toIndex : toIndex - 1;
|
||
newSepIndex = Math.max(0, Math.min(newSepIndex, separators.length));
|
||
separators.splice(newSepIndex, 0, sep);
|
||
}
|
||
}
|
||
|
||
renderSelectedFields();
|
||
updatePreview();
|
||
}
|
||
});
|
||
});
|
||
}
|
||
|
||
// 更新预览
|
||
function updatePreview() {
|
||
const preview = document.getElementById('filenamePreview');
|
||
|
||
if (selectedFields.length === 0) {
|
||
preview.innerHTML = '<span class="opacity-50">请选择字段...</span>';
|
||
return;
|
||
}
|
||
|
||
const exampleStudent = statusData?.students?.[0];
|
||
let filename = '';
|
||
let hasFileField = false;
|
||
|
||
selectedFields.forEach((field, index) => {
|
||
let value = '';
|
||
if (field.key === '学号') {
|
||
value = exampleStudent?.id || '20210001';
|
||
} else if (field.key === '姓名') {
|
||
value = exampleStudent?.name || '张三';
|
||
} else if (field.key === '尾号') {
|
||
value = exampleStudent?.tail || '001';
|
||
} else if (field.type === 'file') {
|
||
value = field.label;
|
||
hasFileField = true;
|
||
} else {
|
||
value = exampleStudent?.data?.[field.key] || field.key;
|
||
}
|
||
|
||
filename += value;
|
||
|
||
if (index < selectedFields.length - 1 && separators[index]) {
|
||
filename += separators[index];
|
||
}
|
||
});
|
||
|
||
if (hasFileField) {
|
||
preview.innerHTML = filename + '.<span style="color: var(--text-muted);">扩展名</span>';
|
||
} else {
|
||
preview.textContent = filename + '.pdf';
|
||
}
|
||
}
|
||
|
||
// 确认导出
|
||
async function confirmExport() {
|
||
if (selectedFields.length === 0) {
|
||
showToast('请至少选择一个字段', 'error');
|
||
return;
|
||
}
|
||
|
||
closeFilenameModal();
|
||
|
||
let template = '';
|
||
selectedFields.forEach((field, index) => {
|
||
template += `{${field.key}}`;
|
||
if (index < selectedFields.length - 1 && separators[index]) {
|
||
template += separators[index];
|
||
}
|
||
});
|
||
|
||
const fieldTypes = {};
|
||
selectedFields.forEach(f => {
|
||
fieldTypes[f.key] = f.type;
|
||
});
|
||
|
||
try {
|
||
showToast('正在打包...', 'success');
|
||
|
||
const response = await fetch(`/api/create_zip/${formId}`, {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json'
|
||
},
|
||
body: JSON.stringify({
|
||
template: template,
|
||
fieldTypes: fieldTypes
|
||
})
|
||
});
|
||
|
||
const data = await response.json();
|
||
|
||
if (data.success) {
|
||
// 多浏览器兼容的下载触发
|
||
const downloadUrl = data.download_url;
|
||
|
||
// 方法1: 使用a标签(推荐,避免拦截)
|
||
const link = document.createElement('a');
|
||
link.href = downloadUrl;
|
||
link.download = data.filename || 'export.zip';
|
||
link.style.display = 'none';
|
||
document.body.appendChild(link);
|
||
|
||
try {
|
||
link.click();
|
||
} catch (e) {
|
||
// 方法2: 直接跳转
|
||
window.location.href = downloadUrl;
|
||
}
|
||
|
||
setTimeout(() => {
|
||
if (link.parentNode) {
|
||
document.body.removeChild(link);
|
||
}
|
||
}, 100);
|
||
|
||
showToast('打包完成,开始下载', 'success');
|
||
} else {
|
||
showToast(data.error || '打包失败', 'error');
|
||
}
|
||
} catch (error) {
|
||
showToast('打包失败: ' + error.message, 'error');
|
||
}
|
||
}
|
||
|
||
function exportData(format) {
|
||
const url = `/api/export/${formId}?format=${format}`;
|
||
|
||
// 多浏览器兼容的下载方式
|
||
// 方式1: 尝试使用a标签下载(避免弹窗拦截)
|
||
const link = document.createElement('a');
|
||
link.href = url;
|
||
link.download = ''; // 让服务器决定文件名
|
||
link.style.display = 'none';
|
||
document.body.appendChild(link);
|
||
|
||
// 方式2: 如果a标签方式失败,回退到window.open
|
||
try {
|
||
link.click();
|
||
} catch (e) {
|
||
window.open(url, '_blank');
|
||
}
|
||
|
||
// 清理
|
||
setTimeout(() => {
|
||
document.body.removeChild(link);
|
||
}, 100);
|
||
|
||
showToast('正在导出Excel表格...', 'success');
|
||
}
|
||
|
||
function downloadFile(url) {
|
||
// 多浏览器兼容下载
|
||
// 移动端某些浏览器会拦截window.open,使用a标签更可靠
|
||
const link = document.createElement('a');
|
||
link.href = url;
|
||
link.download = ''; // 使用服务器提供的文件名
|
||
link.style.display = 'none';
|
||
link.target = '_blank'; // 兼容不支持download属性的浏览器
|
||
document.body.appendChild(link);
|
||
|
||
try {
|
||
link.click();
|
||
} catch (e) {
|
||
// 回退方案
|
||
window.open(url, '_blank');
|
||
}
|
||
|
||
setTimeout(() => {
|
||
if (link.parentNode) {
|
||
document.body.removeChild(link);
|
||
}
|
||
}, 100);
|
||
}
|
||
|
||
|
||
function copyFormLink() {
|
||
if (!formId) {
|
||
showToast('表单ID未加载', 'error');
|
||
return;
|
||
}
|
||
// 动态获取当前协议和host,适配多浏览器/设备环境
|
||
const protocol = window.location.protocol;
|
||
const host = window.location.host;
|
||
const url = `${protocol}//${host}/${formId}`;
|
||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||
navigator.clipboard.writeText(url).then(() => {
|
||
showToast('链接已复制', 'success');
|
||
}).catch(() => {
|
||
fallbackCopy(url);
|
||
});
|
||
} else {
|
||
fallbackCopy(url);
|
||
}
|
||
}
|
||
|
||
function fallbackCopy(text) {
|
||
const textArea = document.createElement('textarea');
|
||
textArea.value = text;
|
||
textArea.style.position = 'fixed';
|
||
textArea.style.left = '-9999px';
|
||
textArea.style.top = '0';
|
||
textArea.setAttribute('readonly', ''); // iOS兼容
|
||
document.body.appendChild(textArea);
|
||
|
||
// 兼容iOS的选择方式
|
||
const range = document.createRange();
|
||
range.selectNodeContents(textArea);
|
||
|
||
const selection = window.getSelection();
|
||
selection.removeAllRanges();
|
||
selection.addRange(range);
|
||
|
||
// 额外尝试select()
|
||
textArea.select();
|
||
textArea.setSelectionRange(0, 999999); // 移动端兼容
|
||
|
||
try {
|
||
const successful = document.execCommand('copy');
|
||
if (successful) {
|
||
showToast('链接已复制', 'success');
|
||
} else {
|
||
// 如果execCommand失败,显示链接让用户手动复制
|
||
showCopyDialog(text);
|
||
}
|
||
} catch (err) {
|
||
console.error('Copy failed:', err);
|
||
showCopyDialog(text);
|
||
}
|
||
|
||
document.body.removeChild(textArea);
|
||
selection.removeAllRanges();
|
||
}
|
||
|
||
// 显示手动复制对话框(终极fallback)
|
||
function showCopyDialog(text) {
|
||
// 创建一个临时的模态框显示链接
|
||
const modal = document.createElement('div');
|
||
modal.style.cssText = `
|
||
position: fixed;
|
||
top: 0; left: 0; right: 0; bottom: 0;
|
||
background: rgba(0,0,0,0.5);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
z-index: 9999;
|
||
padding: 20px;
|
||
`;
|
||
|
||
const box = document.createElement('div');
|
||
box.style.cssText = `
|
||
background: var(--bg-primary, #fff);
|
||
color: var(--text-primary, #000);
|
||
padding: 24px;
|
||
border-radius: 12px;
|
||
max-width: 400px;
|
||
width: 100%;
|
||
box-shadow: 0 20px 40px rgba(0,0,0,0.3);
|
||
`;
|
||
|
||
box.innerHTML = `
|
||
<h3 style="margin: 0 0 12px 0; font-size: 16px;">请手动复制链接</h3>
|
||
<p style="margin: 0 0 12px 0; font-size: 13px; opacity: 0.7;">您的浏览器限制了自动复制功能</p>
|
||
<input type="text" value="${text}" readonly
|
||
style="width: 100%; padding: 10px; border: 1px solid var(--border-color, #ddd);
|
||
border-radius: 6px; font-size: 13px; margin-bottom: 16px;
|
||
background: var(--bg-secondary, #f5f5f5); color: var(--text-primary, #000);"
|
||
onclick="this.select()">
|
||
<button style="width: 100%; padding: 10px; background: var(--accent-bg, #000);
|
||
color: var(--accent-text, #fff); border: none; border-radius: 6px;
|
||
cursor: pointer; font-size: 14px;">关闭</button>
|
||
`;
|
||
|
||
modal.appendChild(box);
|
||
document.body.appendChild(modal);
|
||
|
||
// 自动选中输入框
|
||
const input = box.querySelector('input');
|
||
input.select();
|
||
input.setSelectionRange(0, 999999);
|
||
|
||
// 关闭按钮
|
||
box.querySelector('button').onclick = () => {
|
||
document.body.removeChild(modal);
|
||
};
|
||
|
||
// 点击背景关闭
|
||
modal.onclick = (e) => {
|
||
if (e.target === modal) {
|
||
document.body.removeChild(modal);
|
||
}
|
||
};
|
||
}
|
||
|
||
// Initialize
|
||
// 页面加载完成后获取数据
|
||
window.addEventListener('load', () => {
|
||
console.log('Page loaded, starting loadData...');
|
||
loadData().catch(err => {
|
||
console.error('loadData failed:', err);
|
||
document.getElementById('loadingState').innerHTML =
|
||
`<div class="text-center text-red-500">
|
||
<p>初始化失败</p>
|
||
<p class="text-xs mt-2">${err.message}</p>
|
||
</div>`;
|
||
});
|
||
});
|
||
</script>
|
||
|
||
<!-- 文件名模板配置弹窗 -->
|
||
<div id="filenameModal" class="fixed inset-0 z-50 hidden">
|
||
<!-- 遮罩层 -->
|
||
<div class="absolute inset-0 bg-black/50 backdrop-blur-sm transition-opacity" onclick="closeFilenameModal()"></div>
|
||
|
||
<!-- 弹窗内容 -->
|
||
<div class="absolute inset-0 flex items-center justify-center p-4">
|
||
<div class="glass rounded-2xl w-full max-w-lg shadow-2xl transform transition-all scale-95 opacity-0"
|
||
id="modalContent">
|
||
<!-- 头部 -->
|
||
<div class="flex items-center justify-between p-6 border-b" style="border-color: var(--glass-border);">
|
||
<div>
|
||
<h3 class="text-lg font-semibold" style="color: var(--text-primary);">导出附件</h3>
|
||
<p class="text-xs mt-1" style="color: var(--text-muted);">自定义文件名格式</p>
|
||
</div>
|
||
<button onclick="closeFilenameModal()"
|
||
class="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors">
|
||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||
style="color: var(--text-muted);">
|
||
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
|
||
<!-- 主体 -->
|
||
<div class="p-6 space-y-6">
|
||
<!-- 预览区域 -->
|
||
<div class="rounded-xl p-4" style="background: var(--bg-primary);">
|
||
<div class="text-[10px] tracking-[0.2em] uppercase mb-2" style="color: var(--text-muted);">文件名预览</div>
|
||
<div class="font-mono text-sm break-all" style="color: var(--text-primary);" id="filenamePreview">
|
||
<span class="opacity-50">请选择字段...</span>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 已选字段(可拖拽排序,标签之间可输入分隔符) -->
|
||
<div>
|
||
<div class="flex items-center justify-between mb-3">
|
||
<span class="text-xs font-medium" style="color: var(--text-secondary);">已选字段(拖拽/箭头排序,标签之间输入分隔符)</span>
|
||
<button onclick="clearSelectedFields()" class="text-xs hover:opacity-70 transition-opacity"
|
||
style="color: var(--text-muted);">清空</button>
|
||
</div>
|
||
<div id="selectedFields"
|
||
class="flex flex-wrap items-center gap-1 min-h-[50px] p-3 rounded-xl border-2 border-dashed transition-colors"
|
||
style="border-color: var(--border-color); background: var(--bg-primary);">
|
||
<span class="text-sm italic" style="color: var(--text-muted);">暂无字段</span>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 可用字段 -->
|
||
<div>
|
||
<span class="text-xs font-medium block mb-3" style="color: var(--text-secondary);">可用字段</span>
|
||
<div class="grid grid-cols-2 gap-2" id="availableFields">
|
||
<!-- 动态生成 -->
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 底部按钮 -->
|
||
<div class="flex gap-3 p-6 pt-0">
|
||
<button onclick="closeFilenameModal()" class="flex-1 btn btn-secondary py-3 rounded-xl text-sm font-medium">
|
||
取消
|
||
</button>
|
||
<button onclick="confirmExport()" class="flex-1 btn btn-primary py-3 rounded-xl text-sm font-medium">
|
||
确认导出
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<style>
|
||
/* 弹窗动画 */
|
||
#filenameModal.show .glass {
|
||
transform: scale(1);
|
||
opacity: 1;
|
||
}
|
||
|
||
/* 分隔符输入框 */
|
||
.sep-input {
|
||
width: 40px;
|
||
height: 28px;
|
||
background: transparent;
|
||
border: none;
|
||
border-bottom: 2px solid var(--border-color);
|
||
text-align: center;
|
||
font-size: 14px;
|
||
color: var(--text-primary);
|
||
outline: none;
|
||
transition: border-color 0.2s;
|
||
padding: 0 4px;
|
||
}
|
||
|
||
.sep-input:focus {
|
||
border-color: var(--accent-bg);
|
||
}
|
||
|
||
.sep-input::placeholder {
|
||
color: var(--text-muted);
|
||
opacity: 0.5;
|
||
}
|
||
|
||
/* 字段标签样式 */
|
||
.field-tag {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
padding: 6px 12px;
|
||
border-radius: 8px;
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
cursor: move;
|
||
transition: all 0.2s;
|
||
user-select: none;
|
||
}
|
||
|
||
.field-tag.selected {
|
||
background: var(--accent-bg);
|
||
color: var(--accent-text);
|
||
}
|
||
|
||
.field-tag.available {
|
||
background: var(--bg-secondary);
|
||
color: var(--text-secondary);
|
||
border: 1px solid var(--border-color);
|
||
cursor: pointer;
|
||
}
|
||
|
||
.field-tag.available:hover {
|
||
border-color: var(--text-muted);
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.field-tag.dragging {
|
||
opacity: 0.5;
|
||
}
|
||
|
||
.field-tag .remove-btn {
|
||
width: 14px;
|
||
height: 14px;
|
||
border-radius: 50%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
background: rgba(255, 255, 255, 0.2);
|
||
cursor: pointer;
|
||
font-size: 10px;
|
||
}
|
||
|
||
.field-tag .remove-btn:hover {
|
||
background: rgba(255, 255, 255, 0.3);
|
||
}
|
||
/* 时间粒度选择器样式 */
|
||
.granularity-btn {
|
||
background: var(--bg-secondary);
|
||
color: var(--text-secondary);
|
||
border: 1px solid var(--border-color);
|
||
}
|
||
|
||
.granularity-btn:hover {
|
||
background: var(--bg-primary);
|
||
border-color: var(--text-muted);
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.granularity-btn.active {
|
||
background: var(--accent-bg);
|
||
color: var(--accent-text);
|
||
border-color: var(--accent-bg);
|
||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||
}
|
||
|
||
/* 图表区域标记样式 */
|
||
.date-marker-legend {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.date-marker-dot {
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 50%;
|
||
background: #facc15;
|
||
}
|
||
/* 时间范围选择器样式 */
|
||
.time-range-input {
|
||
background: var(--bg-secondary);
|
||
border: 1px solid var(--border-color);
|
||
border-radius: 6px;
|
||
padding: 4px 8px;
|
||
font-size: 12px;
|
||
color: var(--text-primary);
|
||
outline: none;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
.time-range-input:focus {
|
||
border-color: var(--accent-bg);
|
||
box-shadow: 0 0 0 2px rgba(128, 128, 128, 0.1);
|
||
}
|
||
|
||
.time-range-input::-webkit-calendar-picker-indicator {
|
||
filter: var(--calendar-icon-filter, invert(0.5));
|
||
cursor: pointer;
|
||
}
|
||
|
||
.dark .time-range-input::-webkit-calendar-picker-indicator {
|
||
filter: invert(0.7);
|
||
}
|
||
</style>
|
||
|
||
|
||
<!-- 表格预览全屏弹窗 -->
|
||
<div id="tablePreviewModal" class="fixed inset-0 z-[100] hidden">
|
||
<!-- 遮罩层 -->
|
||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm transition-opacity" onclick="closeTablePreview()"></div>
|
||
|
||
<!-- 弹窗内容 -->
|
||
<div class="absolute inset-4 md:inset-8 flex flex-col">
|
||
<div class="glass rounded-2xl shadow-2xl flex flex-col h-full overflow-hidden"
|
||
style="max-height: calc(100vh - 64px);">
|
||
<!-- 头部 -->
|
||
<div class="flex items-center justify-between p-6 border-b shrink-0" style="border-color: var(--glass-border);">
|
||
<div class="flex items-center gap-4">
|
||
<h3 class="text-xl font-semibold" style="color: var(--text-primary);">表格预览</h3>
|
||
<span class="text-sm" style="color: var(--text-muted);" id="previewRecordCount">共 0 条记录</span>
|
||
</div>
|
||
<div class="flex items-center gap-3">
|
||
<button onclick="downloadTableFromPreview()"
|
||
class="btn btn-primary px-5 py-2.5 rounded-xl text-sm font-medium flex items-center gap-2">
|
||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
||
<polyline points="7 10 12 15 17 10"></polyline>
|
||
<line x1="12" y1="15" x2="12" y2="3"></line>
|
||
</svg>
|
||
下载表格
|
||
</button>
|
||
<button onclick="closeTablePreview()"
|
||
class="p-2.5 rounded-xl hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors">
|
||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||
style="color: var(--text-muted);">
|
||
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 表格内容区域 -->
|
||
<div class="flex-1 overflow-auto" style="background: var(--bg-primary);">
|
||
<table class="w-full border-collapse" id="previewTable" style="table-layout: fixed;">
|
||
<colgroup id="previewTableColgroup">
|
||
<!-- 动态生成列宽 -->
|
||
</colgroup>
|
||
<thead class="sticky top-0 z-20" id="previewTableHead">
|
||
<!-- 动态生成表头 -->
|
||
</thead>
|
||
<tbody id="previewTableBody" class="text-sm">
|
||
<!-- 动态生成 -->
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<style>
|
||
/* 表格预览弹窗动画 */
|
||
#tablePreviewModal {
|
||
transition: opacity 0.3s ease;
|
||
}
|
||
|
||
#tablePreviewModal.hidden {
|
||
opacity: 0;
|
||
pointer-events: none;
|
||
}
|
||
|
||
#tablePreviewModal:not(.hidden) {
|
||
opacity: 1;
|
||
pointer-events: auto;
|
||
}
|
||
|
||
#tablePreviewModal .glass {
|
||
transform: scale(0.95);
|
||
transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1);
|
||
}
|
||
|
||
#tablePreviewModal:not(.hidden) .glass {
|
||
transform: scale(1);
|
||
}
|
||
|
||
/* 预览表格样式 */
|
||
#previewTable {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
table-layout: fixed;
|
||
}
|
||
|
||
#previewTable th,
|
||
#previewTable td {
|
||
padding: 12px 16px;
|
||
text-align: left;
|
||
vertical-align: middle;
|
||
border-bottom: 1px solid var(--glass-border);
|
||
}
|
||
|
||
/* 表头样式 */
|
||
#previewTable thead th {
|
||
position: sticky;
|
||
top: 0;
|
||
background: var(--bg-secondary);
|
||
backdrop-filter: blur(10px);
|
||
-webkit-backdrop-filter: blur(10px);
|
||
z-index: 20;
|
||
font-weight: 600;
|
||
font-size: 11px;
|
||
letter-spacing: 0.05em;
|
||
text-transform: uppercase;
|
||
color: var(--text-muted);
|
||
white-space: nowrap;
|
||
}
|
||
|
||
/* 表头中的固定列 */
|
||
#previewTable thead th.sticky-col-left {
|
||
z-index: 30;
|
||
background: var(--bg-secondary);
|
||
}
|
||
|
||
/* 左侧固定列 */
|
||
.sticky-col-left {
|
||
position: sticky;
|
||
left: 0;
|
||
background: var(--bg-primary);
|
||
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
|
||
z-index: 10;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.dark .sticky-col-left {
|
||
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
|
||
}
|
||
|
||
/* 表格行 */
|
||
#previewTable tbody tr {
|
||
transition: background-color 0.15s ease;
|
||
}
|
||
|
||
#previewTable tbody tr:nth-child(even) {
|
||
background: var(--bg-secondary);
|
||
}
|
||
|
||
#previewTable tbody tr:nth-child(even) .sticky-col-left {
|
||
background: var(--bg-secondary);
|
||
}
|
||
|
||
#previewTable tbody tr:hover {
|
||
background: var(--glass-hover) !important;
|
||
}
|
||
|
||
#previewTable tbody tr:hover .sticky-col-left {
|
||
background: var(--glass-hover) !important;
|
||
}
|
||
|
||
#previewTable tbody tr:last-child td {
|
||
border-bottom: none;
|
||
}
|
||
|
||
/* 可换行的内容单元格 */
|
||
#previewTable td.wrap-content {
|
||
white-space: normal;
|
||
word-wrap: break-word;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
/* 内容溢出显示省略号 */
|
||
#previewTable td {
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
/* 固定宽度列 */
|
||
.col-id {
|
||
width: 100px;
|
||
}
|
||
|
||
.col-name {
|
||
width: 100px;
|
||
}
|
||
|
||
.col-status {
|
||
width: 90px;
|
||
}
|
||
|
||
.col-time {
|
||
width: 140px;
|
||
}
|
||
|
||
/* 状态标签样式 */
|
||
.preview-status-badge {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
padding: 6px 12px;
|
||
border-radius: 20px;
|
||
font-size: 12px;
|
||
font-weight: 500;
|
||
}
|
||
|
||
.preview-status-badge.submitted {
|
||
background: var(--success-bg);
|
||
color: var(--success-text);
|
||
}
|
||
|
||
.preview-status-badge.pending {
|
||
background: var(--warning-bg);
|
||
color: var(--warning-text);
|
||
}
|
||
/* 时间粒度选择器样式 */
|
||
.granularity-btn {
|
||
background: var(--bg-secondary);
|
||
color: var(--text-secondary);
|
||
border: 1px solid var(--border-color);
|
||
}
|
||
|
||
.granularity-btn:hover {
|
||
background: var(--bg-primary);
|
||
border-color: var(--text-muted);
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.granularity-btn.active {
|
||
background: var(--accent-bg);
|
||
color: var(--accent-text);
|
||
border-color: var(--accent-bg);
|
||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||
}
|
||
|
||
/* 图表区域标记样式 */
|
||
.date-marker-legend {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.date-marker-dot {
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 50%;
|
||
background: #facc15;
|
||
}
|
||
/* 时间范围选择器样式 */
|
||
.time-range-input {
|
||
background: var(--bg-secondary);
|
||
border: 1px solid var(--border-color);
|
||
border-radius: 6px;
|
||
padding: 4px 8px;
|
||
font-size: 12px;
|
||
color: var(--text-primary);
|
||
outline: none;
|
||
transition: all 0.2s;
|
||
}
|
||
|
||
.time-range-input:focus {
|
||
border-color: var(--accent-bg);
|
||
box-shadow: 0 0 0 2px rgba(128, 128, 128, 0.1);
|
||
}
|
||
|
||
.time-range-input::-webkit-calendar-picker-indicator {
|
||
filter: var(--calendar-icon-filter, invert(0.5));
|
||
cursor: pointer;
|
||
}
|
||
|
||
.dark .time-range-input::-webkit-calendar-picker-indicator {
|
||
filter: invert(0.7);
|
||
}
|
||
</style>
|
||
|
||
<!-- 提交历史记录模态框 -->
|
||
<style>
|
||
#historyModal .glass {
|
||
transform: scale(0.95);
|
||
opacity: 0;
|
||
transition: transform 0.28s cubic-bezier(0.2, 0, 0, 1), opacity 0.28s ease;
|
||
}
|
||
#historyModal.show .glass {
|
||
transform: scale(1);
|
||
opacity: 1;
|
||
}
|
||
@media (max-width: 640px) {
|
||
#historyModal .glass {
|
||
border-radius: 20px 20px 0 0;
|
||
max-height: 90vh;
|
||
align-self: flex-end;
|
||
width: 100%;
|
||
}
|
||
}
|
||
.history-version {
|
||
border: 1px solid var(--glass-border);
|
||
border-radius: 14px;
|
||
padding: 16px;
|
||
background: var(--bg-primary);
|
||
}
|
||
.history-version + .history-version { margin-top: 14px; }
|
||
.history-file-row {
|
||
display: flex; align-items: center; gap: 10px;
|
||
padding: 8px 10px; border-radius: 10px;
|
||
background: var(--bg-secondary);
|
||
border: 1px solid var(--border-color);
|
||
}
|
||
.history-file-row + .history-file-row { margin-top: 8px; }
|
||
</style>
|
||
|
||
<div id="historyModal" class="fixed inset-0 z-50 hidden">
|
||
<div class="absolute inset-0 bg-black/50 backdrop-blur-sm transition-opacity" onclick="closeHistoryModal()"></div>
|
||
<div class="absolute inset-0 flex items-center justify-center p-4">
|
||
<div class="glass rounded-2xl w-full max-w-xl shadow-2xl" id="historyModalContent">
|
||
<!-- 头部 -->
|
||
<div class="flex items-center justify-between p-6 border-b" style="border-color: var(--glass-border);">
|
||
<div>
|
||
<h3 class="text-lg font-semibold" style="color: var(--text-primary);">提交记录</h3>
|
||
<p class="text-xs mt-1" style="color: var(--text-muted);" id="historyStudentLabel">-</p>
|
||
</div>
|
||
<button onclick="closeHistoryModal()"
|
||
class="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors">
|
||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
||
style="color: var(--text-muted);">
|
||
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
<!-- 版本列表 -->
|
||
<div class="p-6 overflow-y-auto" style="max-height: 68vh;" id="historyList"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
// 打开表格预览弹窗
|
||
function previewTable() {
|
||
if (!statusData || !statusData.students) {
|
||
showToast('暂无数据可预览', 'error');
|
||
return;
|
||
}
|
||
|
||
renderPreviewTable();
|
||
document.getElementById('tablePreviewModal').classList.remove('hidden');
|
||
document.body.style.overflow = 'hidden'; // 防止背景滚动
|
||
}
|
||
|
||
// 关闭表格预览弹窗
|
||
function closeTablePreview() {
|
||
document.getElementById('tablePreviewModal').classList.add('hidden');
|
||
document.body.style.overflow = ''; // 恢复背景滚动
|
||
}
|
||
|
||
// 动态表头配置(根据表单字段生成)
|
||
let previewColumns = [];
|
||
|
||
// 获取表单字段配置
|
||
async function getFormFields() {
|
||
try {
|
||
const response = await fetch(`/api/get_form/${formId}`);
|
||
if (response.ok) {
|
||
const formData = await response.json();
|
||
if (formData.fields && Array.isArray(formData.fields)) {
|
||
// 过滤掉文件字段和特殊字段,只保留文本类字段用于预览
|
||
return formData.fields.filter(f => f.type !== 'file' && f.type !== 'page_break' && f.name !== 'tail');
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error('获取表单字段失败:', e);
|
||
}
|
||
return [];
|
||
}
|
||
|
||
// 渲染预览表格
|
||
async function renderPreviewTable() {
|
||
const colgroup = document.getElementById('previewTableColgroup');
|
||
const thead = document.getElementById('previewTableHead');
|
||
const tbody = document.getElementById('previewTableBody');
|
||
const students = statusData.students;
|
||
|
||
// 更新记录数
|
||
document.getElementById('previewRecordCount').textContent = `共 ${students.length} 条记录`;
|
||
|
||
// 获取表单字段
|
||
const formFields = await getFormFields();
|
||
|
||
// 计算动态列宽度
|
||
const fixedWidth = 100 + 100 + 90 + 140; // 学号+姓名+状态+时间
|
||
const dynamicCount = formFields.length;
|
||
const dynamicWidth = dynamicCount > 0 ? `calc((100% - ${fixedWidth}px) / ${dynamicCount})` : 'auto';
|
||
|
||
// 生成colgroup(定义列宽)
|
||
let colgroupHTML = '';
|
||
colgroupHTML += '<col style="width: 100px;">'; // 学号
|
||
colgroupHTML += '<col style="width: 100px;">'; // 姓名
|
||
colgroupHTML += '<col style="width: 90px;">'; // 状态
|
||
formFields.forEach(() => {
|
||
colgroupHTML += `<col style="width: ${dynamicWidth};">`; // 动态字段
|
||
});
|
||
colgroupHTML += '<col style="width: 140px;">'; // 提交时间
|
||
colgroup.innerHTML = colgroupHTML;
|
||
|
||
// 构建表头
|
||
let headerHTML = '<tr>';
|
||
|
||
// 固定列 - 学号
|
||
headerHTML += `<th class="sticky-col-left" style="left: 0;">学号</th>`;
|
||
// 固定列 - 姓名
|
||
headerHTML += `<th class="sticky-col-left" style="left: 100px;">姓名</th>`;
|
||
|
||
// 其他列
|
||
headerHTML += '<th>状态</th>';
|
||
|
||
formFields.forEach(field => {
|
||
const label = field.placeholder || field.name;
|
||
headerHTML += `<th>${escapeHtml(label)}</th>`;
|
||
});
|
||
|
||
headerHTML += '<th>提交时间</th>';
|
||
headerHTML += '</tr>';
|
||
thead.innerHTML = headerHTML;
|
||
|
||
// 渲染表格内容
|
||
tbody.innerHTML = students.map((student, index) => {
|
||
const submitTime = student.submitTime ? formatDateTime(student.submitTime) : '-';
|
||
|
||
let rowHTML = '<tr>';
|
||
|
||
// 固定列 - 学号
|
||
rowHTML += `<td class="sticky-col-left font-mono text-xs" style="left: 0;">${escapeHtml(student.id)}</td>`;
|
||
|
||
// 固定列 - 姓名
|
||
rowHTML += `<td class="sticky-col-left font-medium" style="left: 100px;">${escapeHtml(student.name)}</td>`;
|
||
|
||
// 状态
|
||
rowHTML += `<td>${student.submitted
|
||
? `<span class="preview-status-badge submitted">
|
||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
||
<polyline points="20 6 9 17 4 12"></polyline>
|
||
</svg>
|
||
已提交
|
||
</span>`
|
||
: `<span class="preview-status-badge pending">
|
||
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5">
|
||
<circle cx="12" cy="12" r="10"></circle>
|
||
<line x1="12" y1="8" x2="12" y2="12"></line>
|
||
<line x1="12" y1="16" x2="12.01" y2="16"></line>
|
||
</svg>
|
||
未提交
|
||
</span>`
|
||
}</td>`;
|
||
|
||
// 动态表单字段值
|
||
formFields.forEach(field => {
|
||
const value = student.data && student.data[field.name] ? student.data[field.name] : '-';
|
||
const displayValue = value === '-' ? '<span style="opacity:0.4;">-</span>' : escapeHtml(value);
|
||
// 长内容自动换行
|
||
const cellClass = value.length > 20 ? 'wrap-content' : '';
|
||
rowHTML += `<td class="${cellClass}">${displayValue}</td>`;
|
||
});
|
||
|
||
// 提交时间
|
||
rowHTML += `<td>${submitTime}</td>`;
|
||
|
||
rowHTML += '</tr>';
|
||
return rowHTML;
|
||
}).join('');
|
||
}
|
||
|
||
// HTML转义函数
|
||
function escapeHtml(text) {
|
||
if (!text) return '';
|
||
const div = document.createElement('div');
|
||
div.textContent = text;
|
||
return div.innerHTML;
|
||
}
|
||
|
||
// 格式化日期时间
|
||
function formatDateTime(dateStr) {
|
||
if (!dateStr) return '-';
|
||
try {
|
||
const date = new Date(dateStr);
|
||
if (isNaN(date.getTime())) return dateStr;
|
||
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||
const day = String(date.getDate()).padStart(2, '0');
|
||
const hours = String(date.getHours()).padStart(2, '0');
|
||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||
|
||
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
||
} catch (e) {
|
||
return dateStr;
|
||
}
|
||
}
|
||
|
||
// 从预览弹窗下载表格
|
||
function downloadTableFromPreview() {
|
||
exportData('xlsx');
|
||
showToast('正在下载表格...', 'success');
|
||
}
|
||
|
||
// ===== 提交历史记录模态框 =====
|
||
let historyCtx = null; // { student, versions }
|
||
let formFieldsCache = null; // 表单字段配置(用于历史数据标签展示)
|
||
|
||
async function openHistoryModal(idx) {
|
||
if (!statusData || !statusData.students || !statusData.students[idx]) return;
|
||
const student = statusData.students[idx];
|
||
document.getElementById('historyStudentLabel').textContent =
|
||
student.anonymous ? student.name : `${student.name} · 学号尾号 ${student.tail}`;
|
||
|
||
const modal = document.getElementById('historyModal');
|
||
modal.classList.remove('hidden');
|
||
requestAnimationFrame(() => modal.classList.add('show'));
|
||
document.getElementById('historyList').innerHTML =
|
||
'<p class="text-sm text-center py-8" style="color: var(--text-muted);">加载中...</p>';
|
||
|
||
try {
|
||
if (!formFieldsCache) formFieldsCache = await getFormFields();
|
||
const resp = await fetch(`/api/admin/submission_history?formId=${encodeURIComponent(formId)}&studentId=${encodeURIComponent(student.id)}`);
|
||
const data = await resp.json();
|
||
historyCtx = { student, versions: data.versions || [] };
|
||
renderHistoryList();
|
||
} catch (e) {
|
||
document.getElementById('historyList').innerHTML =
|
||
'<p class="text-sm text-center py-8" style="color: var(--error-text);">加载失败,请刷新重试</p>';
|
||
}
|
||
}
|
||
|
||
function closeHistoryModal() {
|
||
const modal = document.getElementById('historyModal');
|
||
modal.classList.remove('show');
|
||
setTimeout(() => modal.classList.add('hidden'), 280);
|
||
historyCtx = null;
|
||
}
|
||
|
||
function renderHistoryList() {
|
||
const box = document.getElementById('historyList');
|
||
const versions = historyCtx ? historyCtx.versions : [];
|
||
if (!versions.length) {
|
||
box.innerHTML = '<p class="text-sm text-center py-8" style="color: var(--text-muted);">暂无历史记录</p>';
|
||
return;
|
||
}
|
||
|
||
// 由旧到新编号,便于"第N次提交"展示
|
||
const total = versions.length;
|
||
box.innerHTML = versions.map((v, i) => {
|
||
const seq = total - i; // 列表为倒序
|
||
const typeBadge = v.isLatest
|
||
? `<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium" style="background: var(--success-bg); color: var(--success-text);">当前版本</span>`
|
||
: `<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium" style="background: var(--bg-secondary); color: var(--text-muted); border: 1px solid var(--border-color);">历史版本</span>`;
|
||
const opBadge = v.isOverwrite ? '覆盖提交' : '首次提交';
|
||
|
||
const dataRows = (v.data && Object.keys(v.data).length)
|
||
? Object.entries(v.data).map(([k, val]) => {
|
||
const field = (typeof formFieldsCache !== 'undefined' && formFieldsCache) ? formFieldsCache.find(f => f.name === k) : null;
|
||
const label = (field && field.placeholder) || k;
|
||
return `<div class="flex gap-3 text-xs py-1">
|
||
<span class="shrink-0" style="color: var(--text-muted);">${escapeHtml(label)}</span>
|
||
<span class="break-all" style="color: var(--text-primary);">${escapeHtml(String(val ?? ''))}</span>
|
||
</div>`;
|
||
}).join('')
|
||
: '<p class="text-xs py-1" style="color: var(--text-muted);">(无表单数据)</p>';
|
||
|
||
const fileRows = (v.files && v.files.length)
|
||
? v.files.map(f => `
|
||
<div class="history-file-row">
|
||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" class="shrink-0" style="color: var(--text-muted);">
|
||
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/><polyline points="13 2 13 9 20 9"/>
|
||
</svg>
|
||
<span class="text-xs flex-1 break-all" style="color: var(--text-primary);">${escapeHtml(f.name)}</span>
|
||
${f.archived ? '<span class="text-[10px] px-1.5 py-0.5 rounded-full shrink-0" style="background: var(--bg-primary); color: var(--text-muted);">归档</span>' : ''}
|
||
<button onclick="downloadFile('${f.downloadUrl}')" class="text-[11px] px-2.5 py-1 rounded-lg border shrink-0 hover:opacity-80 transition-opacity" style="border-color: var(--border-color); color: var(--text-secondary);">下载</button>
|
||
</div>`).join('')
|
||
: '<p class="text-xs" style="color: var(--text-muted);">(无附件)</p>';
|
||
|
||
return `
|
||
<div class="history-version">
|
||
<div class="flex items-center flex-wrap gap-2">
|
||
<span class="text-sm font-semibold" style="color: var(--text-primary);">第 ${seq} 次</span>
|
||
<span class="text-[10px] px-2 py-0.5 rounded-full" style="background: var(--bg-secondary); color: var(--text-secondary); border: 1px solid var(--border-color);">${opBadge}</span>
|
||
${typeBadge}
|
||
<span class="text-[11px] ml-auto font-mono" style="color: var(--text-muted);">${escapeHtml(formatDateTime(v.submittedAt))}</span>
|
||
</div>
|
||
<div class="mt-3">${dataRows}</div>
|
||
<div class="mt-3">${fileRows}</div>
|
||
<div class="flex items-center flex-wrap gap-2 mt-4 pt-3 border-t" style="border-color: var(--glass-border);">
|
||
<span class="text-[10px] font-mono mr-auto" style="color: var(--text-muted);">IP ${escapeHtml(v.ip || '-')}</span>
|
||
<button onclick="exportHistoryExcel('${v.submittedAt}')" class="text-[11px] px-3 py-1.5 rounded-lg border hover:opacity-80 transition-opacity" style="border-color: var(--border-color); color: var(--text-secondary);">导出此版本 Excel</button>
|
||
<button onclick="exportHistoryZip('${v.submittedAt}')" class="text-[11px] px-3 py-1.5 rounded-lg border hover:opacity-80 transition-opacity" style="border-color: var(--border-color); color: var(--text-secondary);">导出此版本附件</button>
|
||
<button onclick="deleteHistoryVersion(${v.id})" class="text-[11px] px-3 py-1.5 rounded-lg transition-opacity hover:opacity-80" style="background: rgba(220,38,38,0.08); color: var(--error-text); border: 1px solid rgba(220,38,38,0.25);">删除此条</button>
|
||
</div>
|
||
</div>`;
|
||
}).join('');
|
||
}
|
||
|
||
async function refreshHistoryModal() {
|
||
if (!historyCtx) return;
|
||
const studentId = historyCtx.student.id;
|
||
await loadData(); // 刷新主列表(当前状态可能已变)
|
||
const idx = statusData.students.findIndex(s => s.id === studentId);
|
||
if (idx >= 0) await openHistoryModal(idx);
|
||
}
|
||
|
||
async function deleteHistoryVersion(versionId) {
|
||
const versions = historyCtx ? historyCtx.versions : [];
|
||
const target = versions.find(v => v.id === versionId);
|
||
const tip = (target && target.isLatest)
|
||
? '这是最新一条记录,删除将同时清除该学生的当前提交与全部现存文件,且不自动回滚。确定删除?'
|
||
: '删除该条历史记录及其归档附件?此操作不可恢复。';
|
||
if (!confirm(tip)) return;
|
||
|
||
try {
|
||
const resp = await fetch(`/api/admin/delete_submission_version/${versionId}`, { method: 'POST' });
|
||
const data = await resp.json();
|
||
if (data.success) {
|
||
showToast(data.deletedCurrent ? '已删除该记录及学生的当前提交' : '已删除该条历史记录', 'success');
|
||
await refreshHistoryModal();
|
||
} else {
|
||
showToast(data.message || '删除失败', 'error');
|
||
}
|
||
} catch (e) {
|
||
showToast('删除失败: ' + e.message, 'error');
|
||
}
|
||
}
|
||
|
||
function exportHistoryExcel(asOf) {
|
||
const url = `/api/export/${formId}?format=xlsx&asOf=${encodeURIComponent(asOf)}`;
|
||
const link = document.createElement('a');
|
||
link.href = url;
|
||
link.download = '';
|
||
link.style.display = 'none';
|
||
document.body.appendChild(link);
|
||
link.click();
|
||
setTimeout(() => { if (link.parentNode) document.body.removeChild(link); }, 100);
|
||
showToast('正在导出该时间点的Excel...', 'success');
|
||
}
|
||
|
||
async function exportHistoryZip(asOf) {
|
||
try {
|
||
showToast('正在按该时间点打包...', 'success');
|
||
const response = await fetch(`/api/create_zip/${formId}`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ asOf })
|
||
});
|
||
const data = await response.json();
|
||
if (data.success) {
|
||
const link = document.createElement('a');
|
||
link.href = data.download_url;
|
||
link.download = data.filename || 'export.zip';
|
||
link.style.display = 'none';
|
||
document.body.appendChild(link);
|
||
link.click();
|
||
setTimeout(() => { if (link.parentNode) document.body.removeChild(link); }, 100);
|
||
showToast('打包完成,开始下载', 'success');
|
||
} else {
|
||
showToast(data.error || '打包失败', 'error');
|
||
}
|
||
} catch (e) {
|
||
showToast('打包失败: ' + e.message, 'error');
|
||
}
|
||
}
|
||
|
||
// ESC键关闭弹窗
|
||
document.addEventListener('keydown', (e) => {
|
||
if (e.key === 'Escape') {
|
||
closeTablePreview();
|
||
closeFilenameModal();
|
||
closeHistoryModal();
|
||
}
|
||
});
|
||
</script>
|
||
|
||
</body>
|
||
|
||
</html>
|