453 lines
20 KiB
HTML
453 lines
20 KiB
HTML
{% extends "base_tailwind.html" %}
|
|
|
|
{% block title %}考试安排 - {{ brand_name }}{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<style>
|
|
@keyframes fadeSlideIn {
|
|
from { opacity: 0; transform: translateY(8px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
.row-animate {
|
|
animation: fadeSlideIn 0.3s ease both;
|
|
}
|
|
|
|
.exam-card {
|
|
transition: all 0.25s ease;
|
|
}
|
|
.exam-card:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 8px 25px rgba(0,0,0,0.08);
|
|
}
|
|
.dark .exam-card:hover {
|
|
box-shadow: 0 8px 25px rgba(0,0,0,0.4);
|
|
}
|
|
|
|
.status-badge {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.25rem;
|
|
padding: 0.125rem 0.75rem;
|
|
border-radius: 9999px;
|
|
font-size: 0.75rem;
|
|
font-weight: 600;
|
|
}
|
|
.status-upcoming {
|
|
background: #dbeafe;
|
|
color: #1d4ed8;
|
|
}
|
|
.status-ongoing {
|
|
background: #dcfce7;
|
|
color: #16a34a;
|
|
}
|
|
.status-past {
|
|
background: #f3f4f6;
|
|
color: #6b7280;
|
|
}
|
|
.dark .status-upcoming {
|
|
background: #1e3a5f;
|
|
color: #93c5fd;
|
|
}
|
|
.dark .status-ongoing {
|
|
background: #14532d;
|
|
color: #86efac;
|
|
}
|
|
.dark .status-past {
|
|
background: #374151;
|
|
color: #9ca3af;
|
|
}
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.fade-slide-in { animation: none !important; opacity: 1 !important; }
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div>
|
|
<!-- 页面标题 -->
|
|
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4 mb-6 list-item-enter" style="animation-delay: 0ms;">
|
|
<div>
|
|
<h2 class="text-2xl font-bold flex items-center gap-2">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"/>
|
|
<line x1="16" y1="2" x2="16" y2="6"/>
|
|
<line x1="8" y1="2" x2="8" y2="6"/>
|
|
<line x1="3" y1="10" x2="21" y2="10"/>
|
|
<line x1="8" y1="14" x2="8" y2="14.01"/>
|
|
<line x1="12" y1="14" x2="12" y2="14.01"/>
|
|
<line x1="16" y1="14" x2="16" y2="14.01"/>
|
|
<line x1="8" y1="18" x2="8" y2="18.01"/>
|
|
<line x1="12" y1="18" x2="12" y2="18.01"/>
|
|
<line x1="16" y1="18" x2="16" y2="18.01"/>
|
|
</svg>
|
|
考试安排
|
|
</h2>
|
|
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">查看本学期考试时间与地点</p>
|
|
</div>
|
|
<div class="flex flex-wrap gap-3 items-center">
|
|
<select id="semesterSelect"
|
|
class="px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm font-medium focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white">
|
|
<option value="">当前学期</option>
|
|
</select>
|
|
<button onclick="refreshExams()"
|
|
class="px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm font-medium hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors flex items-center gap-2">
|
|
<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">
|
|
<polyline points="23 4 23 10 17 10"/>
|
|
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>
|
|
</svg>
|
|
刷新
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 加载提示 -->
|
|
<div id="loadingIndicator" class="text-center py-12 list-item-enter" style="animation-delay: 100ms;">
|
|
<div class="w-10 h-10 border-2 border-black dark:border-white border-t-transparent rounded-full animate-spin mx-auto mb-4"></div>
|
|
<p class="text-gray-500 dark:text-gray-400">正在加载考试安排...</p>
|
|
</div>
|
|
|
|
<!-- 图表区 -->
|
|
<div id="chartsRow" class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6 hidden">
|
|
<div class="glass rounded-2xl p-4">
|
|
<h3 class="text-sm font-semibold text-gray-600 dark:text-gray-400 mb-3">考试日期分布</h3>
|
|
<div id="examDateChart" class="h-64"></div>
|
|
</div>
|
|
<div class="glass rounded-2xl p-4">
|
|
<h3 class="text-sm font-semibold text-gray-600 dark:text-gray-400 mb-3">考试形式分布</h3>
|
|
<div id="examTypeChart" class="h-64"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 错误提示 -->
|
|
<div id="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden list-item-enter" style="animation-delay: 100ms;">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none"
|
|
stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
|
|
class="mx-auto mb-4 text-red-500">
|
|
<circle cx="12" cy="12" r="10"/>
|
|
<line x1="15" y1="9" x2="9" y2="15"/>
|
|
<line x1="9" y1="9" x2="15" y2="15"/>
|
|
</svg>
|
|
<p id="errorText" class="text-gray-600 dark:text-gray-400"></p>
|
|
</div>
|
|
|
|
<!-- 考试卡片列表 -->
|
|
<div id="examsContainer" class="hidden list-item-enter grid grid-cols-1 lg:grid-cols-2 gap-4" style="animation-delay: 150ms;">
|
|
</div>
|
|
|
|
<!-- 空状态 -->
|
|
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden list-item-enter" style="animation-delay: 150ms;">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none"
|
|
stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"
|
|
class="mx-auto mb-4 text-gray-300 dark:text-gray-600">
|
|
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"/>
|
|
<line x1="16" y1="2" x2="16" y2="6"/>
|
|
<line x1="8" y1="2" x2="8" y2="6"/>
|
|
<line x1="3" y1="10" x2="21" y2="10"/>
|
|
</svg>
|
|
<p class="text-gray-500 dark:text-gray-400 text-lg">暂无考试安排</p>
|
|
<p class="text-gray-400 dark:text-gray-500 text-sm mt-1">可能尚未发布或已全部结束</p>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
|
|
<script>
|
|
let examDateChart = null;
|
|
let examTypeChart = null;
|
|
|
|
// ── 深色模式 ──
|
|
function isDarkMode() { return document.documentElement.classList.contains('dark'); }
|
|
|
|
// ── Session 健康检查 ──
|
|
async function initSession() {
|
|
try {
|
|
const res = await fetch('/api/jwxt/ping');
|
|
const data = await res.json();
|
|
if (!data.success) { console.warn('Session ping 失败:', data.message); return false; }
|
|
if (data.refreshed) console.log('🔄 Session 已自动刷新');
|
|
return true;
|
|
} catch (e) { console.error('Session ping 异常:', e); return false; }
|
|
}
|
|
|
|
async function loadSemesters() {
|
|
try {
|
|
const res = await fetch('/api/jwxt/semesters');
|
|
const data = await res.json();
|
|
if (data.success && data.semesters) {
|
|
const sel = document.getElementById('semesterSelect');
|
|
data.semesters.forEach(s => {
|
|
const opt = document.createElement('option');
|
|
opt.value = s.id;
|
|
opt.textContent = s.name || s.id;
|
|
sel.appendChild(opt);
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.error('加载学期列表失败:', e);
|
|
}
|
|
}
|
|
|
|
async function refreshExams() {
|
|
const loading = document.getElementById('loadingIndicator');
|
|
const error = document.getElementById('errorMessage');
|
|
const container = document.getElementById('examsContainer');
|
|
const empty = document.getElementById('emptyState');
|
|
|
|
loading.classList.remove('hidden');
|
|
error.classList.add('hidden');
|
|
container.classList.add('hidden');
|
|
empty.classList.add('hidden');
|
|
|
|
const semester = document.getElementById('semesterSelect').value;
|
|
|
|
try {
|
|
const res = await fetch('/api/jwxt/exams?' + new URLSearchParams({ semester }));
|
|
const data = await res.json();
|
|
|
|
loading.classList.add('hidden');
|
|
|
|
if (!data.success) {
|
|
showError(data.message || '查询失败');
|
|
return;
|
|
}
|
|
|
|
const exams = data.items || [];
|
|
|
|
if (exams.length === 0) {
|
|
empty.classList.remove('hidden');
|
|
return;
|
|
}
|
|
|
|
renderExams(exams);
|
|
container.classList.remove('hidden');
|
|
|
|
// 渲染图表
|
|
const chartsRow = document.getElementById('chartsRow');
|
|
chartsRow.classList.remove('hidden');
|
|
renderExamDateChart(exams);
|
|
renderExamTypeChart(exams);
|
|
setupDarkObserver(exams);
|
|
} catch (e) {
|
|
loading.classList.add('hidden');
|
|
showError('网络错误: ' + e.message);
|
|
}
|
|
}
|
|
|
|
// 正方系统 kssj 格式: "2026-07-09(10:30-12:10)" 或 "2026-07-09"
|
|
function parseKssj(kssj) {
|
|
const m = (kssj || '').match(/^(\d{4}-\d{2}-\d{2})(?:\((\d{2}:\d{2})-(\d{2}:\d{2})\))?$/);
|
|
if (m) return { date: m[1], startTime: m[2] || '', endTime: m[3] || '' };
|
|
const fallback = (kssj || '').match(/^(\d{4})[年-](\d{1,2})[月-](\d{1,2})/);
|
|
if (fallback) {
|
|
const y = fallback[1], mo = fallback[2].padStart(2,'0'), d = fallback[3].padStart(2,'0');
|
|
return { date: y + '-' + mo + '-' + d };
|
|
}
|
|
return { date: kssj || '--' };
|
|
}
|
|
|
|
function getExamStatus(kssj) {
|
|
const parsed = parseKssj(kssj);
|
|
const dateStr = parsed.date;
|
|
if (dateStr === '--') return { status: 'unknown', label: '未知', class: 'status-past' };
|
|
|
|
const d = new Date(dateStr + (parsed.startTime ? 'T' + parsed.startTime : ''));
|
|
const now = new Date();
|
|
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
const examDay = new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
|
|
if (examDay < today) return { status: 'past', label: '已结束', class: 'status-past' };
|
|
if (examDay > today) return { status: 'upcoming', label: '即将考试', class: 'status-upcoming' };
|
|
|
|
if (!parsed.startTime || !parsed.endTime) return { status: 'ongoing', label: '今日考试', class: 'status-ongoing' };
|
|
|
|
const toMin = s => { const p = s.split(':'); return parseInt(p[0])*60 + parseInt(p[1]); };
|
|
const nowMin = now.getHours() * 60 + now.getMinutes();
|
|
const startMin = toMin(parsed.startTime);
|
|
const endMin = toMin(parsed.endTime);
|
|
|
|
if (nowMin < startMin) return { status: 'upcoming', label: '即将考试', class: 'status-upcoming' };
|
|
if (nowMin > endMin) return { status: 'past', label: '已结束', class: 'status-past' };
|
|
return { status: 'ongoing', label: '正在考试', class: 'status-ongoing' };
|
|
}
|
|
|
|
function renderExams(exams) {
|
|
const container = document.getElementById('examsContainer');
|
|
container.innerHTML = '';
|
|
|
|
// 按考试时间排序
|
|
exams.sort((a, b) => {
|
|
const da = a.kssj || '';
|
|
const db = b.kssj || '';
|
|
return da.localeCompare(db);
|
|
});
|
|
|
|
exams.forEach((item, idx) => {
|
|
const courseName = item.kcmc || item.KCMC || item['课程名称'] || '未知课程';
|
|
const parsed = parseKssj(item.kssj);
|
|
const examDate = parsed.date;
|
|
const examTime = parsed.startTime && parsed.endTime ? `${parsed.startTime} ~ ${parsed.endTime}` : (item.kssj || '--');
|
|
const location = item.cdmc || item.KSDD || item['考试地点'] || '--';
|
|
const examType = item.khfs || item.ksxs || item.KSXS || item['考试形式'] || '--';
|
|
const campus = item.cdxqmc || item.xqmc || item.XQMC || '--';
|
|
const teacher = item.jsxx || '--';
|
|
|
|
const status = getExamStatus(item.kssj);
|
|
const delay = idx * 60;
|
|
|
|
const card = document.createElement('div');
|
|
card.className = 'exam-card glass rounded-2xl p-5 row-animate';
|
|
card.style.animationDelay = delay + 'ms';
|
|
card.innerHTML = `
|
|
<div class="flex flex-col sm:flex-row sm:items-start justify-between gap-3">
|
|
<!-- 左侧信息 -->
|
|
<div class="flex-1 min-w-0">
|
|
<div class="flex items-start gap-3 mb-3">
|
|
<div class="w-10 h-10 rounded-xl bg-gray-100 dark:bg-gray-800 flex items-center justify-center flex-shrink-0">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
|
|
stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
|
|
class="text-gray-600 dark:text-gray-400">
|
|
<path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"/>
|
|
<path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"/>
|
|
</svg>
|
|
</div>
|
|
<div class="min-w-0">
|
|
<h3 class="text-base font-semibold truncate">${courseName}</h3>
|
|
<div class="flex flex-wrap gap-x-4 gap-y-1 mt-1 text-xs text-gray-500 dark:text-gray-400">
|
|
<span>${examType}</span>
|
|
<span>${campus}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-2 sm:grid-cols-4 gap-3">
|
|
<div>
|
|
<div class="text-xs text-gray-400 dark:text-gray-500 mb-0.5">考试日期</div>
|
|
<div class="text-sm font-medium">${examDate}</div>
|
|
</div>
|
|
<div>
|
|
<div class="text-xs text-gray-400 dark:text-gray-500 mb-0.5">考试时间</div>
|
|
<div class="text-sm font-medium">${examTime}</div>
|
|
</div>
|
|
<div>
|
|
<div class="text-xs text-gray-400 dark:text-gray-500 mb-0.5">考试地点</div>
|
|
<div class="text-sm font-medium">${location}</div>
|
|
</div>
|
|
<div>
|
|
<div class="text-xs text-gray-400 dark:text-gray-500 mb-0.5">任课教师</div>
|
|
<div class="text-sm font-medium">${teacher}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 右侧状态 -->
|
|
<div class="flex-shrink-0">
|
|
<span class="status-badge ${status.class}">${status.label}</span>
|
|
</div>
|
|
</div>
|
|
`;
|
|
container.appendChild(card);
|
|
});
|
|
}
|
|
|
|
function showError(msg) {
|
|
const error = document.getElementById('errorMessage');
|
|
document.getElementById('errorText').textContent = msg;
|
|
error.classList.remove('hidden');
|
|
}
|
|
|
|
// ── 考试日期分布柱状图 ──
|
|
function renderExamDateChart(exams) {
|
|
const container = document.getElementById('examDateChart');
|
|
if (!container) return;
|
|
if (!examDateChart) examDateChart = echarts.init(container);
|
|
|
|
const dateCount = {};
|
|
exams.forEach(item => {
|
|
const parsed = parseKssj(item.kssj);
|
|
const date = parsed.date || '';
|
|
if (date) dateCount[date] = (dateCount[date] || 0) + 1;
|
|
});
|
|
const dates = Object.keys(dateCount).sort();
|
|
|
|
const dark = isDarkMode();
|
|
examDateChart.setOption({
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', data: dates, axisLabel: { fontSize: 10, rotate: 30 } },
|
|
yAxis: { type: 'value', name: '场次', minInterval: 1, nameTextStyle: { fontSize: 11 } },
|
|
series: [{
|
|
type: 'bar', data: dates.map(d => dateCount[d]),
|
|
itemStyle: {
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
{ offset: 0, color: dark ? '#fbbf24' : '#f59e0b' },
|
|
{ offset: 1, color: dark ? '#d97706' : '#b45309' }
|
|
])
|
|
},
|
|
barMaxWidth: 36,
|
|
label: { show: true, position: 'top', fontSize: 11, color: dark ? '#9ca3af' : '#6b7280' }
|
|
}]
|
|
}, true);
|
|
}
|
|
|
|
// ── 考试形式饼图 ──
|
|
function renderExamTypeChart(exams) {
|
|
const container = document.getElementById('examTypeChart');
|
|
if (!container) return;
|
|
if (!examTypeChart) examTypeChart = echarts.init(container);
|
|
|
|
const typeCount = {};
|
|
exams.forEach(item => {
|
|
const type = item.khfs || item.ksxs || item.KSXS || item['考试形式'] || '其他';
|
|
typeCount[type] = (typeCount[type] || 0) + 1;
|
|
});
|
|
const entries = Object.entries(typeCount).sort((a, b) => b[1] - a[1]);
|
|
const dark = isDarkMode();
|
|
const colors = dark
|
|
? ['#60a5fa', '#34d399', '#fbbf24', '#f87171', '#a78bfa', '#f472b6']
|
|
: ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899'];
|
|
|
|
examTypeChart.setOption({
|
|
tooltip: { trigger: 'item', formatter: '{b}: {c} 场 ({d}%)' },
|
|
series: [{
|
|
type: 'pie', radius: ['40%', '70%'], center: ['50%', '50%'],
|
|
itemStyle: { borderRadius: 4, borderColor: dark ? '#1f2937' : '#fff', borderWidth: 2 },
|
|
label: { fontSize: 11, color: dark ? '#d1d5db' : '#374151' },
|
|
data: entries.map(([name, value], i) => ({ name, value, itemStyle: { color: colors[i % colors.length] } }))
|
|
}]
|
|
}, true);
|
|
}
|
|
|
|
// ── 深色模式观察者 ──
|
|
let _darkObserver = null;
|
|
function setupDarkObserver(exams) {
|
|
if (_darkObserver) return;
|
|
_darkObserver = new MutationObserver(() => {
|
|
if (exams.length > 0) {
|
|
renderExamDateChart(exams);
|
|
renderExamTypeChart(exams);
|
|
}
|
|
});
|
|
_darkObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
|
}
|
|
|
|
window.addEventListener('resize', () => {
|
|
examDateChart?.resize();
|
|
examTypeChart?.resize();
|
|
});
|
|
|
|
// 学期切换自动刷新
|
|
document.getElementById('semesterSelect').addEventListener('change', refreshExams);
|
|
|
|
// 初始化:先检查 session,再加载数据
|
|
initSession().then(sessionOk => {
|
|
if (!sessionOk) {
|
|
showError('教务系统 Session 已失效,请尝试<a href="/dashboard" class="underline">重新配置教务账号</a>');
|
|
return;
|
|
}
|
|
loadSemesters().then(() => refreshExams());
|
|
});
|
|
</script>
|
|
{% endblock %}
|