初版:教务抢课系统 jwxt(从线上实例导出)

This commit is contained in:
deploy
2026-10-29 12:54:56 +08:00
commit 4adf153426
106 changed files with 50288 additions and 0 deletions
+487
View File
@@ -0,0 +1,487 @@
{% extends "base_tailwind.html" %}
{% block title %}学业情况 - {{ brand_name }}{% endblock %}
{% block extra_css %}
<style>
@keyframes fadeSlideIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
.row-animate { animation: fadeSlideIn 0.35s ease both; }
/* 树节点 */
.tree-node { transition: all 0.15s ease; }
.tree-node:hover { background: rgba(0,0,0,0.02); }
.dark .tree-node:hover { background: rgba(255,255,255,0.03); }
.tree-toggle { cursor: pointer; user-select: none; }
.tree-children { overflow: hidden; transition: max-height 0.3s ease; }
.tree-children.collapsed { max-height: 0 !important; }
.depth-0 { border-left: 3px solid #22c55e; }
.depth-1 { border-left: 2px solid #818cf8; }
.depth-2 { border-left: 2px solid #94a3b8; }
.depth-3 { border-left: 1px solid #cbd5e1; }
.dark .depth-3 { border-left-color: #475569; }
/* 进度条 */
.progress-track { height: 5px; border-radius: 3px; background: #e5e7eb; overflow: hidden; }
.dark .progress-track { background: #374151; }
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.5s ease; }
.progress-fill.ok { background: #22c55e; }
.progress-fill.warn { background: #f59e0b; }
.progress-fill.danger { background: #ef4444; }
/* 课程表 */
.course-row { transition: background 0.15s; }
.course-row:hover { background: rgba(0,0,0,0.02); }
.dark .course-row:hover { background: rgba(255,255,255,0.03); }
.badge-pass { background: #dcfce7; color: #15803d; }
.badge-fail { background: #fef3c7; color: #92400e; }
.badge-progress { background: #dbeafe; color: #1d4ed8; }
.dark .badge-pass { background: #14532d; color: #86efac; }
.dark .badge-fail { background: #451a03; color: #fcd34d; }
.dark .badge-progress { background: #1e3a5f; color: #93c5fd; }
/* 统计卡片 */
.stat-card {
background: linear-gradient(135deg, rgba(79,70,229,0.04), rgba(99,102,241,0.01));
border: 1px solid rgba(99,102,241,0.1);
}
.dark .stat-card {
background: linear-gradient(135deg, rgba(129,140,248,0.08), rgba(165,180,252,0.02));
border-color: rgba(129,140,248,0.15);
}
</style>
{% endblock %}
{% block content %}
<div>
<!-- 标题区 -->
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4 mb-5">
<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">
<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>
</svg>
学业情况
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-0.5">培养方案完成度分析</p>
</div>
<div class="flex items-center gap-2">
<button onclick="toggleAll(true)"
class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-xs hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
全部展开
</button>
<button onclick="toggleAll(false)"
class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-xs hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
全部收起
</button>
<button onclick="refresh()"
class="px-4 py-1.5 rounded-lg bg-indigo-600 text-white text-xs font-medium hover:bg-indigo-700 transition-colors flex items-center gap-1.5">
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></svg>
刷新
</button>
</div>
</div>
<!-- 摘要卡片 -->
<div id="summaryCards" class="hidden grid grid-cols-2 md:grid-cols-5 gap-3 mb-5 row-animate">
<div class="stat-card rounded-xl p-3.5">
<p class="text-xs text-gray-500 dark:text-gray-400">学生姓名</p>
<p id="summaryName" class="font-semibold text-base mt-0.5">--</p>
</div>
<div class="stat-card rounded-xl p-3.5">
<p class="text-xs text-gray-500 dark:text-gray-400">GPA</p>
<p id="summaryGpa" class="font-bold text-xl text-indigo-600 dark:text-indigo-400 mt-0.5">--</p>
</div>
<div class="stat-card rounded-xl p-3.5">
<p class="text-xs text-gray-500 dark:text-gray-400">已获 / 要求</p>
<p id="summaryCredits" class="font-semibold text-base mt-0.5">--</p>
</div>
<div class="stat-card rounded-xl p-3.5">
<p class="text-xs text-gray-500 dark:text-gray-400">课程进度</p>
<p id="summaryCourses" class="font-semibold text-base mt-0.5">--</p>
</div>
<div class="stat-card rounded-xl p-3.5">
<p class="text-xs text-gray-500 dark:text-gray-400">统计时间</p>
<p id="summaryTime" class="text-xs text-gray-400 dark:text-gray-500 mt-0.5">--</p>
</div>
</div>
<!-- 图表 -->
<div id="chartsRow" class="hidden grid grid-cols-1 md:grid-cols-2 gap-4 mb-5 row-animate">
<div class="glass rounded-2xl p-4">
<h4 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">整体完成度</h4>
<div id="gaugeChart" style="height: 240px; width: 100%;"></div>
</div>
<div class="glass rounded-2xl p-4">
<h4 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">各类别学分</h4>
<div id="levelChart" style="height: 240px;"></div>
</div>
</div>
<!-- 加载 -->
<div id="loadingIndicator" class="text-center py-16">
<div class="w-9 h-9 border-2 border-indigo-500 border-t-transparent rounded-full animate-spin mx-auto mb-4"></div>
<p class="text-gray-400 dark:text-gray-500 text-sm">正在查询学业情况,数据较多请稍候…</p>
</div>
<!-- 错误 -->
<div id="errorMessage" class="glass rounded-2xl p-5 mb-4 text-center hidden">
<p id="errorText" class="text-red-500 text-sm"></p>
</div>
<!-- 树形结构 -->
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden divide-y divide-gray-100 dark:divide-gray-800">
<div id="treeRoot"></div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden">
<p class="text-gray-400 dark:text-gray-500">暂无学业情况数据</p>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
async function initSession() {
try { await fetch('/api/jwxt/ping'); return true; }
catch(e) { console.warn('[Session] ping fail:', e); return false; }
}
function isDark() { return document.documentElement.classList.contains('dark'); }
let _expandedAll = true;
// ── 渲染树节点 ──────────────────────────────────────────────────
function renderNode(node, depth) {
const hasChildren = node.children && node.children.length > 0;
const earned = node.earned_credits || 0;
const required = node.required_credits || 0;
const missing = Math.max(0, required - earned);
const passed = node.passed;
const pct = required > 0 ? Math.min(100, Math.round((earned / required) * 100)) : (passed ? 100 : 0);
const progressClass = pct >= 100 ? 'ok' : (pct >= 60 ? 'warn' : 'danger');
const nodeId = node.id;
const childrenId = 'children-' + nodeId;
const coursePanelId = 'courses-' + nodeId;
// 深度样式
const textClass = depth === 0 ? 'text-base font-bold' : depth === 1 ? 'text-sm font-semibold' : 'text-sm';
const indent = Math.min(depth, 3);
const chevronHtml = hasChildren ? `
<svg class="tree-chevron w-4 h-4 flex-shrink-0 text-gray-400 transition-transform duration-200"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="6 9 12 15 18 9"/>
</svg>` : '<span class="w-4 flex-shrink-0"></span>';
// 状态徽章
let badgeHtml = '';
if (required > 0) {
if (pct >= 100) badgeHtml = '<span class="px-2 py-0.5 rounded-full text-xs font-medium badge-pass flex-shrink-0">已完成</span>';
else if (earned > 0) badgeHtml = '<span class="px-2 py-0.5 rounded-full text-xs font-medium badge-progress flex-shrink-0">进行中</span>';
else badgeHtml = '<span class="px-2 py-0.5 rounded-full text-xs font-medium badge-fail flex-shrink-0">未开始</span>';
}
// 学分文字:要求学分:X 获得学分:Y 未获得学分:Z
const creditText = required > 0
? `要求学分:${required.toFixed(1)} 获得学分:${earned.toFixed(1)} 未获得学分:${missing.toFixed(1)}`
: (earned > 0 ? `获得学分:${earned.toFixed(1)}` : '');
// 进度条
const progressHtml = required > 0 ? `
<div class="flex items-center gap-2 flex-shrink-0" style="min-width:90px">
<div class="progress-track flex-1"><div class="progress-fill ${progressClass}" style="width:${pct}%"></div></div>
<span class="text-xs text-gray-400 dark:text-gray-500 w-9 text-right">${pct}%</span>
</div>` : '';
// 课程展开按钮
const expandBtnHtml = `
<button onclick="loadCourses('${nodeId}', '${coursePanelId}', this)"
class="flex-shrink-0 text-xs text-indigo-500 dark:text-indigo-400 hover:text-indigo-700 dark:hover:text-indigo-300 font-medium flex items-center gap-1 px-2 py-0.5 rounded hover:bg-indigo-50 dark:hover:bg-indigo-900/20 transition-colors"
title="查看课程明细">
<span class="course-count-${nodeId}">课程</span>
<svg class="course-chevron-${nodeId} w-3 h-3 transition-transform" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>
</button>`;
const clickHandler = hasChildren ? `onclick="toggleNode('${childrenId}', this)"` : '';
const toggleClass = hasChildren ? 'tree-toggle' : '';
const html = `
<div class="tree-node depth-${depth}">
<div class="${toggleClass} flex items-center gap-2 py-2.5 px-4" style="padding-left:${0.75 + indent * 1.25}rem" ${clickHandler}>
${chevronHtml}
<div class="flex-1 min-w-0">
<span class="${textClass}">${escHtml(node.name)}</span>
${creditText ? `<span class="text-xs text-gray-400 dark:text-gray-500 ml-2">${creditText}</span>` : ''}
</div>
${progressHtml}
${badgeHtml}
${!hasChildren ? expandBtnHtml : ''}
</div>
<div id="${coursePanelId}" class="hidden px-4 pb-3" style="padding-left:${2 + indent * 1.25}rem"></div>
${hasChildren ? `<div id="${childrenId}" class="tree-children" style="max-height:10000px">${node.children.map(c => renderNode(c, depth + 1)).join('')}</div>` : ''}
</div>`;
return html;
}
function escHtml(s) { return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
// ── 展开/收起子节点 ────────────────────────────────────────────
function toggleNode(childrenId, el) {
const container = document.getElementById(childrenId);
if (!container) return;
const chevron = el.querySelector('.tree-chevron');
if (container.classList.contains('collapsed')) {
container.classList.remove('collapsed');
container.style.maxHeight = '10000px';
if (chevron) chevron.style.transform = 'rotate(0deg)';
} else {
container.classList.add('collapsed');
container.style.maxHeight = '0px';
if (chevron) chevron.style.transform = 'rotate(-90deg)';
}
}
function toggleAll(expand) {
_expandedAll = expand;
document.querySelectorAll('.tree-children').forEach(el => {
if (expand) { el.classList.remove('collapsed'); el.style.maxHeight = '10000px'; }
else { el.classList.add('collapsed'); el.style.maxHeight = '0px'; }
});
document.querySelectorAll('.tree-chevron').forEach(el => {
el.style.transform = expand ? 'rotate(0deg)' : 'rotate(-90deg)';
});
}
// ── 加载课程明细 ──────────────────────────────────────────────
async function loadCourses(nodeId, panelId, btn) {
const panel = document.getElementById(panelId);
if (!panel) return;
const chevron = btn.querySelector('svg');
// 已展开则收起
if (!panel.classList.contains('hidden') && panel.innerHTML) {
panel.classList.add('hidden');
if (chevron) chevron.style.transform = 'rotate(0deg)';
return;
}
// 已加载过则展示
if (panel.innerHTML) {
panel.classList.remove('hidden');
if (chevron) chevron.style.transform = 'rotate(180deg)';
return;
}
// 显示加载
panel.innerHTML = '<div class="text-xs text-gray-400 py-2">加载中…</div>';
panel.classList.remove('hidden');
if (chevron) chevron.style.transform = 'rotate(180deg)';
try {
const res = await fetch(`/api/jwxt/academic-status/courses?xfyqjd_id=${encodeURIComponent(nodeId)}`);
const data = await res.json();
if (!data.success) {
panel.innerHTML = `<div class="text-xs text-red-400 py-2">${escHtml(data.message || '加载失败')}</div>`;
return;
}
// 更新按钮计数
const countEl = document.querySelector(`.course-count-${nodeId}`);
if (countEl) countEl.textContent = `共 ${data.total} 门 通过 ${data.passed} 门`;
if (!data.courses || !data.courses.length) {
if (countEl) countEl.textContent = '共 0 门';
panel.innerHTML = '<div class="text-xs text-gray-400 py-1">该节点暂无课程</div>';
setTimeout(() => { panel.classList.add('hidden'); if (chevron) chevron.style.transform = 'rotate(0deg)'; }, 1200);
return;
}
// 排序:已修(有成绩)在前,在修次之,未修最后
const sorted = [...data.courses].sort((a, b) => {
const aScore = a.cj && a.cj !== '未开放' ? 0 : a.kczt === 1 ? 1 : 2;
const bScore = b.cj && b.cj !== '未开放' ? 0 : b.kczt === 1 ? 1 : 2;
return aScore - bScore;
});
// 渲染课程表
const rows = sorted.map((c, i) => {
const grade = c.cj || (c.kczt === 1 ? '在修' : '未修');
const gpa = c.jd != null ? c.jd : '--';
const statusCls = c.cj && c.cj !== '未开放' ? 'badge-pass' : c.kczt === 1 ? 'badge-progress' : 'badge-fail';
return `
<tr class="course-row" style="animation: fadeSlideIn ${0.1 + i * 0.02}s ease both">
<td class="py-1.5 pr-4 text-xs text-gray-500 w-6">${i + 1}</td>
<td class="py-1.5 pr-4 text-sm truncate max-w-[200px]" title="${escHtml(c.kcmc)}">${escHtml(c.kcmc)}</td>
<td class="py-1.5 pr-4 text-xs text-gray-400 w-10 text-right">${c.xf || '--'}</td>
<td class="py-1.5 pr-4 text-xs font-medium w-12 text-right">${escHtml(String(grade))}</td>
<td class="py-1.5 pr-4 text-xs text-gray-500 w-10 text-right">${gpa}</td>
<td class="py-1.5 pr-4 text-xs text-gray-400 whitespace-nowrap">${c.xnmc || ''} ${c.xqmmc || ''}</td>
<td class="py-1.5 pr-4 text-xs text-gray-400 truncate max-w-[100px]">${escHtml(c.kcxz || '')}</td>
<td class="py-1.5 text-xs"><span class="px-1.5 py-0.5 rounded text-xs ${statusCls}">${c.cj && c.cj !== '未开放' ? '已修' : c.kczt === 1 ? '在修' : '未修'}</span></td>
</tr>`;
}).join('');
panel.innerHTML = `
<div class="border-t border-gray-100 dark:border-gray-800 mt-1 pt-2">
<div class="text-xs text-gray-400 mb-2">共 ${data.total} 门,通过 ${data.passed} 门</div>
<div class="overflow-x-auto -mx-2">
<table class="w-full text-left">
<thead>
<tr class="text-xs text-gray-400 dark:text-gray-500 border-b border-gray-100 dark:border-gray-800">
<th class="py-1.5 pr-4 font-normal w-6">#</th>
<th class="py-1.5 pr-4 font-normal">课程名称</th>
<th class="py-1.5 pr-4 font-normal w-10 text-right">学分</th>
<th class="py-1.5 pr-4 font-normal w-12 text-right">成绩</th>
<th class="py-1.5 pr-4 font-normal w-10 text-right">绩点</th>
<th class="py-1.5 pr-4 font-normal whitespace-nowrap">学期</th>
<th class="py-1.5 pr-4 font-normal">类别</th>
<th class="py-1.5 font-normal w-12">状态</th>
</tr>
</thead>
<tbody>${rows}</tbody>
</table>
</div>
</div>`;
} catch (e) {
panel.innerHTML = `<div class="text-xs text-red-400 py-2">网络错误: ${escHtml(e.message)}</div>`;
}
}
// ── ECharts ──────────────────────────────────────────────────
let gaugeChart = null, levelChart = null;
function renderGaugeChart(pct) {
const dom = document.getElementById('gaugeChart');
if (!dom) return;
const dark = isDark();
if (!gaugeChart) gaugeChart = echarts.init(dom);
gaugeChart.setOption({
series: [{
type: 'gauge', startAngle: 200, endAngle: -20, center: ['50%', '60%'], radius: '85%',
min: 0, max: 100,
axisLine: { lineStyle: { width: 14, color: [[0.55, '#ef4444'], [0.8, '#f59e0b'], [1, '#22c55e']] }},
pointer: { length: '60%', width: 5, itemStyle: { color: dark ? '#d1d5db' : '#374151' } },
axisTick: { show: false }, splitLine: { show: false },
axisLabel: { color: dark ? '#9ca3af' : '#6b7280', fontSize: 10, distance: -25 },
detail: { valueAnimation: true, fontSize: 26, fontWeight: 'bold', color: dark ? '#f9fafb' : '#111827', formatter: '{value}%', offsetCenter: [0, '62%'] },
data: [{ value: pct }]
}]
}, { notMerge: true });
gaugeChart.resize();
}
function renderLevelChart(tree) {
const dom = document.getElementById('levelChart');
if (!dom) return;
const dark = isDark();
const categories = tree.map(root => ({
name: root.name, earned: root.earned_credits || 0, required: root.required_credits || 0,
}));
if (!categories.length) return;
const names = categories.map(c => c.name);
if (!levelChart) levelChart = echarts.init(dom);
levelChart.setOption({
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: p => {
const c = categories[p[0].dataIndex];
return `${c.name}<br/>已获: ${c.earned} / 要求: ${c.required}`;
}},
grid: { left: '3%', right: '5%', top: 8, bottom: 8, containLabel: true },
xAxis: { type: 'value', name: '学分', nameTextStyle: { color: dark ? '#9ca3af' : '#6b7280', fontSize: 10 }, axisLabel: { color: dark ? '#9ca3af' : '#6b7280', fontSize: 10 } },
yAxis: { type: 'category', data: names, axisLabel: { color: dark ? '#9ca3af' : '#6b7280', fontSize: 10, width: 70, overflow: 'truncate' }, inverse: true },
series: [
{ name: '要求', type: 'bar', data: categories.map(c => c.required), itemStyle: { color: dark ? '#374151' : '#e5e7eb', borderRadius: [0,5,5,0] }, barGap: '-100%', z: 1 },
{ name: '已获', type: 'bar', data: categories.map(c => c.earned), itemStyle: { color: dark ? '#818cf8' : '#4f46e5', borderRadius: [0,5,5,0] }, z: 2 },
]
}, { notMerge: true });
levelChart.resize();
}
function renderCharts(tree, rootCredits) {
document.getElementById('chartsRow').classList.remove('hidden');
const pct = rootCredits.required > 0 ? Math.min(100, Math.round((rootCredits.earned / rootCredits.required) * 100)) : 0;
renderGaugeChart(pct);
renderLevelChart(tree);
}
function setupDarkObserver() {
new MutationObserver(() => {
if (gaugeChart) { gaugeChart.dispose(); gaugeChart = null; }
if (levelChart) { levelChart.dispose(); levelChart = null; }
const tree = window._lastTree, c = window._lastCredits;
if (tree && tree.length) renderCharts(tree, c);
}).observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
window.addEventListener('resize', () => { if (gaugeChart) gaugeChart.resize(); if (levelChart) levelChart.resize(); });
// ── 数据加载 ──────────────────────────────────────────────────
async function refresh() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('summaryCards').classList.add('hidden');
document.getElementById('chartsRow').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/academic-status');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) {
document.getElementById('errorText').textContent = data.message || '查询失败';
document.getElementById('errorMessage').classList.remove('hidden');
return;
}
const tree = data.tree || [];
if (!tree.length) {
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('emptyState').classList.remove('hidden');
return;
}
// 摘要
document.getElementById('summaryName').textContent = data.student_name || '--';
document.getElementById('summaryGpa').textContent = data.gpa || '--';
document.getElementById('summaryTime').textContent = data.stat_time || '--';
const root = tree[0];
let rootCredits = { earned: 0, required: 0 };
if (root) {
rootCredits = { earned: root.earned_credits || 0, required: root.required_credits || 0 };
document.getElementById('summaryCredits').textContent = `${rootCredits.earned} / ${rootCredits.required}`;
const pct = rootCredits.required > 0 ? Math.round((rootCredits.earned / rootCredits.required) * 100) : 0;
document.getElementById('summaryCourses').textContent = `${pct}%`;
}
document.getElementById('summaryCards').classList.remove('hidden');
// 渲染树
document.getElementById('treeRoot').innerHTML = tree.map(n => renderNode(n, 0)).join('');
document.getElementById('emptyState').classList.add('hidden');
document.getElementById('dataContainer').classList.remove('hidden');
window._lastTree = tree;
window._lastCredits = rootCredits;
renderCharts(tree, rootCredits);
} catch (e) {
document.getElementById('loadingIndicator').classList.add('hidden');
document.getElementById('errorText').textContent = '网络错误: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
initSession().then(() => { setupDarkObserver(); refresh(); });
</script>
{% endblock %}
+467
View File
@@ -0,0 +1,467 @@
{% 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; }
.category-panel {
transition: all 0.2s ease;
}
.category-panel .toggle-icon {
transition: transform 0.2s ease;
}
.category-panel.open .toggle-icon {
transform: rotate(90deg);
}
.course-table {
transition: max-height 0.3s ease;
overflow: hidden;
}
.course-table.collapsed {
max-height: 0 !important;
}
.course-table.expanded {
max-height: 2000px;
}
</style>
{% endblock %}
{% block content %}
<div>
<!-- Header -->
<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">
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/>
<line x1="12" y1="9" x2="12" y2="13"/>
<line x1="12" y1="17" x2="12.01" y2="17"/>
</svg>
学业预警查询
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">按教学计划分类展示修读情况与学分预警</p>
</div>
</div>
<!-- Filter Bar -->
<div class="glass rounded-2xl p-4 mb-6 list-item-enter max-w-5xl mx-auto" style="animation-delay: 50ms;">
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3 items-end">
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">学院</label>
<select id="filter_jg_id" class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
<option value="">加载中...</option>
</select>
</div>
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">年级</label>
<select id="filter_njdm_id" class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
<option value="">加载中...</option>
</select>
</div>
<div class="flex-1 min-w-[200px]">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">专业</label>
<select id="filter_zyh_id" class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
<option value="">加载中...</option>
</select>
</div>
<button id="searchBtn" onclick="doSearch()"
class="px-5 py-2 rounded-lg bg-black dark:bg-white text-white dark:text-black text-sm font-medium hover:opacity-85 transition-opacity whitespace-nowrap flex-shrink-0"
disabled>
查询
</button>
</div>
</div>
<!-- Loading -->
<div id="loadingIndicator" class="text-center py-12 hidden">
<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="creditBarChart" class="h-80"></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="courseStatusChart" class="h-64"></div>
</div>
</div>
<!-- Error -->
<div id="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden">
<p id="errorText" class="text-red-500"></p>
</div>
<!-- Results -->
<div id="dataContainer" class="hidden space-y-4"></div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
let paramsReady = false;
let creditBarChart = null;
let courseStatusChart = 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; }
}
// ── Init: load dropdowns ──
async function loadParams() {
try {
const res = await fetch('/api/jwxt/academic-warning/params');
const data = await res.json();
if (!data.success || !data.selects) {
throw new Error(data.message || '获取下拉框参数失败');
}
fillSelect('filter_jg_id', data.selects.jg_id);
fillSelect('filter_njdm_id', data.selects.njdm_id);
fillSelect('filter_zyh_id', data.selects.zyh_id);
paramsReady = true;
document.getElementById('searchBtn').disabled = false;
// Auto query on load
doSearch();
} catch (e) {
document.getElementById('errorText').textContent = '加载参数失败: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
function fillSelect(id, selectData) {
const el = document.getElementById(id);
if (!selectData || !selectData.options) {
el.innerHTML = '<option value="">--</option>';
return;
}
const defaultVal = selectData.default || '';
el.innerHTML = selectData.options.map(o =>
`<option value="${escAttr(o.value)}" ${o.value === defaultVal ? 'selected' : ''}>${escHtml(o.label)}</option>`
).join('');
}
// ── Search ──
async function doSearch() {
if (!paramsReady) return;
showLoading();
const jg_id = document.getElementById('filter_jg_id').value;
const njdm_id = document.getElementById('filter_njdm_id').value;
const zyh_id = document.getElementById('filter_zyh_id').value;
try {
const params = new URLSearchParams();
if (jg_id) params.append('jg_id', jg_id);
if (njdm_id) params.append('njdm_id', njdm_id);
if (zyh_id) params.append('zyh_id', zyh_id);
const res = await fetch('/api/jwxt/academic-warning?' + params.toString());
const data = await res.json();
hideLoading();
if (!data.success) {
showError(data.message || '查询失败');
return;
}
if (!data.items || !data.items.length) {
showEmpty('暂无学业预警数据');
return;
}
renderCategories(data.items);
} catch (e) {
hideLoading();
showError('网络错误: ' + e.message);
}
}
// ── Render ──
function renderCategories(items) {
const container = document.getElementById('dataContainer');
container.classList.remove('hidden');
container.innerHTML = '';
items.forEach((item, idx) => {
const kcList = item.kcList || [];
const name = item.xfyqjdmc || item.fxfyqjdMc || `分类 ${idx + 1}`;
const minCredit = item.yqzdxf || '0';
const earnedCredit = '--'; // 教务数据中可能没有
const hasCourses = kcList.length > 0;
const card = document.createElement('div');
card.className = `glass rounded-2xl overflow-hidden category-panel ${hasCourses ? 'open' : ''} row-animate`;
card.style.animationDelay = (idx * 50) + 'ms';
card.innerHTML = `
<div class="px-5 py-4 flex justify-between items-center cursor-pointer hover:bg-gray-50/30 dark:hover:bg-gray-800/20 transition-colors"
onclick="toggleCategory(this)">
<div>
<h3 class="font-semibold text-base">${escHtml(name)}</h3>
<p class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
要求最低 <span class="font-medium text-black dark:text-white">${escHtml(minCredit)}</span> 学分
${kcList.length > 0 ? ' · ' + kcList.length + ' 门课程' : ''}
</p>
</div>
${hasCourses ? `
<svg class="toggle-icon w-5 h-5 text-gray-400 flex-shrink-0" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd"/>
</svg>` : ''}
</div>
${hasCourses ? `
<div class="course-table expanded overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-t border-b border-gray-100 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-800/30">
<th class="text-left py-2.5 px-4 font-medium text-gray-600 dark:text-gray-400 text-xs">课程号</th>
<th class="text-left py-2.5 px-4 font-medium text-gray-600 dark:text-gray-400 text-xs">课程名称</th>
<th class="text-center py-2.5 px-4 font-medium text-gray-600 dark:text-gray-400 text-xs">学分</th>
<th class="text-left py-2.5 px-4 font-medium text-gray-600 dark:text-gray-400 text-xs">建议修读</th>
<th class="text-left py-2.5 px-4 font-medium text-gray-600 dark:text-gray-400 text-xs">实际修读</th>
<th class="text-center py-2.5 px-4 font-medium text-gray-600 dark:text-gray-400 text-xs">必修</th>
<th class="text-center py-2.5 px-4 font-medium text-gray-600 dark:text-gray-400 text-xs">成绩</th>
<th class="text-center py-2.5 px-4 font-medium text-gray-600 dark:text-gray-400 text-xs">状态</th>
</tr>
</thead>
<tbody>
${kcList.map(course => renderCourseRow(course)).join('')}
</tbody>
</table>
</div>` : ''}
`;
container.appendChild(card);
});
// 渲染图表
const chartsRow = document.getElementById('chartsRow');
chartsRow.classList.remove('hidden');
renderCreditBarChart(items);
renderCourseStatusChart(items);
setupDarkObserver(items);
}
function renderCourseRow(c) {
// Format semester strings
const planSem = c.jyxdxnmc && c.jyxdxqmc ? `${c.jyxdxnmc} ${c.jyxdxqmc}` : '--';
const actualSem = c.xnmc && c.xqmc ? `${c.xnmc} ${c.xqmc}` : '--';
const isRequired = c.jgpxzd === '1' ? '必修' : '选修';
const score = c.cj || '--';
const scoreClass = getScoreClass(score);
const status = getStatusBadge(c);
return `
<tr class="border-b border-gray-50 dark:border-gray-800/30 hover:bg-gray-50/30 dark:hover:bg-gray-800/20 transition-colors">
<td class="py-2 px-4 text-xs text-gray-500 dark:text-gray-400 font-mono">${escHtml(c.kch || '--')}</td>
<td class="py-2 px-4 text-sm">${escHtml(c.kcmc || '--')}</td>
<td class="py-2 px-4 text-center text-xs">${escHtml(c.xf || '--')}</td>
<td class="py-2 px-4 text-xs text-gray-500">${escHtml(planSem)}</td>
<td class="py-2 px-4 text-xs text-gray-500">${escHtml(actualSem)}</td>
<td class="py-2 px-4 text-center text-xs">${isRequired}</td>
<td class="py-2 px-4 text-center text-sm font-medium ${scoreClass}">${score}</td>
<td class="py-2 px-4 text-center">${status}</td>
</tr>
`;
}
function getScoreClass(score) {
const n = parseFloat(score);
if (isNaN(n)) return 'text-gray-400';
if (n >= 90) return 'text-green-600 dark:text-green-400';
if (n >= 80) return 'text-blue-600 dark:text-blue-400';
if (n >= 70) return 'text-yellow-600 dark:text-yellow-400';
if (n >= 60) return 'text-orange-500 dark:text-orange-400';
return 'text-red-600 dark:text-red-400';
}
function getStatusBadge(c) {
const tdbj = c.tdbj;
const bfzcj = c.bfzcj;
const xnmc = c.xnmc;
if (tdbj === '1') {
return '<span class="inline-block px-2 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400">退课</span>';
}
if (bfzcj === null && xnmc !== null) {
return '<span class="inline-block px-2 py-0.5 rounded text-xs bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400">已修</span>';
}
if (bfzcj !== null && parseFloat(bfzcj) < 60) {
return '<span class="inline-block px-2 py-0.5 rounded text-xs bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400">不及格</span>';
}
if (bfzcj === null && xnmc === null) {
return '<span class="inline-block px-2 py-0.5 rounded text-xs bg-gray-100 dark:bg-gray-800 text-gray-500">未修</span>';
}
if (bfzcj !== null && parseFloat(bfzcj) >= 60) {
return '<span class="inline-block px-2 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400">通过</span>';
}
return '--';
}
// ── Toggle category ──
function toggleCategory(header) {
const panel = header.parentElement;
const table = panel.querySelector('.course-table');
if (!table) return;
panel.classList.toggle('open');
if (panel.classList.contains('open')) {
table.classList.remove('collapsed');
table.classList.add('expanded');
} else {
table.classList.add('collapsed');
table.classList.remove('expanded');
}
}
// ── Helpers ──
function showLoading() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
}
function hideLoading() {
document.getElementById('loadingIndicator').classList.add('hidden');
}
function showError(msg) {
document.getElementById('errorText').textContent = msg;
document.getElementById('errorMessage').classList.remove('hidden');
}
function showEmpty(msg) {
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('dataContainer').innerHTML = `
<div class="glass rounded-2xl p-12 text-center">
<p class="text-gray-500 dark:text-gray-400 text-lg">${escHtml(msg)}</p>
</div>`;
}
function escHtml(s) {
if (s == null) return '';
return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
function escAttr(s) {
if (s == null) return '';
return String(s).replace(/&/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// ── 各类别学分完成度柱状图 ──
function renderCreditBarChart(items) {
const container = document.getElementById('creditBarChart');
if (!container) return;
if (!creditBarChart) creditBarChart = echarts.init(container);
const categories = [];
const requiredCredits = [];
const dark = isDarkMode();
items.forEach(item => {
const name = (item.xfyqjdmc || item.fxfyqjdMc || '未知').substring(0, 8);
const minCredit = parseFloat(item.yqzdxf) || 0;
categories.push(name);
requiredCredits.push(minCredit);
});
creditBarChart.setOption({
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
legend: { data: ['要求学分'], top: 0, textStyle: { fontSize: 11, color: dark ? '#9ca3af' : '#6b7280' } },
grid: { left: '3%', right: '4%', bottom: '3%', top: '15%', containLabel: true },
xAxis: { type: 'value', name: '学分', nameTextStyle: { fontSize: 11 } },
yAxis: { type: 'category', data: categories, axisLabel: { fontSize: 10 }, inverse: true },
series: [{
name: '要求学分', type: 'bar', data: requiredCredits,
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
{ offset: 0, color: dark ? '#60a5fa' : '#3b82f6' },
{ offset: 1, color: dark ? '#34d399' : '#10b981' }
])
},
barMaxWidth: 28,
label: { show: true, position: 'right', fontSize: 11, color: dark ? '#9ca3af' : '#6b7280' }
}]
}, true);
}
// ── 课程状态饼图 ──
function renderCourseStatusChart(items) {
const container = document.getElementById('courseStatusChart');
if (!container) return;
if (!courseStatusChart) courseStatusChart = echarts.init(container);
const statusCount = { '已修/通过': 0, '未修': 0, '不及格': 0, '退课': 0 };
items.forEach(item => {
(item.kcList || []).forEach(c => {
if (c.tdbj === '1') { statusCount['退课']++; return; }
if (c.bfzcj === null && c.xnmc === null) { statusCount['未修']++; return; }
if (c.bfzcj !== null && parseFloat(c.bfzcj) < 60) { statusCount['不及格']++; return; }
statusCount['已修/通过']++;
});
});
const entries = Object.entries(statusCount).filter(([, v]) => v > 0);
const dark = isDarkMode();
const colorMap = {
'已修/通过': dark ? '#34d399' : '#10b981',
'未修': dark ? '#9ca3af' : '#6b7280',
'不及格': dark ? '#f87171' : '#ef4444',
'退课': dark ? '#fbbf24' : '#f59e0b',
};
courseStatusChart.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]) => ({ name, value, itemStyle: { color: colorMap[name] || '#999' } }))
}]
}, true);
}
// ── 深色模式观察者 ──
let _darkObserver = null;
let _lastItems = null;
function setupDarkObserver(items) {
_lastItems = items;
if (_darkObserver) return;
_darkObserver = new MutationObserver(() => {
if (_lastItems && _lastItems.length > 0) {
renderCreditBarChart(_lastItems);
renderCourseStatusChart(_lastItems);
}
});
_darkObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
window.addEventListener('resize', () => {
creditBarChart?.resize();
courseStatusChart?.resize();
});
// ── Start ──
initSession().then(sessionOk => {
if (!sessionOk) {
showError('教务系统 Session 已失效,请尝试<a href="/dashboard">重新配置教务账号</a>');
return;
}
loadParams();
});
</script>
{% endblock %}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+623
View File
@@ -0,0 +1,623 @@
{% extends "base_tailwind.html" %}
{% block title %}IP管理 - {{ brand_name }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- 页面标题 -->
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4 list-item-enter" style="animation-delay: 0ms;">
<div>
<h1 class="text-2xl md:text-3xl font-bold text-neutral-900 dark:text-white">IP 管理</h1>
<p class="text-neutral-500 dark:text-neutral-400 mt-1">访问控制、封禁管理与访问统计</p>
</div>
<div class="flex gap-3 flex-wrap">
<button onclick="openBanModal()" class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
</svg>
添加封禁
</button>
<button onclick="openConfigModal()" class="px-5 py-2.5 rounded-full text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">
频率设置
</button>
<a href="{{ url_for('main.admin_users') }}" class="px-5 py-2.5 rounded-full text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors flex items-center gap-1.5">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 17l-5-5m0 0l5-5m-5 5h12"/>
</svg>
返回管理后台
</a>
</div>
</div>
<!-- 统计概览 -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 50ms;">
<p class="text-sm text-neutral-500 dark:text-neutral-400">今日访问</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statTotal">-</p>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 100ms;">
<p class="text-sm text-neutral-500 dark:text-neutral-400">独立IP</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statUnique">-</p>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 150ms;">
<p class="text-sm text-neutral-500 dark:text-neutral-400">被拦截</p>
<p class="text-2xl font-bold text-red-500 mt-1" id="statBlocked">-</p>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 200ms;">
<p class="text-sm text-neutral-500 dark:text-neutral-400">封禁规则</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statBans">-</p>
</div>
</div>
<!-- 标签页切换 -->
<div class="border-b border-neutral-200 dark:border-neutral-800 list-item-enter" style="animation-delay: 250ms;">
<nav class="flex gap-6">
<button onclick="switchTab('stats')" id="tab-stats" class="pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors">
统计图表
</button>
<button onclick="switchTab('logs')" id="tab-logs" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
访问日志
</button>
<button onclick="switchTab('bans')" id="tab-bans" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
封禁管理
</button>
</nav>
</div>
<!-- 统计图表 -->
<div id="panel-stats" class="space-y-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 300ms;">
<div class="flex items-center justify-between mb-3">
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300">访问时段分布</h3>
<select id="statsHours" onchange="loadStats()" class="text-xs rounded-lg border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 px-2 py-1 text-neutral-700 dark:text-neutral-300">
<option value="1">最近1小时</option>
<option value="6">最近6小时</option>
<option value="24" selected>最近24小时</option>
<option value="72">最近3天</option>
<option value="168">最近7天</option>
</select>
</div>
<div id="chartHour" class="w-full h-64"></div>
</div>
<div class="grid md:grid-cols-2 gap-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 350ms;">
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300 mb-3">来源国家/地区 Top10</h3>
<div id="chartCountry" class="w-full h-64"></div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 400ms;">
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300 mb-3">中国省份分布 Top15</h3>
<div id="chartRegion" class="w-full h-64"></div>
</div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 450ms;">
<div class="flex items-center justify-between mb-3">
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300">访问最多 IP Top10</h3>
</div>
<div id="topIpTable" class="space-y-2 max-h-64 overflow-y-auto"></div>
</div>
</div>
<!-- 访问日志 -->
<div id="panel-logs" class="hidden space-y-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 300ms;">
<!-- 过滤栏 -->
<div class="flex flex-wrap gap-3 mb-4">
<input id="filterIp" type="text" placeholder="IP过滤..."
class="rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 text-sm px-3 py-2 text-neutral-700 dark:text-neutral-300 w-40">
<select id="filterBlocked" class="rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 text-sm px-3 py-2 text-neutral-700 dark:text-neutral-300">
<option value="">全部</option>
<option value="true">仅拦截</option>
</select>
<button onclick="loadLogs(1)" class="px-4 py-2 rounded-xl bg-blue-500 text-white text-sm font-medium hover:bg-blue-600 transition-colors">搜索</button>
<button onclick="openCleanModal()" class="px-4 py-2 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 text-sm font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition-colors">🗑 清理日志</button>
</div>
<!-- 日志表格 -->
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-neutral-500 dark:text-neutral-400 border-b border-neutral-200 dark:border-neutral-700">
<th class="pb-3 pr-4 font-medium">时间</th>
<th class="pb-3 pr-4 font-medium">IP</th>
<th class="pb-3 pr-4 font-medium">地区</th>
<th class="pb-3 pr-4 font-medium">路径</th>
<th class="pb-3 pr-4 font-medium">状态</th>
<th class="pb-3 font-medium">操作</th>
</tr>
</thead>
<tbody id="logsTableBody" class="divide-y divide-neutral-100 dark:divide-neutral-800">
<tr><td colspan="6" class="py-8 text-center text-neutral-400">加载中...</td></tr>
</tbody>
</table>
</div>
<!-- 分页 -->
<div id="logsPagination" class="flex items-center justify-between mt-4">
<span id="logsInfo" class="text-sm text-neutral-500"></span>
<div class="flex gap-2" id="paginationBtns"></div>
</div>
</div>
</div>
<!-- 封禁管理 -->
<div id="panel-bans" class="hidden space-y-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 300ms;">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-neutral-500 dark:text-neutral-400 border-b border-neutral-200 dark:border-neutral-700">
<th class="pb-3 pr-4 font-medium">类型</th>
<th class="pb-3 pr-4 font-medium">值</th>
<th class="pb-3 pr-4 font-medium">原因</th>
<th class="pb-3 pr-4 font-medium">到期时间</th>
<th class="pb-3 pr-4 font-medium">创建时间</th>
<th class="pb-3 pr-4 font-medium">操作者</th>
<th class="pb-3 font-medium">操作</th>
</tr>
</thead>
<tbody id="bansTableBody" class="divide-y divide-neutral-100 dark:divide-neutral-800">
<tr><td colspan="7" class="py-8 text-center text-neutral-400">加载中...</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- 添加封禁 Modal -->
<div id="banModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeBanModal()"></div>
<div class="absolute inset-0 flex items-center justify-center p-4 pointer-events-none">
<div class="bg-white dark:bg-neutral-900 rounded-2xl shadow-xl w-full max-w-md pointer-events-auto">
<div class="p-6">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-5">添加封禁规则</h3>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁类型</label>
<select id="banType" class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<option value="ip">单个IP</option>
<option value="cidr">IP段 (CIDR,如 1.2.3.0/24)</option>
<option value="country">国家/地区代码 (如 US)</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁值</label>
<input id="banValue" type="text" placeholder="IP / CIDR / 国家代码"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁时长</label>
<select id="banDuration" class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<option value="">永久封禁</option>
<option value="1h">1小时</option>
<option value="6h">6小时</option>
<option value="1d">1天</option>
<option value="3d">3天</option>
<option value="1w">1周</option>
<option value="1m">1个月</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁原因</label>
<input id="banReason" type="text" placeholder="可选"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
</div>
</div>
<div class="flex gap-3 mt-6">
<button onclick="submitBan()" class="flex-1 btn-primary py-2.5 rounded-xl text-sm font-bold">确认封禁</button>
<button onclick="closeBanModal()" class="flex-1 px-4 py-2.5 rounded-xl text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">取消</button>
</div>
</div>
</div>
</div>
</div>
<!-- 快速封禁 Modal -->
<div id="quickBanModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="document.getElementById('quickBanModal').classList.add('hidden')"></div>
<div class="absolute inset-0 flex items-center justify-center p-4 pointer-events-none">
<div class="bg-white dark:bg-neutral-900 rounded-2xl shadow-xl w-full max-w-md pointer-events-auto">
<div class="p-6">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-2">快速封禁 IP</h3>
<p class="text-sm text-neutral-500 mb-5">IP:<strong id="quickBanIpDisplay" class="text-neutral-800 dark:text-neutral-200 font-mono"></strong></p>
<input type="hidden" id="quickBanIp">
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁时长</label>
<select id="quickBanDuration" class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<option value="">永久封禁</option>
<option value="1h">1小时</option>
<option value="6h">6小时</option>
<option value="1d">1天</option>
<option value="3d">3天</option>
<option value="1w">1周</option>
<option value="1m">1个月</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">原因</label>
<input id="quickBanReason" type="text" value="管理员从日志封禁"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
</div>
</div>
<div class="flex gap-3 mt-6">
<button onclick="submitQuickBan()" class="flex-1 bg-red-500 text-white py-2.5 rounded-xl text-sm font-bold hover:bg-red-600 transition-colors">确认封禁</button>
<button onclick="document.getElementById('quickBanModal').classList.add('hidden')" class="flex-1 px-4 py-2.5 rounded-xl text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">取消</button>
</div>
</div>
</div>
</div>
</div>
<!-- 频率设置 Modal -->
<div id="configModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="document.getElementById('configModal').classList.add('hidden')"></div>
<div class="absolute inset-0 flex items-center justify-center p-4 pointer-events-none">
<div class="bg-white dark:bg-neutral-900 rounded-2xl shadow-xl w-full max-w-md pointer-events-auto">
<div class="p-6">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-5">登录频率限制设置</h3>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">统计时间窗口(分钟)</label>
<input id="cfgWindow" type="number" min="1" max="60"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<p class="text-xs text-neutral-400 mt-1">在此时间窗口内统计失败次数</p>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">最大失败次数</label>
<input id="cfgMax" type="number" min="1" max="100"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<p class="text-xs text-neutral-400 mt-1">超过此次数自动封禁1小时</p>
</div>
<div class="flex items-center gap-3">
<input id="cfgChinaOnly" type="checkbox" class="w-4 h-4 rounded">
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300">启用中国IP限制(关闭后允许境外访问)</label>
</div>
</div>
<div class="flex gap-3 mt-6">
<button onclick="submitConfig()" class="flex-1 btn-primary py-2.5 rounded-xl text-sm font-bold">保存配置</button>
<button onclick="document.getElementById('configModal').classList.add('hidden')" class="flex-1 px-4 py-2.5 rounded-xl text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">取消</button>
</div>
</div>
</div>
</div>
</div>
<!-- 清理日志 Modal -->
<div id="cleanModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="document.getElementById('cleanModal').classList.add('hidden')"></div>
<div class="absolute inset-0 flex items-center justify-center p-4 pointer-events-none">
<div class="bg-white dark:bg-neutral-900 rounded-2xl shadow-xl w-full max-w-sm pointer-events-auto">
<div class="p-6">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-4">清理访问日志</h3>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">清理多少天前的日志</label>
<select id="cleanDays" class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<option value="1">1天前</option>
<option value="3">3天前</option>
<option value="7" selected>7天前</option>
<option value="30">30天前</option>
</select>
</div>
<div class="flex gap-3 mt-6">
<button onclick="submitClean()" class="flex-1 bg-red-500 text-white py-2.5 rounded-xl text-sm font-bold hover:bg-red-600 transition-colors">确认清理</button>
<button onclick="document.getElementById('cleanModal').classList.add('hidden')" class="flex-1 px-4 py-2.5 rounded-xl text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">取消</button>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
// ==================== 工具函数 ====================
function showToast(msg, type='success') {
const t = document.getElementById('toast');
if (!t) return;
const inner = document.getElementById('toastInner');
inner.textContent = msg;
inner.className = `rounded-2xl px-5 py-3 text-sm font-medium shadow-xl text-white ${type === 'success' ? 'bg-green-500' : 'bg-red-500'}`;
t.classList.remove('hidden');
setTimeout(() => t.classList.add('hidden'), 3000);
}
async function apiFetch(url, options={}) {
const resp = await fetch(url, {
headers: {'Content-Type': 'application/json', ...(options.headers || {})},
...options
});
return resp.json();
}
// ==================== Tab 切换 ====================
let currentTab = 'stats';
function switchTab(tab) {
['stats','logs','bans'].forEach(t => {
document.getElementById(`panel-${t}`).classList.add('hidden');
document.getElementById(`tab-${t}`).className = t === tab
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
});
document.getElementById(`panel-${tab}`).classList.remove('hidden');
currentTab = tab;
if (tab === 'logs' && !logsLoaded) loadLogs(1);
if (tab === 'bans' && !bansLoaded) loadBans();
}
// ==================== 统计图表 ====================
let chartHour = null, chartCountry = null, chartRegion = null;
let logsLoaded = false, bansLoaded = false;
async function loadStats() {
const hours = document.getElementById('statsHours').value;
const data = await apiFetch(`/api/admin/ip/stats?hours=${hours}`);
if (!data.success) { showToast('加载统计失败: ' + data.message, 'error'); return; }
const s = data.stats;
document.getElementById('statTotal').textContent = s.total.toLocaleString();
document.getElementById('statUnique').textContent = s.unique_ips.toLocaleString();
document.getElementById('statBlocked').textContent = s.blocked.toLocaleString();
document.getElementById('statBans').textContent = s.active_bans;
// 时段分布
const now = new Date();
const allHours = [];
for (let i = parseInt(hours) - 1; i >= 0; i--) {
const d = new Date(now.getTime() - i * 3600000);
if (parseInt(hours) <= 24) {
allHours.push(d.toISOString().slice(11, 16));
} else {
allHours.push(d.toISOString().slice(5, 10));
}
}
const hourMap = {};
s.by_hour.forEach(h => hourMap[String(h.hour).padStart(2,'0')] = h.count);
const hourData = allHours.map((_, idx) => {
if (parseInt(hours) <= 24) return hourMap[String(idx).padStart(2,'0')] || 0;
const d = new Date(now.getTime() - (parseInt(hours) - 1 - idx) * 3600000);
return hourMap[String(d.getUTCHours()).padStart(2,'0')] || 0;
});
renderHourBar('chartHour', allHours, hourData);
// 国家分布
const topCountries = s.by_country.slice(0, 10);
renderCountryBar('chartCountry', topCountries.map(c => c.country || '-'), topCountries.map(c => c.count));
// 省份分布
const topRegions = s.by_region.slice(0, 15);
renderRegionBar('chartRegion', topRegions.map(r => r.region || '-'), topRegions.map(r => r.count));
// Top IP
document.getElementById('topIpTable').innerHTML = s.top_ips.slice(0, 10).map((ip, i) => `
<div class="flex items-center justify-between py-2 border-b border-neutral-100 dark:border-neutral-800">
<div class="flex items-center gap-3">
<span class="w-5 text-xs text-neutral-400 font-mono">${i+1}</span>
<div>
<p class="text-sm font-mono text-neutral-800 dark:text-neutral-200">${ip.ip}</p>
<p class="text-xs text-neutral-400">${ip.country||''} ${ip.region||''} ${ip.city||''}</p>
</div>
</div>
<div class="flex items-center gap-3">
<span class="text-sm font-bold text-neutral-700 dark:text-neutral-300">${ip.count}</span>
<button onclick="openQuickBan('${ip.ip}')" class="text-xs px-2 py-1 rounded-lg bg-red-100 text-red-600 hover:bg-red-200 transition-colors">封禁</button>
</div>
</div>`).join('');
}
function renderHourBar(domId, labels, data) {
const dom = document.getElementById(domId);
if (!dom) return;
if (chartHour) { chartHour.dispose(); chartHour = null; }
const isDark = document.documentElement.classList.contains('dark');
chartHour = echarts.init(dom);
chartHour.setOption({
tooltip: { trigger: 'axis', backgroundColor: isDark ? '#262626' : '#fff', textStyle: { color: isDark ? '#fff' : '#333' } },
grid: { left: '3%', right: '4%', bottom: '3%', top: '10%', containLabel: true },
xAxis: { type: 'category', data: labels, axisLabel: { color: isDark ? '#888' : '#666', rotate: labels.length > 12 ? 45 : 0 }, axisLine: { lineStyle: { color: isDark ? '#444' : '#ddd' } } },
yAxis: { type: 'value', axisLabel: { color: isDark ? '#888' : '#666' }, splitLine: { lineStyle: { color: isDark ? '#333' : '#eee' } } },
series: [{ type: 'bar', data: data, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#3b82f6' }, { offset: 1, color: '#60a5fa' }]), borderRadius: [4, 4, 0, 0] }, emphasis: { itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#2563eb' }, { offset: 1, color: '#3b82f6' }]) } } }]
});
window.addEventListener('resize', () => chartHour && chartHour.resize());
}
function renderCountryBar(domId, labels, data) {
const dom = document.getElementById(domId);
if (!dom) return;
if (chartCountry) { chartCountry.dispose(); chartCountry = null; }
const isDark = document.documentElement.classList.contains('dark');
chartCountry = echarts.init(dom);
chartCountry.setOption({
tooltip: { trigger: 'axis', backgroundColor: isDark ? '#262626' : '#fff', textStyle: { color: isDark ? '#fff' : '#333' } },
grid: { left: '3%', right: '4%', bottom: '15%', top: '10%', containLabel: true },
xAxis: { type: 'category', data: labels, axisLabel: { color: isDark ? '#888' : '#666', rotate: 30 }, axisLine: { lineStyle: { color: isDark ? '#444' : '#ddd' } } },
yAxis: { type: 'value', axisLabel: { color: isDark ? '#888' : '#666' }, splitLine: { lineStyle: { color: isDark ? '#333' : '#eee' } } },
series: [{ type: 'bar', data: data, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#10b981' }, { offset: 1, color: '#34d399' }]), borderRadius: [4, 4, 0, 0] }, emphasis: { itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#059669' }, { offset: 1, color: '#10b981' }]) } } }]
});
window.addEventListener('resize', () => chartCountry && chartCountry.resize());
}
function renderRegionBar(domId, labels, data) {
const dom = document.getElementById(domId);
if (!dom) return;
if (chartRegion) { chartRegion.dispose(); chartRegion = null; }
const isDark = document.documentElement.classList.contains('dark');
chartRegion = echarts.init(dom);
chartRegion.setOption({
tooltip: { trigger: 'axis', backgroundColor: isDark ? '#262626' : '#fff', textStyle: { color: isDark ? '#fff' : '#333' } },
grid: { left: '3%', right: '4%', bottom: '15%', top: '10%', containLabel: true },
xAxis: { type: 'category', data: labels, axisLabel: { color: isDark ? '#888' : '#666', rotate: 30 }, axisLine: { lineStyle: { color: isDark ? '#444' : '#ddd' } } },
yAxis: { type: 'value', axisLabel: { color: isDark ? '#888' : '#666' }, splitLine: { lineStyle: { color: isDark ? '#333' : '#eee' } } },
series: [{ type: 'bar', data: data, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#f59e0b' }, { offset: 1, color: '#fbbf24' }]), borderRadius: [4, 4, 0, 0] }, emphasis: { itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#d97706' }, { offset: 1, color: '#f59e0b' }]) } } }]
});
window.addEventListener('resize', () => chartRegion && chartRegion.resize());
}
// ==================== 访问日志 ====================
let currentPage = 1;
async function loadLogs(page=1) {
currentPage = page;
logsLoaded = true;
const ip = document.getElementById('filterIp').value.trim();
const blocked = document.getElementById('filterBlocked').value;
let url = `/api/admin/ip/logs?page=${page}&per_page=50`;
if (ip) url += `&ip=${encodeURIComponent(ip)}`;
if (blocked) url += `&blocked=${blocked}`;
const data = await apiFetch(url);
if (!data.success) { showToast('加载日志失败', 'error'); return; }
const tbody = document.getElementById('logsTableBody');
tbody.innerHTML = data.logs.length === 0 ? '<tr><td colspan="6" class="py-8 text-center text-neutral-400">暂无日志</td></tr>' :
data.logs.map(l => `
<tr class="hover:bg-neutral-50 dark:hover:bg-neutral-800/50">
<td class="py-2.5 pr-4 text-xs text-neutral-500 whitespace-nowrap">${formatTime(l.created_at)}</td>
<td class="py-2.5 pr-4"><span class="font-mono text-xs text-neutral-800 dark:text-neutral-200">${l.ip}</span></td>
<td class="py-2.5 pr-4 text-xs text-neutral-500">${l.country||''} ${l.region||''}</td>
<td class="py-2.5 pr-4 text-xs text-neutral-600 dark:text-neutral-400 max-w-[200px] truncate" title="${l.path||''}">${l.method||''} ${l.path||''}</td>
<td class="py-2.5 pr-4">${l.blocked ? `<span class="text-xs px-2 py-0.5 rounded-full bg-red-100 text-red-600">拦截 ${l.block_reason||''}</span>` : `<span class="text-xs px-2 py-0.5 rounded-full bg-green-100 text-green-600">放行</span>`}</td>
<td class="py-2.5"><button onclick="openQuickBan('${l.ip}')" class="text-xs px-2 py-1 rounded-lg bg-red-50 text-red-500 hover:bg-red-100 transition-colors">封禁</button></td>
</tr>`).join('');
document.getElementById('logsInfo').textContent = `共 ${data.total} 条,第 ${page}/${data.pages} 页`;
const paginationDiv = document.getElementById('paginationBtns');
paginationDiv.innerHTML = '';
const totalPages = data.pages;
const start = Math.max(1, page-2), end = Math.min(totalPages, page+2);
if (page > 1) addPageBtn(paginationDiv, page-1, '‹');
for (let p=start; p<=end; p++) addPageBtn(paginationDiv, p, p, p===page);
if (page < totalPages) addPageBtn(paginationDiv, page+1, '›');
}
function addPageBtn(container, page, label, active=false) {
const btn = document.createElement('button');
btn.textContent = label;
btn.className = `px-3 py-1.5 rounded-lg text-sm font-medium transition-colors ${active ? 'bg-blue-500 text-white' : 'bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700'}`;
btn.onclick = () => loadLogs(page);
container.appendChild(btn);
}
// ==================== 封禁管理 ====================
async function loadBans() {
bansLoaded = true;
const data = await apiFetch('/api/admin/ip/bans');
if (!data.success) { showToast('加载封禁列表失败', 'error'); return; }
const tbody = document.getElementById('bansTableBody');
tbody.innerHTML = data.bans.length === 0 ? '<tr><td colspan="7" class="py-8 text-center text-neutral-400">暂无封禁规则</td></tr>' :
data.bans.map(b => `
<tr class="${b.is_active ? '' : 'opacity-40'} hover:bg-neutral-50 dark:hover:bg-neutral-800/50">
<td class="py-2.5 pr-4"><span class="text-xs px-2 py-0.5 rounded-full font-medium ${b.ban_type==='ip'?'bg-red-100 text-red-600':b.ban_type==='cidr'?'bg-orange-100 text-orange-600':'bg-purple-100 text-purple-600'}">${b.ban_type.toUpperCase()}</span></td>
<td class="py-2.5 pr-4 font-mono text-sm text-neutral-800 dark:text-neutral-200">${b.value}</td>
<td class="py-2.5 pr-4 text-xs text-neutral-500 max-w-[160px] truncate" title="${b.reason||''}">${b.reason||'-'}</td>
<td class="py-2.5 pr-4 text-xs text-neutral-500">${b.is_permanent ? '<span class="text-red-500 font-semibold">永久</span>' : formatTime(b.expires_at)}</td>
<td class="py-2.5 pr-4 text-xs text-neutral-500">${formatTime(b.created_at)}</td>
<td class="py-2.5 pr-4 text-xs text-neutral-500">${b.created_by||'-'}</td>
<td class="py-2.5"><button onclick="unbanById(${b.id},'${b.value}')" class="text-xs px-2 py-1 rounded-lg bg-green-50 text-green-600 hover:bg-green-100 transition-colors">解封</button></td>
</tr>`).join('');
}
async function unbanById(id, value) {
if (!confirm(`确认解封 ${value}?`)) return;
const data = await apiFetch('/api/admin/ip/unban', { method: 'POST', body: JSON.stringify({id}) });
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) { bansLoaded = false; loadBans(); loadStats(); }
}
// ==================== 添加封禁 Modal ====================
function openBanModal() { document.getElementById('banModal').classList.remove('hidden'); }
function closeBanModal() { document.getElementById('banModal').classList.add('hidden'); }
async function submitBan() {
const value = document.getElementById('banValue').value.trim();
if (!value) { showToast('请填写封禁值', 'error'); return; }
const data = await apiFetch('/api/admin/ip/ban', {
method: 'POST',
body: JSON.stringify({
value,
ban_type: document.getElementById('banType').value,
duration: document.getElementById('banDuration').value || null,
reason: document.getElementById('banReason').value
})
});
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) { closeBanModal(); bansLoaded = false; if (currentTab === 'bans') loadBans(); loadStats(); }
}
// ==================== 快速封禁 ====================
function openQuickBan(ip) {
document.getElementById('quickBanIp').value = ip;
document.getElementById('quickBanIpDisplay').textContent = ip;
document.getElementById('quickBanModal').classList.remove('hidden');
}
async function submitQuickBan() {
const ip = document.getElementById('quickBanIp').value;
const data = await apiFetch('/api/admin/ip/ban_from_log', {
method: 'POST',
body: JSON.stringify({
ip,
duration: document.getElementById('quickBanDuration').value || null,
reason: document.getElementById('quickBanReason').value
})
});
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) {
document.getElementById('quickBanModal').classList.add('hidden');
if (currentTab === 'logs') loadLogs(currentPage);
if (currentTab === 'bans') loadBans();
loadStats();
}
}
// ==================== 频率限制配置 Modal ====================
async function openConfigModal() {
const data = await apiFetch('/api/admin/ip/config');
if (data.success) {
document.getElementById('cfgWindow').value = data.config.login_window_minutes;
document.getElementById('cfgMax').value = data.config.login_max_attempts;
document.getElementById('cfgChinaOnly').checked = data.config.enable_china_only === 'true';
}
document.getElementById('configModal').classList.remove('hidden');
}
async function submitConfig() {
const data = await apiFetch('/api/admin/ip/config', {
method: 'POST',
body: JSON.stringify({
login_window_minutes: parseInt(document.getElementById('cfgWindow').value),
login_max_attempts: parseInt(document.getElementById('cfgMax').value),
enable_china_only: document.getElementById('cfgChinaOnly').checked
})
});
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) document.getElementById('configModal').classList.add('hidden');
}
// ==================== 清理日志 Modal ====================
function openCleanModal() { document.getElementById('cleanModal').classList.remove('hidden'); }
async function submitClean() {
const days = parseInt(document.getElementById('cleanDays').value);
const data = await apiFetch('/api/admin/ip/clean_logs', {
method: 'POST',
body: JSON.stringify({days})
});
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) {
document.getElementById('cleanModal').classList.add('hidden');
loadLogs(1);
}
}
// ==================== 初始化 ====================
document.addEventListener('DOMContentLoaded', () => {
loadStats();
apiFetch('/api/admin/ip/bans').then(d => {
if (d.success) document.getElementById('statBans').textContent = d.bans.filter(b=>b.is_active).length;
});
});
</script>
{% endblock %}
+191
View File
@@ -0,0 +1,191 @@
{% extends "base_tailwind.html" %}
{% block title %}用户管理 - {{ brand_name }}{% endblock %}
{% block extra_css %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
<style>
.modal-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; opacity: 0; pointer-events: none; transition: opacity 0.24s ease; }
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.modal-panel { position: relative; width: 100%; max-width: 28rem; opacity: 0; transform: scale(0.95) translateY(8px); transition: opacity 0.24s ease, transform 0.26s cubic-bezier(0.22,1,0.36,1); }
.modal-overlay.open .modal-panel { opacity: 1; transform: scale(1) translateY(0); }
.modal-panel-lg { max-width: 48rem; }
.pagination { display: flex; gap: 0.25rem; justify-content: center; align-items: center; padding: 0; margin: 0; list-style: none; }
.page-item { list-style: none; }
.page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 2.25rem; height: 2.25rem; padding: 0 0.75rem; border-radius: 0.5rem; font-size: 0.875rem; font-weight: 500; background: rgba(255,255,255,0.6); border: 1px solid rgba(0,0,0,0.08); color: #333; cursor: pointer; transition: all 0.2s; text-decoration: none; }
.page-link:hover { background: rgba(0,0,0,0.05); }
.dark .page-link { background: rgba(23,23,23,0.8); border-color: rgba(255,255,255,0.08); color: #e5e5e5; }
.dark .page-link:hover { background: rgba(255,255,255,0.05); }
.page-item.active .page-link { background: #111; color: #fff; border-color: #111; }
.dark .page-item.active .page-link { background: #fff; color: #000; border-color: #fff; }
.page-item.disabled .page-link { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.loading-spinner { width: 40px; height: 40px; border: 3px solid rgba(0,0,0,0.1); border-top-color: currentColor; border-radius: 50%; animation: spin 0.8s linear infinite; }
.dark .loading-spinner { border-color: rgba(255,255,255,0.15); border-top-color: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-spinner { animation: none !important; border: 3px solid currentColor; opacity: 0.3; } }
</style>
{% endblock %}
{% block content %}
<div class="space-y-6">
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4 list-item-enter" style="animation-delay:0ms">
<h2 class="text-2xl font-bold flex items-center gap-2"><i class="bi bi-people"></i> 用户管理</h2>
<button class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold inline-flex items-center gap-2" onclick="showModal(&#39;createUserModal&#39;)"><i class="bi bi-person-plus"></i> 添加用户</button>
</div>
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay:50ms">
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
<div>
<h5 class="font-bold mb-2 flex items-center gap-2"><i class="bi bi-shield-check"></i> Session 状态</h5>
<div class="flex gap-4 flex-wrap">
<span class="text-green-600 dark:text-green-400 flex items-center gap-1"><i class="bi bi-check-circle-fill"></i> 有效: <strong id="sessionValid">-</strong></span>
<span class="text-red-500 dark:text-red-400 flex items-center gap-1"><i class="bi bi-x-circle-fill"></i> 过期: <strong id="sessionInvalid">-</strong></span>
<span class="text-neutral-500 dark:text-neutral-400 flex items-center gap-1"><i class="bi bi-question-circle-fill"></i> 未知: <strong id="sessionUnknown">-</strong></span>
</div>
</div>
<div class="flex gap-2">
<button class="btn-outline text-sm px-4 py-2" onclick="batchCheckSession()"><i class="bi bi-search"></i> 批量检查</button>
<button class="btn-outline text-sm px-4 py-2" onclick="showModal(&#39;batchRefreshModal&#39;)"><i class="bi bi-arrow-clockwise"></i> 批量刷新</button>
</div>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4 list-item-enter" style="animation-delay:100ms">
<div class="glass rounded-2xl p-5 layer-2 flex items-center justify-between">
<div><p class="text-sm text-neutral-500 dark:text-neutral-400">总用户数</p><p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="totalUsers">-</p></div>
<div class="w-10 h-10 rounded-xl bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center text-blue-600 dark:text-blue-400"><i class="bi bi-people text-lg"></i></div>
</div>
<div class="glass rounded-2xl p-5 layer-2 flex items-center justify-between">
<div><p class="text-sm text-neutral-500 dark:text-neutral-400">总任务数</p><p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="totalTasks">-</p></div>
<div class="w-10 h-10 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center text-amber-600 dark:text-amber-400"><i class="bi bi-list-task text-lg"></i></div>
</div>
<div class="glass rounded-2xl p-5 layer-2 flex items-center justify-between">
<div><p class="text-sm text-neutral-500 dark:text-neutral-400">运行中</p><p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="runningTasks">-</p></div>
<div class="w-10 h-10 rounded-xl bg-green-100 dark:bg-green-900/30 flex items-center justify-center text-green-600 dark:text-green-400"><i class="bi bi-play-circle text-lg"></i></div>
</div>
<div class="glass rounded-2xl p-5 layer-2 flex items-center justify-between">
<div><p class="text-sm text-neutral-500 dark:text-neutral-400">成功任务</p><p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="successTasks">-</p></div>
<div class="w-10 h-10 rounded-xl bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center text-purple-600 dark:text-purple-400"><i class="bi bi-check-circle text-lg"></i></div>
</div>
</div>
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay:150ms">
<div class="flex justify-between items-center mb-4">
<h5 class="font-bold flex items-center gap-2"><i class="bi bi-list"></i> 用户列表</h5>
<button class="btn-outline text-sm px-4 py-2" onclick="loadUsers()"><i class="bi bi-arrow-clockwise"></i> 刷新</button>
</div>
<div id="loadingIndicator" class="text-center py-12">
<div class="loading-spinner mx-auto mb-3 text-neutral-900 dark:text-white"></div>
<p class="text-neutral-500 dark:text-neutral-400">加载中...</p>
</div>
<div id="emptyState" class="text-center py-12" style="display:none">
<div class="w-16 h-16 mx-auto mb-4 rounded-2xl bg-neutral-100 dark:bg-neutral-800 flex items-center justify-center text-neutral-400"><i class="bi bi-inbox text-2xl"></i></div>
<p class="text-neutral-500 dark:text-neutral-400">暂无用户</p>
</div>
<div id="usersTableContainer" class="overflow-x-auto" style="display:none">
<table class="data-table">
<thead><tr><th>ID</th><th>用户名</th><th>学号</th><th>Session</th><th>角色</th><th>状态</th><th>创建时间</th><th>操作</th></tr></thead>
<tbody id="usersTableBody"></tbody>
</table>
</div>
<nav id="pagination" class="mt-4" style="display:none"><ul class="pagination" id="paginationList"></ul></nav>
</div>
</div>
<div id="createUserModal" class="modal-overlay" onclick="if(event.target===this)hideModal(&#39;createUserModal&#39;)">
<div class="modal-backdrop" onclick="hideModal(&#39;createUserModal&#39;)"></div>
<div class="modal-panel">
<div class="glass rounded-2xl p-6 layer-4">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white flex items-center gap-2"><i class="bi bi-person-plus"></i> 添加用户</h3>
<button onclick="hideModal(&#39;createUserModal&#39;)" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition"><i class="bi bi-x-lg"></i></button>
</div>
<form id="createUserForm" class="space-y-4">
<div><label class="input-label">用户名(学号)</label><input type="text" class="input-field" id="newUsername" required></div>
<div><label class="input-label">密码</label><input type="password" class="input-field" id="newPassword" required></div>
<div class="flex items-center gap-2"><input type="checkbox" id="newIsAdmin" class="w-4 h-4 rounded border-neutral-300 dark:border-neutral-600 accent-neutral-900 dark:accent-white"><label for="newIsAdmin" class="text-sm text-neutral-700 dark:text-neutral-300">设为管理员</label></div>
</form>
<div class="flex gap-3 mt-6">
<button type="button" onclick="hideModal(&#39;createUserModal&#39;)" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">取消</button>
<button type="button" onclick="submitCreateUser()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition"><i class="bi bi-check-circle"></i> 创建</button>
</div>
</div>
</div>
</div>
<div id="batchRefreshModal" class="modal-overlay" onclick="if(event.target===this)hideModal(&#39;batchRefreshModal&#39;)">
<div class="modal-backdrop" onclick="hideModal(&#39;batchRefreshModal&#39;)"></div>
<div class="modal-panel modal-panel-lg">
<div class="glass rounded-2xl p-6 layer-4 max-h-[90vh] overflow-y-auto">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white flex items-center gap-2"><i class="bi bi-arrow-clockwise"></i> 批量刷新 Session</h3>
<button onclick="hideModal(&#39;batchRefreshModal&#39;)" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition"><i class="bi bi-x-lg"></i></button>
</div>
<div class="glass rounded-xl p-4 mb-4 bg-blue-50 dark:bg-blue-900/20 text-blue-800 dark:text-blue-200 text-sm"><i class="bi bi-info-circle"></i> 请选择刷新选项。强制刷新会忽略当前有效的 session,重新登录所有账号。</div>
<div class="flex items-center gap-2 mb-4"><input type="checkbox" id="batchForceRefresh" class="w-4 h-4 rounded border-neutral-300 dark:border-neutral-600 accent-neutral-900 dark:accent-white"><label for="batchForceRefresh" class="text-sm text-neutral-700 dark:text-neutral-300"><strong>强制刷新</strong>(即使 session 有效也重新登录)</label></div>
<div class="mb-4"><label class="input-label">密码映射(JSON 格式,可选)</label><textarea class="input-field" id="batchPasswordMap" rows="5" placeholder="{&quot;学号1&quot;: &quot;密码1&quot;, &quot;学号2&quot;: &quot;密码2&quot;}"></textarea><p class="text-xs text-neutral-500 mt-1">如果不提供密码映射,将只检查状态,无法刷新过期的 session</p></div>
<div id="batchRefreshResult" style="display:none">
<div class="border-t border-neutral-200 dark:border-neutral-700 pt-4 mb-4">
<h6 class="font-bold mb-2">刷新结果</h6>
<div class="flex gap-3 mb-3 flex-wrap">
<span class="text-green-600 dark:text-green-400">未过期: <strong id="resultValid">0</strong></span>
<span class="text-blue-600 dark:text-blue-400">刷新成功: <strong id="resultRefreshed">0</strong></span>
<span class="text-red-500 dark:text-red-400">登录失败: <strong id="resultFailed">0</strong></span>
</div>
<div class="overflow-y-auto" style="max-height:300px">
<table class="data-table"><thead><tr><th>用户</th><th>状态</th><th>消息</th></tr></thead><tbody id="batchRefreshDetails"></tbody></table>
</div>
</div>
</div>
<div class="flex gap-3">
<button type="button" onclick="hideModal(&#39;batchRefreshModal&#39;)" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">关闭</button>
<button type="button" id="btnCheckOnly" onclick="batchCheckOnly()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition"><i class="bi bi-search"></i> 仅检查</button>
<button type="button" id="btnDoBatchRefresh" onclick="doBatchRefresh()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition"><i class="bi bi-arrow-clockwise"></i> 开始刷新</button>
</div>
</div>
</div>
</div>
<div id="singleRefreshModal" class="modal-overlay" onclick="if(event.target===this)hideModal(&#39;singleRefreshModal&#39;)">
<div class="modal-backdrop" onclick="hideModal(&#39;singleRefreshModal&#39;)"></div>
<div class="modal-panel">
<div class="glass rounded-2xl p-6 layer-4">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white flex items-center gap-2"><i class="bi bi-arrow-clockwise"></i> 刷新用户 Session</h3>
<button onclick="hideModal(&#39;singleRefreshModal&#39;)" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition"><i class="bi bi-x-lg"></i></button>
</div>
<div class="space-y-4">
<div><label class="input-label">用户</label><input type="text" class="input-field" id="singleRefreshUsername" readonly><input type="hidden" id="singleRefreshUserId"></div>
<div><label class="input-label">教务系统密码</label><input type="password" class="input-field" id="singleRefreshPassword" placeholder="请输入密码"></div>
<div class="flex items-center gap-2"><input type="checkbox" id="singleForceRefresh" class="w-4 h-4 rounded border-neutral-300 dark:border-neutral-600 accent-neutral-900 dark:accent-white"><label for="singleForceRefresh" class="text-sm text-neutral-700 dark:text-neutral-300">强制刷新(即使 session 有效)</label></div>
<div id="singleRefreshResult"></div>
</div>
<div class="flex gap-3 mt-6">
<button type="button" onclick="hideModal(&#39;singleRefreshModal&#39;)" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">取消</button>
<button type="button" id="btnDoSingleRefresh" onclick="doSingleRefresh()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition"><i class="bi bi-arrow-clockwise"></i> 刷新</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
let currentPage=1,allUsers=[];
function showModal(id){const m=document.getElementById(id);m.classList.add('open');document.body.style.overflow='hidden';}
function hideModal(id){const m=document.getElementById(id);m.classList.remove('open');document.body.style.overflow='';}
async function loadStats(){try{const d=await apiRequest('/api/admin/stats');if(d.success){document.getElementById('totalUsers').textContent=d.stats.total_users;document.getElementById('totalTasks').textContent=d.stats.total_tasks;document.getElementById('runningTasks').textContent=d.stats.running_tasks;document.getElementById('successTasks').textContent=d.stats.success_tasks;if(d.stats.session_stats){document.getElementById('sessionValid').textContent=d.stats.session_stats.valid||0;document.getElementById('sessionInvalid').textContent=d.stats.session_stats.invalid||0;document.getElementById('sessionUnknown').textContent=d.stats.session_stats.unknown||0;}}}catch(e){console.error(e);}}
async function loadUsers(page=1){currentPage=page;document.getElementById('loadingIndicator').style.display='block';document.getElementById('emptyState').style.display='none';document.getElementById('usersTableContainer').style.display='none';document.getElementById('pagination').style.display='none';try{const d=await apiRequest(`/api/admin/users/list?page=${page}&per_page=20`);document.getElementById('loadingIndicator').style.display='none';if(!d.success||!d.users||d.users.length===0){document.getElementById('emptyState').style.display='block';return;}allUsers=d.users;renderUsersTable(d.users);renderPagination(d.total,d.pages,page);document.getElementById('usersTableContainer').style.display='block';document.getElementById('pagination').style.display='block';}catch(e){document.getElementById('loadingIndicator').style.display='none';showToast('加载失败','error');}}
function renderUsersTable(users){const tbody=document.getElementById('usersTableBody');tbody.innerHTML=users.map(u=>`<tr><td>${u.id}</td><td><strong>${escapeHtml(u.username)}</strong></td><td>${u.jwxt_username?escapeHtml(u.jwxt_username):'<span class="text-neutral-400">-</span>'}</td><td>${u.session_status==='valid'?'<span class="status-badge status-success" title="更新时间: '+(u.session_updated_at?formatTime(u.session_updated_at):'未知')+'">有效</span>':u.session_status==='invalid'?'<span class="status-badge status-danger">过期</span>':'<span class="status-badge status-pending">未知</span>'}</td><td>${u.is_admin?'<span class="status-badge status-danger">管理员</span>':'<span class="status-badge status-pending">普通用户</span>'}</td><td>${u.is_active?'<span class="status-badge status-success">激活</span>':'<span class="status-badge status-pending">禁用</span>'}</td><td class="text-sm text-neutral-500">${formatTime(u.created_at)}</td><td><button class="btn-outline text-xs px-2 py-1" onclick="viewUserTasks(${u.id})" title="查看任务"><i class="bi bi-list-task"></i></button><button class="btn-outline text-xs px-2 py-1 ml-1" onclick="refreshUserSession(${u.id},'${u.jwxt_username||u.username}')" title="刷新Session"><i class="bi bi-arrow-clockwise"></i></button></td></tr>`).join('');}
function renderPagination(total,pages,current){const ul=document.getElementById('paginationList');let h='';h+=`<li class="page-item ${current===1?'disabled':''}"><a class="page-link" href="#" onclick="loadUsers(${current-1});return false;">上一页</a></li>`;for(let i=1;i<=pages;i++){if(i===1||i===pages||(i>=current-2&&i<=current+2)){h+=`<li class="page-item ${i===current?'active':''}"><a class="page-link" href="#" onclick="loadUsers(${i});return false;">${i}</a></li>`;}else if(i===current-3||i===current+3){h+=`<li class="page-item disabled"><span class="page-link">...</span></li>`;}}h+=`<li class="page-item ${current===pages?'disabled':''}"><a class="page-link" href="#" onclick="loadUsers(${current+1});return false;">下一页</a></li>`;ul.innerHTML=h;}
async function submitCreateUser(){const u=document.getElementById('newUsername').value.trim(),p=document.getElementById('newPassword').value,a=document.getElementById('newIsAdmin').checked;if(!u||!p){showToast('请填写完整信息','warning');return;}try{const d=await apiRequest('/api/admin/users/create',{method:'POST',body:JSON.stringify({username:u,password:p,is_admin:a})});if(d.success){showToast('用户创建成功','success');hideModal('createUserModal');document.getElementById('createUserForm').reset();loadUsers();loadStats();}else{showToast(d.message||'创建失败','error');}}catch(e){showToast('网络错误','error');}}
function viewUserTasks(id){window.location.href=`/tasks?user_id=${id}`;}
document.addEventListener('DOMContentLoaded',()=>{loadStats();loadUsers();});
async function batchCheckSession(){if(!confirm('开始批量检查所有用户的 Session 状态?'))return;showToast('正在检查 Session 状态...','info');try{const d=await apiRequest('/api/admin/session/batch_check',{method:'POST',body:JSON.stringify({})});if(d.success){const r=d.results;showToast(`检查完成:有效${r.valid}个,过期${r.invalid}个,未配置${r.no_account}个`,'success');loadStats();loadUsers();}else{showToast(d.message||'检查失败','error');}}catch(e){showToast('网络错误','error');}}
async function batchCheckOnly(){const btn=document.getElementById('btnCheckOnly');btn.disabled=true;btn.innerHTML='<i class="bi bi-search"></i> 检查中...';try{const d=await apiRequest('/api/admin/session/batch_check',{method:'POST',body:JSON.stringify({})});if(d.success){const results=d.results;document.getElementById('resultValid').textContent=results.valid;document.getElementById('resultRefreshed').textContent=0;document.getElementById('resultFailed').textContent=results.invalid+results.no_jwxt;const tbody=document.getElementById('batchRefreshDetails');tbody.innerHTML=results.details.map(d=>`<tr><td>${escapeHtml(d.username)}</td><td>${d.status==='valid'?'<span class="status-badge status-success">有效</span>':d.status==='no_jwxt'?'<span class="status-badge status-pending">未配置</span>':'<span class="status-badge status-danger">过期</span>'}</td><td class="text-sm text-neutral-500">${escapeHtml(d.message)||'-'}</td></tr>`).join('');document.getElementById('batchRefreshResult').style.display='block';loadStats();}}catch(e){showToast('检查失败','error');}finally{btn.disabled=false;btn.innerHTML='<i class="bi bi-search"></i> 仅检查';}}
async function doBatchRefresh(){const force=document.getElementById('batchForceRefresh').checked;const passwordMapText=document.getElementById('batchPasswordMap').value.trim();let passwordMap={};if(passwordMapText){try{passwordMap=JSON.parse(passwordMapText);}catch(e){showToast('密码映射 JSON 格式错误','warning');return;}}const btn=document.getElementById('btnDoBatchRefresh');btn.disabled=true;btn.innerHTML='<i class="bi bi-arrow-clockwise"></i> 刷新中...';try{const d=await apiRequest('/api/admin/session/batch_refresh',{method:'POST',body:JSON.stringify({force:force,password_map:passwordMap})});if(d.success){const results=d.results;document.getElementById('resultValid').textContent=results.valid;document.getElementById('resultRefreshed').textContent=results.refreshed;document.getElementById('resultFailed').textContent=results.failed+results.no_password;const tbody=document.getElementById('batchRefreshDetails');tbody.innerHTML=results.details.map(d=>`<tr><td>${escapeHtml(d.username)}</td><td>${d.status==='valid'?'<span class="status-badge status-success">有效</span>':d.status==='refreshed'?'<span class="status-badge status-info">已刷新</span>':d.status==='no_password'?'<span class="status-badge status-warning">无密码</span>':'<span class="status-badge status-danger">失败</span>'}</td><td class="text-sm text-neutral-500">${escapeHtml(d.message)||'-'}</td></tr>`).join('');document.getElementById('batchRefreshResult').style.display='block';showToast(`刷新完成:有效${results.valid}个,刷新${results.refreshed}个,失败${results.failed}个`,'success');loadStats();loadUsers();}else{showToast(d.message||'刷新失败','error');}}catch(e){showToast('网络错误','error');}finally{btn.disabled=false;btn.innerHTML='<i class="bi bi-arrow-clockwise"></i> 开始刷新';}}
function refreshUserSession(userId,username){document.getElementById('singleRefreshUserId').value=userId;document.getElementById('singleRefreshUsername').value=username;document.getElementById('singleRefreshPassword').value='';document.getElementById('singleForceRefresh').checked=false;document.getElementById('singleRefreshResult').innerHTML='';showModal('singleRefreshModal');}
async function doSingleRefresh(){const userId=document.getElementById('singleRefreshUserId').value;const password=document.getElementById('singleRefreshPassword').value.trim();const force=document.getElementById('singleForceRefresh').checked;if(!password){document.getElementById('singleRefreshResult').innerHTML='<div class="glass rounded-xl p-3 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200 text-sm">请输入密码</div>';return;}const btn=document.getElementById('btnDoSingleRefresh');btn.disabled=true;btn.innerHTML='<i class="bi bi-arrow-clockwise"></i> 刷新中...';try{const d=await apiRequest(`/api/admin/users/${userId}/session/refresh`,{method:'POST',body:JSON.stringify({jwxt_password:password,force:force})});if(d.success){document.getElementById('singleRefreshResult').innerHTML=`<div class="glass rounded-xl p-3 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 text-sm">${d.message}</div>`;setTimeout(()=>{hideModal('singleRefreshModal');loadStats();loadUsers();},1500);}else{document.getElementById('singleRefreshResult').innerHTML=`<div class="glass rounded-xl p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 text-sm">${d.message}</div>`;}}catch(e){document.getElementById('singleRefreshResult').innerHTML='<div class="glass rounded-xl p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 text-sm">刷新失败</div>';}finally{btn.disabled=false;btn.innerHTML='<i class="bi bi-arrow-clockwise"></i> 刷新';}}
</script>
{% endblock %}
+76
View File
@@ -0,0 +1,76 @@
{% extends "base_tailwind.html" %}
{% block title %}API 调用示例 - {{ brand_name }}{% endblock %}
{% block extra_css %}
<style>
.prose h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }
.prose h2 { font-size: 1.1rem; font-weight: 700; margin-top: 2rem; margin-bottom: 0.75rem; padding-bottom: 0.4rem; border-bottom: 1px solid rgba(0,0,0,0.08); }
.dark .prose h2 { border-bottom-color: rgba(255,255,255,0.08); }
.prose h3 { font-size: 0.95rem; font-weight: 600; margin-top: 1.25rem; margin-bottom: 0.5rem; }
.prose p { margin-bottom: 0.75rem; line-height: 1.75; color: #4b5563; }
.dark .prose p { color: #9ca3af; }
.prose ul, .prose ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.prose li { margin-bottom: 0.35rem; line-height: 1.7; color: #4b5563; }
.dark .prose li { color: #9ca3af; }
.prose ul li { list-style-type: disc; }
.prose ol li { list-style-type: decimal; }
.prose strong { font-weight: 600; color: #111827; }
.dark .prose strong { color: #f3f4f6; }
.prose table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.875rem; }
.prose th { background: #f3f4f6; font-weight: 600; padding: 0.6rem 0.8rem; text-align: left; border: 1px solid #e5e7eb; }
.dark .prose th { background: #1f2937; border-color: #374151; }
.prose td { padding: 0.6rem 0.8rem; border: 1px solid #e5e7eb; }
.dark .prose td { border-color: #374151; }
.prose hr { border: none; border-top: 1px solid #e5e7eb; margin: 1.5rem 0; }
.dark .prose hr { border-top-color: #374151; }
.prose code { background: #f3f4f6; padding: 0.1em 0.4em; border-radius: 4px; font-size: 0.85em; }
.dark .prose code { background: #1f2937; }
.prose blockquote { border-left: 3px solid #e5e7eb; padding-left: 1rem; color: #6b7280; margin: 1rem 0; }
.dark .prose blockquote { border-color: #374151; color: #9ca3af; }
/* 代码块样式 */
.prose pre { background: #1e293b; color: #e2e8f0; border-radius: 0.75rem; padding: 1rem 1.25rem; overflow-x: auto; margin: 1rem 0; font-size: 0.8rem; line-height: 1.6; }
.prose pre code { background: transparent; padding: 0; color: inherit; font-size: inherit; }
</style>
{% endblock %}
{% block content %}
<div class="max-w-3xl mx-auto py-4">
<!-- 返回 -->
<div class="mb-6 list-item-enter" style="animation-delay:0ms">
<a href="javascript:history.back()" class="inline-flex items-center gap-1.5 text-sm text-neutral-500 hover:text-neutral-800 dark:hover:text-neutral-200 transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
返回
</a>
</div>
<div class="glass rounded-3xl p-6 md:p-10 layer-3 list-item-enter" style="animation-delay:50ms">
<!-- 头部 -->
<div class="flex items-start gap-4 mb-8 pb-6 border-b border-neutral-200 dark:border-neutral-800">
<div class="w-12 h-12 rounded-2xl bg-black dark:bg-white flex items-center justify-center text-white dark:text-black flex-shrink-0">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="16 3 21 3 21 8"/><line x1="4" y1="20" x2="21" y2="3"/>
<polyline points="21 16 21 21 16 21"/><line x1="15" y1="15" x2="21" y2="21"/>
<line x1="4" y1="4" x2="9" y2="9"/>
</svg>
</div>
<div>
<h1 class="text-xl md:text-2xl font-bold text-neutral-900 dark:text-white">API 调用示例</h1>
<p class="text-sm text-neutral-500 dark:text-neutral-400 mt-1">常见场景的 Python 示例代码</p>
</div>
</div>
<!-- 正文:由后端读取 docs/api_examples.md 渲染 -->
<div class="prose text-sm md:text-base text-neutral-800 dark:text-neutral-200">
{{ content | safe }}
</div>
<!-- 底部链接 -->
<div class="mt-8 pt-6 border-t border-neutral-200 dark:border-neutral-800 flex gap-4 text-sm text-neutral-500">
<a href="{{ url_for('main.page_api_playground') }}" class="hover:text-black dark:hover:text-white transition-colors underline underline-offset-2">API 接口测试</a>
</div>
</div>
</div>
{% endblock %}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+156
View File
@@ -0,0 +1,156 @@
{% extends "base_tailwind.html" %}
{% block title %}{% if block_type == 'foreign' %}访问受限 - {{ brand_name }}{% else %}IP 已被封禁 - {{ brand_name }}{% endif %}{% endblock %}
{% block content %}
<div class="min-h-[80vh] flex items-center justify-center px-4 py-8">
<div class="max-w-md w-full space-y-6">
<!-- 主卡片 -->
<div class="glass rounded-2xl p-8 layer-2 list-item-enter">
<!-- 图标 -->
<div class="w-20 h-20 mx-auto mb-6 rounded-full flex items-center justify-center
{% if block_type == 'foreign' %}bg-amber-100 dark:bg-amber-900/30{% else %}bg-red-100 dark:bg-red-900/30{% endif %}">
{% if block_type == 'foreign' %}
<svg class="w-10 h-10 text-amber-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
{% else %}
<svg class="w-10 h-10 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"></path>
</svg>
{% endif %}
</div>
<!-- 标题 -->
<h1 class="text-2xl font-bold text-neutral-900 dark:text-white text-center mb-2">
{% if block_type == 'foreign' %}访问受限{% else %}IP 已被封禁{% endif %}
</h1>
<!-- 副标题 -->
<p class="text-neutral-500 dark:text-neutral-400 text-sm text-center mb-6">
{% if block_type == 'foreign' %}
本服务仅对中国大陆用户开放
{% else %}
您的 IP 地址已被系统封禁
{% endif %}
</p>
<!-- 提示框 -->
<div class="{% if block_type == 'foreign' %}bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800{% else %}bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800{% endif %}
rounded-2xl p-4 mb-6">
{% if block_type == 'foreign' %}
<p class="text-amber-800 dark:text-amber-300 text-sm font-medium mb-3 flex items-center gap-2">
<svg class="w-4 h-4 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"></path>
</svg>
检测到您正在使用 VPN 或境外网络
</p>
<ul class="text-amber-700 dark:text-amber-400 text-sm space-y-2">
<li class="flex items-start gap-2">
<span class="mt-0.5 w-1.5 h-1.5 rounded-full bg-amber-500 flex-shrink-0"></span>
请关闭 VPN、代理等翻墙工具后重试
</li>
<li class="flex items-start gap-2">
<span class="mt-0.5 w-1.5 h-1.5 rounded-full bg-amber-500 flex-shrink-0"></span>
请关闭浏览器的代理设置
</li>
<li class="flex items-start gap-2">
<span class="mt-0.5 w-1.5 h-1.5 rounded-full bg-amber-500 flex-shrink-0"></span>
如使用手机,请检查是否开启了加速器
</li>
<li class="flex items-start gap-2">
<span class="mt-0.5 w-1.5 h-1.5 rounded-full bg-amber-500 flex-shrink-0"></span>
关闭后请刷新本页面重试
</li>
</ul>
{% else %}
<p class="text-red-800 dark:text-red-300 text-sm font-medium mb-2 flex items-center gap-2">
<svg class="w-4 h-4 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
</svg>
封禁原因
</p>
<p class="text-red-700 dark:text-red-400 text-sm">{{ reason }}</p>
{% if expires_at %}
<!-- 解封倒计时 -->
<div class="mt-4 pt-4 border-t border-red-200 dark:border-red-800">
<div class="flex items-center justify-between text-sm">
<span class="text-red-600 dark:text-red-400 font-medium">预计解封时间</span>
<span id="countdown" class="font-mono font-bold text-red-700 dark:text-red-300"></span>
</div>
</div>
{% endif %}
{% endif %}
</div>
<!-- IP信息 -->
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3 mb-6">
<p class="text-neutral-400 dark:text-neutral-500 text-xs mb-1">您的 IP 地址</p>
<p class="text-neutral-700 dark:text-neutral-200 font-mono text-sm font-bold">{{ ip }}</p>
</div>
<!-- 操作按钮 -->
<button onclick="location.reload()"
class="w-full py-3 px-6 bg-neutral-900 dark:bg-white text-white dark:text-neutral-900 rounded-2xl font-medium
hover:shadow-lg transition-colors duration-200 mb-3">
{% if block_type == 'foreign' %}关闭 VPN 后点此重试{% else %}刷新页面{% endif %}
</button>
<p class="text-neutral-400 dark:text-neutral-500 text-xs text-center">
如有疑问,请联系管理员
</p>
</div>
<!-- 底部说明 -->
<p class="text-center text-neutral-400 dark:text-neutral-500 text-xs">
{{ brand_name }} · 仅限中国大陆用户访问
</p>
</div>
</div>
{% if block_type != 'foreign' and expires_at %}
<script>
document.addEventListener('DOMContentLoaded', function() {
var countdownEl = document.getElementById('countdown');
if (!countdownEl) return;
// expires_at 是 Unix 时间戳(服务器UTC),Date.now() 也是 UTC 毫秒
// 直接相减,无需任何时区转换
var expiresAtMs = {{ expires_at }} * 1000;
function updateCountdown() {
var nowMs = Date.now();
var diff = expiresAtMs - nowMs;
if (diff <= 0) {
countdownEl.textContent = '已解封,刷新页面';
location.reload();
return;
}
var totalSeconds = Math.floor(diff / 1000);
var hours = Math.floor(totalSeconds / 3600);
var minutes = Math.floor((totalSeconds % 3600) / 60);
var seconds = totalSeconds % 60;
if (hours > 24) {
var days = Math.floor(hours / 24);
countdownEl.textContent = days + '天 ' + (hours % 24) + '小时';
} else if (hours > 0) {
countdownEl.textContent = hours + '小时 ' + minutes + '分 ' + seconds + '秒';
} else if (minutes > 0) {
countdownEl.textContent = minutes + '分 ' + seconds + '秒';
} else {
countdownEl.textContent = seconds + '秒';
}
}
updateCountdown();
setInterval(updateCountdown, 1000);
});
</script>
{% endif %}
{% endblock %}
File diff suppressed because it is too large Load Diff
+217
View File
@@ -0,0 +1,217 @@
{% 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; }
</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="3" width="18" height="18" rx="2" ry="2"/>
<line x1="3" y1="9" x2="21" y2="9"/>
<line x1="9" y1="21" x2="9" y2="9"/>
</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">
<input id="buildingInput" type="text" placeholder="楼号(可选)" class="px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm w-28">
<input id="roomInput" type="text" placeholder="教室编号(可选)" class="px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm w-32">
<button onclick="refresh()"
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">
刷新
</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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden">
<p id="errorText" class="text-red-500"></p>
</div>
<!-- 图表区域 -->
<div id="chartsRow" class="hidden grid grid-cols-1 gap-4 mb-4 list-item-enter" style="animation-delay: 120ms;">
<div class="glass rounded-2xl p-4">
<h4 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">教学楼课程分布</h4>
<div id="buildingChart" style="height: 280px;"></div>
</div>
</div>
<div id="dataContainer" class="hidden list-item-enter" style="animation-delay: 150ms;">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">序号</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">校区</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">教学楼</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">教室</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">课程名称</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">教师</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">上课时间</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">周次</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden">
<p class="text-gray-500 dark:text-gray-400 text-lg">暂无场地课表</p>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
// ─── Session 自动刷新 ────────────────────────────────────────────
async function initSession() {
try {
const res = await fetch('/api/jwxt/ping');
const data = await res.json();
if (data.refreshed) console.log('[Session] 已刷新');
return true;
} catch (e) { console.warn('[Session] ping 失败:', e); return false; }
}
function isDarkMode() { return document.documentElement.classList.contains('dark'); }
// ─── ECharts 图表 ─────────────────────────────────────────────────
let buildingChart = null;
function renderBuildingChart(items) {
const container = document.getElementById('chartsRow');
if (!container || !items.length) return;
container.classList.remove('hidden');
const dom = document.getElementById('buildingChart');
if (!dom) return;
// 按教学楼统计
const buildingMap = {};
items.forEach(item => {
const b = item.jxlmc || item.JXLMC || item['教学楼'] || '未知';
buildingMap[b] = (buildingMap[b] || 0) + 1;
});
const sorted = Object.entries(buildingMap).sort((a, b) => b[1] - a[1]);
const dark = isDarkMode();
if (!buildingChart) buildingChart = echarts.init(dom);
buildingChart.setOption({
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
grid: { left: '3%', right: '10%', top: 10, bottom: 30, containLabel: true },
xAxis: {
type: 'category', data: sorted.map(s => s[0]),
axisLabel: { color: dark ? '#9ca3af' : '#6b7280', fontSize: 11, rotate: sorted.length > 6 ? 30 : 0 }
},
yAxis: {
type: 'value', name: '课程数',
nameTextStyle: { color: dark ? '#9ca3af' : '#6b7280' },
axisLabel: { color: dark ? '#9ca3af' : '#6b7280' }
},
series: [{
type: 'bar', data: sorted.map(s => s[1]),
itemStyle: { color: dark ? '#818cf8' : '#4f46e5', borderRadius: [6, 6, 0, 0] },
emphasis: { itemStyle: { color: dark ? '#a5b4fc' : '#6366f1' } }
}]
}, { notMerge: true });
buildingChart.resize();
}
function setupDarkObserver() {
const observer = new MutationObserver(() => {
if (buildingChart) { buildingChart.dispose(); buildingChart = null; }
const items = window._lastItems;
if (items && items.length) renderBuildingChart(items);
});
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
window.addEventListener('resize', () => {
if (buildingChart) buildingChart.resize();
});
// ─── 数据加载 ─────────────────────────────────────────────────────
async function refresh() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
const chartsRow = document.getElementById('chartsRow');
if (chartsRow) chartsRow.classList.add('hidden');
const lh = document.getElementById('buildingInput').value;
const cdbh = document.getElementById('roomInput').value;
try {
const params = new URLSearchParams({ page_size: 200 });
if (lh) params.set('lh', lh);
if (cdbh) params.set('cdbh', cdbh);
const res = await fetch('/api/jwxt/classroom-schedule?' + params);
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) {
document.getElementById('errorText').textContent = data.message || '查询失败';
document.getElementById('errorMessage').classList.remove('hidden');
return;
}
const items = data.items || [];
window._lastItems = items;
if (!items.length) {
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('emptyState').classList.remove('hidden');
return;
}
renderTable(items);
document.getElementById('dataContainer').classList.remove('hidden');
renderBuildingChart(items);
} catch (e) {
document.getElementById('loadingIndicator').classList.add('hidden');
document.getElementById('errorText').textContent = '网络错误: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
function renderTable(items) {
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, idx) => `
<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors row-animate" style="animation-delay:${idx * 40}ms;">
<td class="py-3 px-4 text-gray-400 dark:text-gray-500">${idx + 1}</td>
<td class="py-3 px-4">${item.xqhmc || item.XQHMC || item['校区'] || '--'}</td>
<td class="py-3 px-4">${item.jxlmc || item.JXLMC || item['教学楼'] || '--'}</td>
<td class="py-3 px-4 font-medium">${item.cdmc || item.CDMC || item['教室'] || '--'}</td>
<td class="py-3 px-4">${item.kcmc || item.KCMC || item['课程名称'] || '--'}</td>
<td class="py-3 px-4">${item.jsmc || item.JSMC || item.jsxm || item['教师'] || '--'}</td>
<td class="py-3 px-4 text-gray-500 dark:text-gray-400">${item.sksj || item.SKSJ || item['上课时间'] || '--'}</td>
<td class="py-3 px-4 text-center text-gray-500 dark:text-gray-400">${item.zcsm || item.ZCSM || item['周次'] || '--'}</td>
</tr>
`).join('');
}
// ─── 初始化 ───────────────────────────────────────────────────────
initSession().then(() => {
setupDarkObserver();
refresh();
});
</script>
{% endblock %}
+638
View File
@@ -0,0 +1,638 @@
{% 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; }
select.filter-select {
appearance: none;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: right 10px center;
padding-right: 28px;
}
.dark select.filter-select {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
}
.jyfs-radio { transition: all 0.2s; user-select: none; }
.jyfs-radio:not(.active) { background: transparent; color: inherit; }
.jyfs-radio.active { background: #000; color: #fff; }
.dark .jyfs-radio.active { background: #fff; color: #000; }
.time-chip {
display: inline-flex; align-items: center; justify-content: center;
min-width: 34px; height: 30px; padding: 0 8px;
border-radius: 6px; border: 1px solid #d1d5db;
font-size: 12px; cursor: pointer; user-select: none;
transition: all 0.15s; background: transparent;
}
.dark .time-chip { border-color: #374151; }
.time-chip:hover { border-color: #6b7280; }
.time-chip.selected { background: #000; color: #fff; border-color: #000; }
.dark .time-chip.selected { background: #fff; color: #000; border-color: #fff; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
}
</style>
{% endblock %}
{% block content %}
<div>
<!-- Header -->
<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="3" width="18" height="18" rx="2" ry="2"/>
<line x1="3" y1="9" x2="21" y2="9"/>
<line x1="9" y1="21" x2="9" y2="9"/>
</svg>
空闲教室查询
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">查询当前可用的空闲教室</p>
</div>
<button onclick="doSearch()"
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>
<!-- Filter Bar -->
<div class="glass rounded-2xl p-4 mb-4 list-item-enter max-w-5xl mx-auto" style="animation-delay: 50ms;">
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3 items-end">
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">校区</label>
<select id="filter_xqh_id" class="filter-select w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
<option value="">加载中...</option>
</select>
</div>
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">楼号</label>
<select id="filter_lh" class="filter-select w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
<option value="">加载中...</option>
</select>
</div>
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">场地类别</label>
<select id="filter_cdlb_id" class="filter-select w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
<option value="">加载中...</option>
</select>
</div>
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">二级类别</label>
<select id="filter_cdejlb_id" class="filter-select w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
<option value="">加载中...</option>
</select>
</div>
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">座位 ≥</label>
<input id="filter_qszws" type="number" min="0" placeholder="不限"
class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
</div>
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">座位 ≤</label>
<input id="filter_jszws" type="number" min="0" placeholder="不限"
class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
</div>
<div class="w-full">
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">教室名称</label>
<input id="filter_cdmc" type="text" placeholder="模糊搜索"
class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">
</div>
<button id="searchBtn" onclick="doSearch()"
class="px-5 py-2 rounded-lg bg-black dark:bg-white text-white dark:text-black text-sm font-medium hover:opacity-85 transition-opacity whitespace-nowrap flex-shrink-0"
disabled>
查询
</button>
</div>
</div>
<!-- jyfs 模式选择 -->
<div class="glass rounded-2xl p-4 mb-4 list-item-enter" style="animation-delay: 80ms;">
<div class="flex items-center gap-2">
<span class="text-xs font-medium text-gray-500 dark:text-gray-400 mr-2">查询模式</span>
<div class="flex rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden">
<label class="jyfs-radio px-4 py-1.5 text-sm cursor-pointer border-r border-gray-200 dark:border-gray-700 bg-black dark:bg-white text-white dark:text-black" data-jyfs="0">
<input type="radio" name="jyfs" value="0" class="hidden"> 按周次
</label>
<label class="jyfs-radio px-4 py-1.5 text-sm cursor-pointer border-r border-gray-200 dark:border-gray-700" data-jyfs="1">
<input type="radio" name="jyfs" value="1" class="hidden" checked> 连续
</label>
<label class="jyfs-radio px-4 py-1.5 text-sm cursor-pointer" data-jyfs="2">
<input type="radio" name="jyfs" value="2" class="hidden"> 按节次
</label>
</div>
</div>
</div>
<!-- 时间选择器区域 -->
<div id="timeSelectors" class="hidden">
<!-- jyfs=0: 周次 + 星期 + 节次 -->
<div id="timeSection_0" class="hidden">
<div class="glass rounded-2xl p-4 mb-4">
<div class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">周次</div>
<div class="flex gap-1 flex-wrap mb-1">
<button class="week-select-all text-xs text-blue-500 hover:text-blue-600 px-2 py-0.5" data-select="all">全选</button>
<button class="week-select-all text-xs text-gray-400 hover:text-gray-500 px-2 py-0.5" data-select="none">清空</button>
</div>
<div id="weekCheckboxes" class="flex flex-wrap gap-1.5"></div>
</div>
<div class="glass rounded-2xl p-4 mb-4">
<div class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">星期</div>
<div class="flex gap-1 flex-wrap mb-1">
<button class="day-select-all text-xs text-blue-500 hover:text-blue-600 px-2 py-0.5" data-select="all">全选</button>
<button class="day-select-all text-xs text-gray-400 hover:text-gray-500 px-2 py-0.5" data-select="none">清空</button>
</div>
<div id="dayCheckboxes" class="flex flex-wrap gap-1.5"></div>
</div>
<div class="glass rounded-2xl p-4 mb-4">
<div class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">节次</div>
<div class="flex gap-1 flex-wrap mb-1">
<button class="period-select-all text-xs text-blue-500 hover:text-blue-600 px-2 py-0.5" data-select="all">全选</button>
<button class="period-select-all text-xs text-gray-400 hover:text-gray-500 px-2 py-0.5" data-select="none">清空</button>
</div>
<div id="periodCheckboxes_0" class="flex flex-wrap gap-1.5"></div>
</div>
</div>
<!-- jyfs=2: 仅节次 -->
<div id="timeSection_2" class="hidden">
<div class="glass rounded-2xl p-4 mb-4">
<div class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">节次</div>
<div class="flex gap-1 flex-wrap mb-1">
<button class="period-select-all2 text-xs text-blue-500 hover:text-blue-600 px-2 py-0.5" data-select="all">全选</button>
<button class="period-select-all2 text-xs text-gray-400 hover:text-gray-500 px-2 py-0.5" data-select="none">清空</button>
</div>
<div id="periodCheckboxes_2" class="flex flex-wrap gap-1.5"></div>
</div>
</div>
</div>
<!-- Loading -->
<div id="loadingIndicator" class="text-center py-12 hidden">
<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="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="buildingChart" class="h-72"></div>
</div>
</div>
<!-- Error -->
<div id="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden">
<p id="errorText" class="text-red-500"></p>
</div>
<!-- Data Container -->
<div id="dataContainer" class="hidden list-item-enter" style="animation-delay: 150ms;">
<div class="glass rounded-2xl overflow-hidden">
<div id="resultSummary" class="px-5 py-3 text-sm text-gray-500 dark:text-gray-400 border-b border-gray-200 dark:border-gray-700 hidden"></div>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">序号</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">校区</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">教学楼</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">教室名称</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">编号</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">类型</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">座位</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">楼层</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">学院</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<!-- Empty State -->
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden">
<p class="text-gray-500 dark:text-gray-400 text-lg">暂无空闲教室</p>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
let paramsReady = false;
let defaultXnm = '', defaultXqm = '', defaultXqhId = '1';
let buildingChart = 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; }
}
// ── jyfs mode management ──
let currentJyfs = '1'; // 默认连续
let periodData = null; // 节次数据缓存
function setJyfs(mode) {
currentJyfs = mode;
// 更新 radio 样式
document.querySelectorAll('.jyfs-radio').forEach(el => {
el.classList.toggle('active', el.dataset.jyfs === mode);
const inp = el.querySelector('input');
if (inp) inp.checked = (el.dataset.jyfs === mode);
});
// 显示/隐藏时间选择器
const ts = document.getElementById('timeSelectors');
document.querySelectorAll('[id^="timeSection_"]').forEach(s => s.classList.add('hidden'));
if (mode === '0') {
ts.classList.remove('hidden');
document.getElementById('timeSection_0').classList.remove('hidden');
} else if (mode === '2') {
ts.classList.remove('hidden');
document.getElementById('timeSection_2').classList.remove('hidden');
} else {
ts.classList.add('hidden');
}
}
// ── 节次/周次 chip 渲染 ──
function renderPeriodChips(periods, containerId, defaultSelected) {
const container = document.getElementById(containerId);
if (!container) return;
// 按时段分组
let html = '';
let lastRsd = '';
periods.forEach(p => {
const jcmc = p.JCMC; // 1-11
const sjd = p.SJD;
const rsd = p.RSDMC; // 上午/下午/晚上
if (rsd !== lastRsd) {
if (lastRsd) html += '<div class="w-full h-0"></div>'; // break line
html += `<span class="text-[10px] text-gray-400 dark:text-gray-500 mr-1 self-center">${rsd}</span>`;
lastRsd = rsd;
}
const sel = defaultSelected ? ' selected' : '';
html += `<span class="time-chip${sel}" data-value="${jcmc}" data-label="${jcmc}节 ${sjd}" title="${jcmc}节 ${sjd}">${jcmc}</span>`;
});
container.innerHTML = html;
// 绑定点击
container.querySelectorAll('.time-chip').forEach(chip => {
chip.addEventListener('click', () => chip.classList.toggle('selected'));
});
}
function renderWeekChips(weeks, containerId, defaultSelected) {
const container = document.getElementById(containerId);
if (!container) return;
container.innerHTML = weeks.map(w => {
const n = w.dxqzc;
const sel = defaultSelected ? ' selected' : '';
return `<span class="time-chip${sel}" data-value="${n}" title="第${n}周">${n}</span>`;
}).join('');
container.querySelectorAll('.time-chip').forEach(chip => {
chip.addEventListener('click', () => chip.classList.toggle('selected'));
});
}
function renderDayChips(containerId, defaultSelected) {
const container = document.getElementById(containerId);
if (!container) return;
const days = [
{v: 1, l: '一'}, {v: 2, l: '二'}, {v: 3, l: '三'},
{v: 4, l: '四'}, {v: 5, l: '五'}, {v: 6, l: '六'}, {v: 7, l: '日'}
];
const defSet = defaultSelected ? new Set([1,2,3,4,5]) : new Set();
container.innerHTML = days.map(d => {
const sel = defSet.has(d.v) ? ' selected' : '';
return `<span class="time-chip${sel}" data-value="${d.v}" title="星期${d.l}">${d.l}</span>`;
}).join('');
container.querySelectorAll('.time-chip').forEach(chip => {
chip.addEventListener('click', () => chip.classList.toggle('selected'));
});
}
// ── 位掩码计算 ──
function calcBitmask(containerId) {
const container = document.getElementById(containerId);
if (!container) return '';
let mask = 0;
container.querySelectorAll('.time-chip.selected').forEach(chip => {
mask += Math.pow(2, parseInt(chip.dataset.value) - 1);
});
return mask > 0 ? String(mask) : '';
}
function calcCommaList(containerId) {
const container = document.getElementById(containerId);
if (!container) return '';
const vals = [];
container.querySelectorAll('.time-chip.selected').forEach(chip => {
vals.push(chip.dataset.value);
});
return vals.join(',');
}
// ── Init: load dropdowns from教务 page ──
async function loadParams() {
try {
const res = await fetch('/api/jwxt/classroom/params');
const data = await res.json();
if (!data.success || !data.selects) {
throw new Error(data.message || '获取下拉框参数失败');
}
fillSelect('filter_xqh_id', data.selects.xqh_id, true);
fillSelect('filter_lh', data.selects.lh, true);
fillSelect('filter_cdlb_id', data.selects.cdlb_id, true);
fillSelect('filter_cdejlb_id', data.selects.cdejlb_id, true);
defaultXnm = data.default_xnm || '';
defaultXqm = data.default_xqm || '';
// 获取默认校区ID用于节次查询
const xqhSel = data.selects.xqh_id;
if (xqhSel && xqhSel.default) defaultXqhId = xqhSel.default;
// 并行加载周次和节次数据
await Promise.all([loadWeekData(), loadPeriodData()]);
paramsReady = true;
document.getElementById('searchBtn').disabled = false;
doSearch();
} catch (e) {
document.getElementById('errorText').textContent = '加载参数失败: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
async function loadWeekData() {
try {
const res = await fetch(`/api/jwxt/classroom-filter-options?xnm=${defaultXnm}&xqm=${defaultXqm}`);
const data = await res.json();
if (data.success && data.items && data.items.nxqzcList) {
const weeks = data.items.nxqzcList;
const dqzcxq = data.items.dqzcxq || {};
const dqzc = parseInt(dqzcxq.DQZC) || 1;
// 默认选中当前周
const isDefault = true;
renderWeekChips(weeks, 'weekCheckboxes', isDefault);
// 全选/清空按钮
bindSelectAll('weekCheckboxes', '.week-select-all');
}
} catch (e) { console.warn('加载周次数据失败:', e); }
}
async function loadPeriodData() {
try {
const res = await fetch(`/api/jwxt/classroom-periods?xnm=${defaultXnm}&xqm=${defaultXqm}&xqh_id=${defaultXqhId}`);
const data = await res.json();
if (data.success && data.jcList) {
periodData = data.jcList;
renderPeriodChips(periodData, 'periodCheckboxes_0', true);
renderPeriodChips(periodData, 'periodCheckboxes_2', true);
bindSelectAll('periodCheckboxes_0', '.period-select-all');
bindSelectAll('periodCheckboxes_2', '.period-select-all2');
renderDayChips('dayCheckboxes', true);
bindSelectAll('dayCheckboxes', '.day-select-all');
}
} catch (e) { console.warn('加载节次数据失败:', e); }
}
function bindSelectAll(containerId, btnSelector) {
document.querySelectorAll(btnSelector).forEach(btn => {
btn.addEventListener('click', () => {
const action = btn.dataset.select;
const container = document.getElementById(containerId);
if (!container) return;
container.querySelectorAll('.time-chip').forEach(chip => {
if (action === 'all') chip.classList.add('selected');
else chip.classList.remove('selected');
});
});
});
}
function fillSelect(id, selectData, addAll) {
const el = document.getElementById(id);
if (!selectData || !selectData.options || !selectData.options.length) {
el.innerHTML = '<option value="">--</option>';
return;
}
const defaultVal = selectData.default || '';
let html = '';
if (addAll) html += '<option value="">全部</option>';
html += selectData.options.map(o =>
`<option value="${escAttr(o.value)}" ${o.value === defaultVal ? 'selected' : ''}>${escHtml(o.label)}</option>`
).join('');
el.innerHTML = html;
}
// ── jyfs radio event binding ──
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.jyfs-radio').forEach(el => {
el.addEventListener('click', () => setJyfs(el.dataset.jyfs));
});
// init with default mode
setJyfs('1');
});
// ── Search ──
async function doSearch() {
if (!paramsReady) return;
showLoading();
const params = new URLSearchParams();
if (defaultXnm) params.append('xnm', defaultXnm);
if (defaultXqm) params.append('xqm', defaultXqm);
params.append('page_size', '200');
params.append('jyfs', currentJyfs);
// Append filter values (only non-empty)
['xqh_id','lh','cdlb_id','cdejlb_id','qszws','jszws','cdmc'].forEach(name => {
const val = document.getElementById('filter_' + name).value.trim();
if (val) params.append(name, val);
});
// Time selectors based on jyfs mode
if (currentJyfs === '0') {
// 按周次: zcd(bitmask) + xqj(comma) + jcd(bitmask)
const zcd = calcBitmask('weekCheckboxes');
const xqj = calcCommaList('dayCheckboxes');
const jcd = calcBitmask('periodCheckboxes_0');
if (zcd) params.append('zcd', zcd);
if (xqj) params.append('xqj', xqj);
if (jcd) params.append('jcd', jcd);
} else if (currentJyfs === '2') {
// 按节次: jcd(bitmask)
const jcd = calcBitmask('periodCheckboxes_2');
if (jcd) params.append('jcd', jcd);
}
// jyfs=1 (连续): 不需要额外时间参数
try {
const res = await fetch('/api/jwxt/classrooms?' + params.toString());
const data = await res.json();
hideLoading();
if (!data.success) {
showError(data.message || '查询失败');
return;
}
const items = data.items || [];
if (!items.length) {
showEmpty('暂无符合条件的空闲教室');
return;
}
renderTable(items);
} catch (e) {
hideLoading();
showError('网络错误: ' + e.message);
}
}
// ── Render ──
function renderTable(items) {
const summary = document.getElementById('resultSummary');
summary.textContent = `共 ${items.length} 间教室`;
summary.classList.remove('hidden');
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, idx) => {
const xqmc = item.xqmc || item.xqhmc || item.XQHMC || '--';
const jxlmc = item.jxlmc || item.JXLMC || '--';
const cdmc = item.cdmc || item.CDMC || '--';
const cdbh = item.cdbh || '--';
const cdlbmc = item.cdlbmc || item.CDLBMC || '--';
const zws = item.zws || item.kszws1 || item.ZWS || '--';
const lch = item.lch || '--';
const jgmc = item.jgmc || item.JGMC || '--';
return `
<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors row-animate" style="animation-delay:${idx * 30}ms;">
<td class="py-3 px-4 text-gray-400 dark:text-gray-500">${idx + 1}</td>
<td class="py-3 px-4">${escHtml(xqmc)}</td>
<td class="py-3 px-4">${escHtml(jxlmc)}</td>
<td class="py-3 px-4 font-medium">${escHtml(cdmc)}</td>
<td class="py-3 px-4 text-gray-500 text-xs">${escHtml(cdbh)}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(cdlbmc)}</td>
<td class="py-3 px-4 text-center">${escHtml(zws)}</td>
<td class="py-3 px-4 text-gray-400 dark:text-gray-500 text-xs">${escHtml(lch)}</td>
<td class="py-3 px-4 text-gray-500 text-xs">${escHtml(jgmc)}</td>
</tr>
`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('emptyState').classList.add('hidden');
// 渲染图表
const chartsRow = document.getElementById('chartsRow');
chartsRow.classList.remove('hidden');
renderBuildingChart(items);
setupDarkObserver(items);
}
// ── Helpers ──
function showLoading() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
}
function hideLoading() { document.getElementById('loadingIndicator').classList.add('hidden'); }
function showError(msg) {
document.getElementById('errorText').textContent = msg;
document.getElementById('errorMessage').classList.remove('hidden');
}
function showEmpty(msg) {
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.remove('hidden');
document.getElementById('emptyState').querySelector('p').textContent = msg;
}
// ── 各楼栋空闲教室数量柱状图 ──
function renderBuildingChart(items) {
const container = document.getElementById('buildingChart');
if (!container) return;
if (!buildingChart) buildingChart = echarts.init(container);
const buildingCount = {};
items.forEach(item => {
const building = item.jxlmc || item.JXLMC || '未知';
buildingCount[building] = (buildingCount[building] || 0) + 1;
});
const entries = Object.entries(buildingCount).sort((a, b) => b[1] - a[1]);
const dark = isDarkMode();
buildingChart.setOption({
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
grid: { left: '3%', right: '4%', bottom: '3%', top: '5%', containLabel: true },
xAxis: { type: 'value', name: '间数', minInterval: 1, nameTextStyle: { fontSize: 11 } },
yAxis: { type: 'category', data: entries.map(e => e[0]), axisLabel: { fontSize: 11 }, inverse: true },
series: [{
type: 'bar', data: entries.map(e => e[1]),
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
{ offset: 0, color: dark ? '#a78bfa' : '#8b5cf6' },
{ offset: 1, color: dark ? '#60a5fa' : '#3b82f6' }
])
},
barMaxWidth: 28,
label: { show: true, position: 'right', fontSize: 11, color: dark ? '#9ca3af' : '#6b7280' }
}]
}, true);
}
// ── 深色模式观察者 ──
let _darkObserver = null;
let _lastClassroomItems = null;
function setupDarkObserver(items) {
_lastClassroomItems = items;
if (_darkObserver) return;
_darkObserver = new MutationObserver(() => {
if (_lastClassroomItems && _lastClassroomItems.length > 0) {
renderBuildingChart(_lastClassroomItems);
}
});
_darkObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
window.addEventListener('resize', () => { buildingChart?.resize(); });
function escHtml(s) {
if (s == null) return '';
return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
function escAttr(s) {
if (s == null) return '';
return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// ── Start ──
initSession().then(sessionOk => {
if (!sessionOk) {
showError('教务系统 Session 已失效,请尝试<a href="/dashboard">重新配置教务账号</a>');
return;
}
loadParams();
});
</script>
{% endblock %}
+603
View File
@@ -0,0 +1,603 @@
{% 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; }
/* 课程卡片入场动画 */
@keyframes cardFadeIn {
from { opacity: 0; transform: translateY(12px) scale(0.97); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
.course-card-enter {
animation: cardFadeIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}
/* 展开区域动画 */
.session-list {
max-height: 0;
overflow: hidden;
transition: max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.session-list.expanded {
max-height: 9999px;
}
/* 进度条动画 */
@keyframes progressShine {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
.progress-bar-fill {
background: linear-gradient(90deg, #3b82f6, #60a5fa, #3b82f6);
background-size: 200% 100%;
animation: progressShine 2s linear infinite;
}
</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">
<circle cx="11" cy="11" r="8"/>
<path d="m21 21-4.3-4.3"/>
</svg>
课程搜索
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">搜索全校授课信息(课程、教师、班级、地点等所有字段)</p>
</div>
</div>
<!-- 学年学期选择 + 搜索框 -->
<div class="glass rounded-2xl p-4 mb-4 list-item-enter max-w-5xl mx-auto" style="animation-delay: 50ms;">
<div class="flex flex-col md:flex-row gap-3 items-stretch md:items-end">
<div class="flex gap-3">
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">学年</label>
<select id="fXnm" onchange="onFilterChange()" class="w-full md:w-32 px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="2026" selected>2026-2027</option>
<option value="2025">2025-2026</option>
<option value="2024">2024-2025</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">学期</label>
<select id="fXqm" onchange="onFilterChange()" class="w-full md:w-28 px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="3" selected>第1学期</option>
<option value="12">第2学期</option>
</select>
</div>
</div>
<div class="flex-1">
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">搜索关键词</label>
<div class="flex flex-col sm:flex-row gap-2">
<input id="searchInput" type="text" placeholder="输入关键词:课程名、教师、班级、地点等"
onkeydown="if(event.key==='Enter') doSearch()"
class="flex-1 px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<div class="flex gap-2">
<select id="searchField" class="flex-1 sm:flex-none px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="auto">全字段</option>
<option value="kch">课程号</option>
<option value="name">课程名</option>
<option value="teacher">教师</option>
<option value="class">班级</option>
<option value="room">地点</option>
</select>
<button onclick="doSearch()" class="btn-primary px-5 py-2 rounded-lg text-sm font-medium shrink-0">
搜索
</button>
</div>
</div>
</div>
</div>
</div>
<!-- 索引状态卡片 -->
<div id="indexStatusCard" class="glass rounded-2xl p-4 mb-4 list-item-enter max-w-5xl mx-auto" style="animation-delay: 100ms;">
<!-- 由 JS 填充 -->
</div>
<!-- 搜索结果 -->
<div id="resultsContainer" class="max-w-5xl mx-auto"></div>
<!-- 浏览面板(无关键词时显示) -->
<div id="browseContainer" class="max-w-5xl mx-auto hidden"></div>
<!-- 无结果提示 -->
<div id="noResults" class="hidden text-center py-16 list-item-enter">
<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-gray-300 dark:text-gray-600">
<circle cx="11" cy="11" r="8"/>
<path d="m21 21-4.3-4.3"/>
<path d="M8 11h6"/>
</svg>
<p class="text-gray-400 dark:text-gray-500">未找到匹配的课程</p>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
const WEEKDAYS = ['', '周一', '周二', '周三', '周四', '周五', '周六', '周日'];
let pollTimer = null;
let lastSearchKeyword = '';
let lastSearchField = 'auto';
const canManageIndex = {{ 'true' if current_user.is_authenticated and current_user.username == '战忠沅' else 'false' }};
// ── 初始化 ──
document.addEventListener('DOMContentLoaded', () => {
checkIndexStatus();
// 自动聚焦搜索框
document.getElementById('searchInput').focus();
});
function getXnm() { return document.getElementById('fXnm').value; }
function getXqm() { return document.getElementById('fXqm').value; }
function onFilterChange() {
checkIndexStatus();
document.getElementById('searchInput').value = '';
document.getElementById('resultsContainer').innerHTML = '';
document.getElementById('noResults').classList.add('hidden');
browseData = null;
}
// ── 索引状态 ──
async function checkIndexStatus() {
const card = document.getElementById('indexStatusCard');
try {
const resp = await apiRequest(`/api/jwxt/course-index/status?xnm=${getXnm()}&xqm=${getXqm()}`);
renderIndexStatus(resp);
if (resp.building) {
startPolling();
} else {
stopPolling();
}
} catch (e) {
card.innerHTML = `<p class="text-sm text-red-500">状态获取失败: ${escapeHtml(e.message)}</p>`;
}
}
function renderIndexStatus(s) {
const card = document.getElementById('indexStatusCard');
if (s.building) {
// 构建中
const pct = s.total_teachers > 0 ? Math.round(s.current / s.total_teachers * 100) : 0;
card.innerHTML = `
<div class="flex items-center justify-between mb-2">
<div class="flex items-center gap-2">
<span class="status-badge status-running">构建中</span>
<span class="text-sm text-gray-500 dark:text-gray-400">
正在拉取教师课表... ${s.current}/${s.total_teachers}
</span>
</div>
<span class="text-sm font-mono text-blue-500">${pct}%</span>
</div>
<div class="w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden">
<div class="progress-bar-fill h-full rounded-full transition-all duration-500" style="width: ${pct}%"></div>
</div>
<div class="flex gap-4 mt-2 text-xs text-gray-400">
<span>已索引 ${s.total_courses || 0} 门课程</span>
<span>${s.total_sessions || 0} 条排课记录</span>
${s.current_teacher ? `<span>当前: ${escapeHtml(s.current_teacher)}</span>` : ''}
</div>
`;
} else if (s.exists && !s.needs_build) {
// 索引可用
card.innerHTML = `
<div class="flex items-center justify-between flex-wrap gap-2">
<div class="flex items-center gap-3 flex-wrap">
<span class="status-badge status-success">索引就绪</span>
<span class="text-sm text-gray-500 dark:text-gray-400">
${s.total_courses} 门课程 · ${s.total_sessions} 条排课 · ${s.total_teachers} 位教师
</span>
<span class="text-xs text-gray-400">更新于 ${s.age_hours}h 前</span>
</div>
${canManageIndex ? `<button onclick=\"rebuildIndex()\" class=\"btn-outline text-xs shrink-0\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"12\" height=\"12\" 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>\n 重建索引\n </button>` : ''}
</div>
`;
showBrowsePanel();
} else {
// 无索引
card.innerHTML = `
<div class="flex items-center justify-between flex-wrap gap-2">
<div class="flex items-center gap-3 flex-wrap">
<span class="status-badge status-pending">未构建</span>
<span class="text-sm text-gray-500 dark:text-gray-400">
需要全量拉取教师课表来建立课程索引,预计需要 3-5 分钟
</span>
</div>
${canManageIndex ? `<button onclick=\"buildIndex()\" class=\"btn-primary px-4 py-2 rounded-lg text-sm font-medium shrink-0\">\n 构建索引\n </button>` : ''}
</div>
`;
}
}
// ── 构建索引 ──
async function buildIndex() {
try {
const resp = await apiRequest(`/api/jwxt/course-index/build?xnm=${getXnm()}&xqm=${getXqm()}`, { method: 'POST' });
if (resp.success) {
showToast('索引构建已启动,请等待完成', 'info');
checkIndexStatus();
} else {
showToast(resp.message || '构建失败', 'error');
}
} catch (e) {
showToast('构建请求失败: ' + e.message, 'error');
}
}
async function rebuildIndex() {
// 先删除旧索引(通过传一个 force 参数让后端重建)
// 后端 build 会先检查缓存,如果有效则直接返回。需要先删除缓存。
try {
// 直接调用 build,后端会先检查缓存。如果缓存有效,需要先标记过期。
// 简单方案:直接修改 xnm/xqm 不现实。改为直接 POST 请求,后端 build_course_index 会检查缓存。
// 如果缓存有效,build_course_index 直接返回缓存结果。需要先删除缓存文件。
// 但我们不想暴露删除文件接口,所以改为:在 build 路由中加 force 参数。
const resp = await apiRequest(`/api/jwxt/course-index/build?xnm=${getXnm()}&xqm=${getXqm()}&force=1`, { method: 'POST' });
if (resp.success) {
showToast('正在重建索引...', 'info');
checkIndexStatus();
} else {
showToast(resp.message || '重建失败', 'error');
}
} catch (e) {
showToast('重建请求失败: ' + e.message, 'error');
}
}
// ── 轮询构建进度 ──
function startPolling() {
stopPolling();
pollTimer = setInterval(async () => {
try {
const resp = await apiRequest(`/api/jwxt/course-index/status?xnm=${getXnm()}&xqm=${getXqm()}`);
renderIndexStatus(resp);
if (!resp.building) {
stopPolling();
if (resp.exists) {
showToast('索引构建完成!', 'success');
// 如果之前有搜索关键词,重新搜索
if (lastSearchKeyword) {
doSearch();
}
} else if (resp.needs_build) {
showToast('索引构建可能失败,请重试', 'error');
}
}
} catch (e) {
// 忽略轮询中的错误
}
}, 3000);
}
function stopPolling() {
if (pollTimer) {
clearInterval(pollTimer);
pollTimer = null;
}
}
// ── 搜索 ──
async function doSearch() {
const keyword = document.getElementById('searchInput').value.trim();
const field = document.getElementById('searchField').value;
lastSearchKeyword = keyword;
lastSearchField = field;
if (!keyword) {
showBrowsePanel();
return;
}
document.getElementById('browseContainer').classList.add('hidden');
const resultsContainer = document.getElementById('resultsContainer');
const noResults = document.getElementById('noResults');
// 显示加载状态
resultsContainer.innerHTML = `
<div class="text-center py-12 list-item-enter">
<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>
`;
noResults.classList.add('hidden');
try {
const resp = await apiRequest(`/api/jwxt/course-search?keyword=${encodeURIComponent(keyword)}&xnm=${getXnm()}&xqm=${getXqm()}&field=${field}`);
if (!resp.success) {
resultsContainer.innerHTML = `
<div class="glass rounded-2xl p-6 text-center list-item-enter">
<p class="text-red-500">${escapeHtml(resp.message || '搜索失败')}</p>
</div>
`;
return;
}
const courses = resp.courses || [];
if (courses.length === 0) {
resultsContainer.innerHTML = '';
noResults.classList.remove('hidden');
return;
}
renderResults(courses, resp);
} catch (e) {
resultsContainer.innerHTML = `
<div class="glass rounded-2xl p-6 text-center list-item-enter">
<p class="text-red-500">搜索失败: ${escapeHtml(e.message)}</p>
</div>
`;
}
}
// ── 渲染搜索结果 ──
function renderResults(courses, meta) {
const container = document.getElementById('resultsContainer');
let html = `
<div class="flex items-center justify-between mb-3 px-1 list-item-enter">
<p class="text-sm text-gray-500 dark:text-gray-400">
找到 <span class="font-bold text-black dark:text-white">${courses.length}</span> 门课程
</p>
</div>
`;
courses.forEach((course, idx) => {
const sessions = course.sessions || [];
const delay = Math.min(idx * 50, 400);
html += renderCourseCard(course, sessions, delay);
});
container.innerHTML = html;
}
function renderCourseCard(course, sessions, delay) {
const id = `course_${course.kch.replace(/[^a-zA-Z0-9]/g, '')}`;
const tags = [];
if (course.xf) tags.push(`${course.xf}学分`);
if (course.kcxzjc) tags.push(course.kcxzjc);
if (course.khfsmc) tags.push(course.khfsmc);
if (course.xslxbj === '☆' || course.xslxbj === '★') tags.push('选修');
// 统计不同教师数
const teacherSet = new Set();
sessions.forEach(s => { if (s.jsxm) teacherSet.add(s.jsxm); });
// 统计班级数
const classSet = new Set();
sessions.forEach(s => { if (s.jxbzcbjjc) classSet.add(s.jxbzcbjjc); });
return `
<div class="glass rounded-2xl mb-3 overflow-hidden course-card-enter" style="animation-delay: ${delay}ms;" id="${id}">
<!-- 课程头部 -->
<div class="p-4 cursor-pointer hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors" onclick="toggleSessions('${id}')">
<div class="flex items-start justify-between gap-3">
<div class="flex-1 min-w-0">
<div class="flex items-center gap-2 flex-wrap mb-1">
<h3 class="font-bold text-base">${escapeHtml(course.kcmc || '未知课程')}</h3>
${tags.map(t => `<span class="tag">${escapeHtml(t)}</span>`).join('')}
</div>
<p class="text-xs font-mono text-gray-400 dark:text-gray-500">${escapeHtml(course.kch || '')}</p>
</div>
<div class="flex items-center gap-2 shrink-0">
<div class="text-right hidden sm:block">
<p class="text-xs text-gray-400">${teacherSet.size} 位教师</p>
<p class="text-xs text-gray-400">${sessions.length} 个教学班</p>
</div>
<svg class="w-5 h-5 text-gray-400 transition-transform expand-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
</svg>
</div>
</div>
<!-- 手机端统计信息 -->
<div class="flex gap-3 mt-2 sm:hidden">
<span class="text-xs text-gray-400">${teacherSet.size} 位教师</span>
<span class="text-xs text-gray-400">${sessions.length} 个教学班</span>
</div>
</div>
<!-- 教学班列表(可展开) -->
<div class="session-list" id="${id}_sessions">
<div class="border-t border-gray-100 dark:border-gray-800">
${sessions.map((s, si) => renderSessionRow(s, si)).join('')}
</div>
</div>
</div>
`;
}
function renderSessionRow(s, idx) {
const xqj = WEEKDAYS[parseInt(s.xqj)] || (s.xqj || '-');
const skjc = s.skcd || s.skjc || '-';
const zcd = s.zcd || '-';
const teachers = s.jsxm || '-';
const cls = s.jxbzcbjjc || '-';
const room = s.cdmc || '-';
const count = s.jxbrs || '-';
const campus = s.zfjmc || '';
return `
<div class="px-4 py-3 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors ${idx > 0 ? 'border-t border-gray-50 dark:border-gray-900' : ''}">
<div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-2 text-sm">
<div>
<span class="text-xs text-gray-400 block">教师</span>
<span class="font-medium">${escapeHtml(teachers)}</span>
</div>
<div>
<span class="text-xs text-gray-400 block">上课班级</span>
<span class="text-xs">${escapeHtml(cls)}</span>
</div>
<div>
<span class="text-xs text-gray-400 block">时间</span>
<span class="text-xs">${escapeHtml(xqj)} ${escapeHtml(String(skjc))}</span>
</div>
<div>
<span class="text-xs text-gray-400 block">周次</span>
<span class="text-xs">${escapeHtml(String(zcd))}</span>
</div>
<div>
<span class="text-xs text-gray-400 block">地点</span>
<span class="text-xs">${escapeHtml(room)}${campus ? ' <span class="text-gray-400">' + escapeHtml(campus) + '</span>' : ''}</span>
</div>
<div>
<span class="text-xs text-gray-400 block">人数</span>
<span class="text-xs">${escapeHtml(String(count))}</span>
</div>
</div>
</div>
`;
}
function toggleSessions(id) {
const el = document.getElementById(id + '_sessions');
const icon = document.querySelector(`#${id} .expand-icon`);
if (el.classList.contains('expanded')) {
el.classList.remove('expanded');
icon.style.transform = '';
} else {
el.classList.add('expanded');
icon.style.transform = 'rotate(180deg)';
}
}
// ── 浏览面板 ──
let browseData = null;
let browseTab = 'courses';
async function showBrowsePanel() {
const container = document.getElementById('browseContainer');
const resultsContainer = document.getElementById('resultsContainer');
// 隐藏搜索结果
resultsContainer.innerHTML = '';
document.getElementById('noResults').classList.add('hidden');
container.classList.remove('hidden');
if (!browseData || browseData._xnm !== getXnm() || browseData._xqm !== getXqm()) {
container.innerHTML = `
<div class="text-center py-12 list-item-enter">
<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>
`;
try {
const resp = await apiRequest(`/api/jwxt/course-browse?xnm=${getXnm()}&xqm=${getXqm()}`);
if (!resp.success) {
container.innerHTML = `<p class="text-sm text-gray-400 text-center py-8">${escapeHtml(resp.message || '加载失败')}</p>`;
return;
}
resp._xnm = getXnm();
resp._xqm = getXqm();
browseData = resp;
} catch (e) {
container.innerHTML = `<p class="text-sm text-red-500 text-center py-8">加载失败: ${escapeHtml(e.message)}</p>`;
return;
}
}
renderBrowsePanel();
}
function renderBrowsePanel() {
const container = document.getElementById('browseContainer');
const tabs = [
{ key: 'courses', label: `课程 (${browseData.total_courses})` },
{ key: 'teachers', label: `教师 (${browseData.total_teachers})` },
{ key: 'rooms', label: `地点 (${browseData.total_rooms})` },
{ key: 'classes', label: `班级 (${browseData.total_classes})` },
];
let html = `
<div class="glass rounded-2xl p-1 mb-4 flex gap-1 overflow-x-auto">
${tabs.map(t => `
<button data-key="${t.key}" onclick="switchBrowseTab('${t.key}')" class="browse-tab-btn px-4 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${browseTab === t.key ? 'bg-black dark:bg-white text-white dark:text-black' : 'text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800'}">${t.label}</button>
`).join('')}
</div>
<div id="browseContent"></div>
`;
container.innerHTML = html;
renderBrowseTab();
}
function switchBrowseTab(tab) {
browseTab = tab;
// 更新按钮样式
document.querySelectorAll('.browse-tab-btn').forEach(btn => {
const isActive = btn.dataset.key === tab;
btn.className = `browse-tab-btn px-4 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${isActive ? 'bg-black dark:bg-white text-white dark:text-black' : 'text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800'}`;
});
renderBrowseTab();
}
function renderBrowseTab() {
const el = document.getElementById('browseContent');
if (browseTab === 'courses') {
el.innerHTML = renderCourseBrowseList(browseData.courses);
} else if (browseTab === 'teachers') {
el.innerHTML = renderSimpleBrowseList(browseData.teachers, '教师', 'course_count', '门课');
} else if (browseTab === 'rooms') {
el.innerHTML = renderSimpleBrowseList(browseData.rooms, '地点', 'session_count', '条排课');
} else if (browseTab === 'classes') {
el.innerHTML = renderSimpleBrowseList(browseData.classes, '班级', 'session_count', '条排课');
}
}
function renderCourseBrowseList(courses) {
if (!courses.length) return '<p class="text-center text-gray-400 py-8">暂无数据</p>';
return courses.map((c, idx) => `
<div class="glass rounded-xl mb-2 p-3 flex items-center justify-between gap-3 cursor-pointer hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors list-item-enter"
style="animation-delay: ${Math.min(idx * 20, 300)}ms;"
onclick="quickSearch('${escapeHtml(c.kcmc)}')">
<div class="flex-1 min-w-0">
<div class="flex items-center gap-2 flex-wrap">
<span class="font-medium text-sm">${escapeHtml(c.kcmc)}</span>
${c.xf ? `<span class="tag text-xs">${escapeHtml(c.xf)}学分</span>` : ''}
${c.kcxzjc ? `<span class="tag text-xs">${escapeHtml(c.kcxzjc)}</span>` : ''}
${c.khfsmc ? `<span class="tag text-xs">${escapeHtml(c.khfsmc)}</span>` : ''}
</div>
<p class="text-xs font-mono text-gray-400 mt-0.5">${escapeHtml(c.kch)}</p>
</div>
<div class="flex gap-3 shrink-0 text-xs text-gray-400">
<span>${c.teacher_count} 教师</span>
<span>${c.session_count} 教学班</span>
</div>
</div>
`).join('');
}
function renderSimpleBrowseList(items, label, countKey, countLabel) {
if (!items.length) return '<p class="text-center text-gray-400 py-8">暂无数据</p>';
return items.map((item, idx) => `
<div class="glass rounded-xl mb-2 p-3 flex items-center justify-between gap-3 cursor-pointer hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors list-item-enter"
style="animation-delay: ${Math.min(idx * 15, 300)}ms;"
onclick="quickSearch('${escapeHtml(item.name)}')">
<span class="font-medium text-sm">${escapeHtml(item.name)}</span>
<span class="text-xs text-gray-400 shrink-0">${item[countKey]} ${countLabel}</span>
</div>
`).join('');
}
function quickSearch(keyword) {
document.getElementById('searchInput').value = keyword;
document.getElementById('searchField').value = 'auto';
doSearch();
}
</script>
{% endblock %}
+74
View File
@@ -0,0 +1,74 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M16 3h5v5"/><path d="M8 3H3v5"/><path d="M3 16v5h5"/><path d="M16 21h5v-5"/><line x1="12" y1="3" x2="12" y2="21"/><line x1="3" y1="12" x2="21" y2="12"/></svg>
校内课程替代申请
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">申请用已修课程替代未修课程</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">原课程</th><th class="text-left py-3 px-4 font-semibold">替代课程</th><th class="text-left py-3 px-4 font-semibold">申请时间</th><th class="text-left py-3 px-4 font-semibold">审核状态</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无替代申请记录</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/course-substitution');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.ykcmc||item.原课程||'--')}</td>
<td class="py-3 px-4">${escHtml(item.tdkcmc||item.替代课程||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.sqsj||item.申请时间||'--')}</td>
<td class="py-3 px-4"><span class="px-2 py-0.5 rounded text-xs ${(item.shztmc||item.审核状态||'').includes('通过')?'bg-green-100 text-green-700':(item.shztmc||'').includes('待审')?'bg-yellow-100 text-yellow-700':'bg-gray-100 text-gray-600'}">${escHtml(item.shztmc||item.审核状态||'--')}</span></td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
File diff suppressed because it is too large Load Diff
+74
View File
@@ -0,0 +1,74 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M22 10v6M2 10l10-5 10 5-10 5z"/><path d="M6 12v5c0 1.66 2.69 3 6 3"/></svg>
成绩学分认定申请
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">申请成绩和学分的认定</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">课程名称</th><th class="text-left py-3 px-4 font-semibold">申请类型</th><th class="text-left py-3 px-4 font-semibold">申请时间</th><th class="text-left py-3 px-4 font-semibold">审核状态</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无认定申请记录</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/credit-recognition');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.kcmc||item.课程名称||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.sqlx||item.申请类型||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.sqsj||item.申请时间||'--')}</td>
<td class="py-3 px-4"><span class="px-2 py-0.5 rounded text-xs ${(item.shztmc||item.审核状态||'').includes('通过')?'bg-green-100 text-green-700':(item.shztmc||item.审核状态||'').includes('待审')?'bg-yellow-100 text-yellow-700':'bg-gray-100 text-gray-600'}">${escHtml(item.shztmc||item.审核状态||'--')}</span></td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+446
View File
@@ -0,0 +1,446 @@
{% extends "base_tailwind.html" %}
{% block title %}仪表盘 - {{ brand_name }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- 欢迎区域 -->
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 0ms;">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<h1 class="text-2xl md:text-3xl font-bold text-neutral-900 dark:text-white">欢迎回来,{{ current_user.username }}</h1>
<p class="text-neutral-500 dark:text-neutral-400 mt-1">这里是您的抢课任务概览</p>
</div>
<div class="flex gap-3 flex-wrap">
<a href="{{ url_for('main.courses') }}" class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold inline-flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
</svg>
查询课程
</a>
<a href="{{ url_for('main.timetable') }}" class="px-5 py-2.5 rounded-full text-sm font-bold bg-blue-600 text-white hover:bg-blue-700 transition inline-flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
</svg>
课表查询
</a>
<a href="{{ url_for('main.tasks') }}" class="px-5 py-2.5 rounded-full text-sm font-bold bg-green-600 text-white hover:bg-green-700 transition inline-flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
</svg>
创建任务
</a>
</div>
</div>
</div>
<!-- 统计卡片 -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 50ms;">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-neutral-500 dark:text-neutral-400">总任务数</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1">{{ task_count }}</p>
</div>
<div class="w-10 h-10 rounded-xl bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center">
<svg class="w-5 h-5 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"></path>
</svg>
</div>
</div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 100ms;">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-neutral-500 dark:text-neutral-400">待执行</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1">{{ pending_count }}</p>
</div>
<div class="w-10 h-10 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center">
<svg class="w-5 h-5 text-amber-600 dark:text-amber-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
</div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 150ms;">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-neutral-500 dark:text-neutral-400">抢课成功</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1">{{ success_count }}</p>
</div>
<div class="w-10 h-10 rounded-xl bg-green-100 dark:bg-green-900/30 flex items-center justify-center">
<svg class="w-5 h-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
</div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 200ms;">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-neutral-500 dark:text-neutral-400">选课系统</p>
<p class="text-lg font-bold mt-1" id="systemStatus">
<span class="inline-block w-4 h-4 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></span>
</p>
</div>
<div class="w-10 h-10 rounded-xl bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center">
<svg class="w-5 h-5 text-purple-600 dark:text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3.055 11H5a2 2 0 012 2v1a2 2 0 002 2 2 2 0 012 2v2.945M8 3.935V5.5A2.5 2.5 0 0010.5 8h.5a2 2 0 012 2 2 2 0 104 0 2 2 0 012-2h1.064M15 20.488V18a2 2 0 012-2h3.064M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
</div>
</div>
</div>
<!-- Session 状态 -->
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 250ms;">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<h3 class="text-lg font-bold text-neutral-900 dark:text-white flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>
</svg>
登录状态
</h3>
<p class="text-sm text-neutral-500 mt-1" id="sessionStatusInfo">
<span class="inline-block w-3 h-3 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin mr-1"></span>
检查中...
</p>
</div>
<div class="flex gap-3">
<button onclick="refreshSession()" class="px-4 py-2 bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded-full text-sm font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
刷新登录
</button>
<button onclick="showJwxtConfigModal()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
</svg>
配置账号
</button>
</div>
</div>
</div>
<!-- 最近任务 -->
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 300ms;">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">最近任务</h3>
<a href="{{ url_for('main.tasks') }}" class="text-sm text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition flex items-center gap-1">
查看全部
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
</svg>
</a>
</div>
{% if recent_tasks %}
<div class="overflow-x-auto max-w-5xl mx-auto">
<table class="data-table">
<thead>
<tr>
<th>课程名称</th>
<th>类型</th>
<th>状态</th>
<th>创建时间</th>
</tr>
</thead>
<tbody>
{% for task in recent_tasks %}
<tr class="list-item-enter" style="animation-delay: {{ (loop.index0 * 30) }}ms;">
<td class="font-medium">{{ task.course_name }}</td>
<td>
{% if task.task_type == 'immediate' %}
<span class="status-badge status-info">立即</span>
{% else %}
<span class="status-badge status-warning">定时</span>
{% endif %}
</td>
<td>
{% if task.status == 'success' %}
<span class="status-badge status-success">成功</span>
{% elif task.status == 'pending' %}
<span class="status-badge status-warning">待执行</span>
{% elif task.status == 'running' %}
<span class="status-badge status-info">运行中</span>
{% else %}
<span class="status-badge status-danger">失败</span>
{% endif %}
</td>
<td class="text-sm text-neutral-500">{{ task.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="text-center py-8">
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"></path>
</svg>
<p class="text-neutral-500">暂无任务,快去创建抢课任务吧!</p>
</div>
{% endif %}
</div>
</div>
<!-- 刷新 Session 模态框 -->
<div id="refreshSessionModal" class="fixed inset-0 z-50 flex items-center justify-center p-4 opacity-0 pointer-events-none transition-opacity duration-240">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeRefreshSessionModal()"></div>
<div class="relative w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">刷新登录状态</h3>
<button onclick="closeRefreshSessionModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-100 dark:border-blue-800 rounded-xl p-4 mb-4">
<p class="text-sm text-blue-800 dark:text-blue-200">系统将自动使用已保存的教务系统密码刷新登录状态</p>
</div>
<div id="refreshResult"></div>
<div class="flex gap-3 mt-6">
<button type="button" onclick="closeRefreshSessionModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
取消
</button>
<button type="button" onclick="doRefreshSession()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
刷新
</button>
</div>
</div>
</div>
</div>
<!-- 配置教务系统账号模态框 -->
<div id="jwxtConfigModal" class="fixed inset-0 z-50 flex items-center justify-center p-4 opacity-0 pointer-events-none transition-opacity duration-240">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeJwxtConfigModal()"></div>
<div class="relative w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">配置教务系统账号</h3>
<button onclick="closeJwxtConfigModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<div class="bg-amber-50 dark:bg-amber-900/20 border border-amber-100 dark:border-amber-800 rounded-xl p-4 mb-4">
<p class="text-sm text-amber-800 dark:text-amber-200">修改账号信息需要重新验证</p>
</div>
<div class="space-y-4">
<div>
<label class="input-label">学号</label>
<input type="text" id="configJwxtUsername" class="input-field" placeholder="请输入学号">
</div>
<div>
<label class="input-label">密码</label>
<input type="password" id="configJwxtPassword" class="input-field" placeholder="请输入密码">
</div>
<div>
<label class="input-label">姓名(选填)</label>
<input type="text" id="configJwxtName" class="input-field" placeholder="请输入姓名">
</div>
<div id="configResult"></div>
</div>
<div class="flex gap-3 mt-6">
<button type="button" onclick="closeJwxtConfigModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
取消
</button>
<button type="button" onclick="saveJwxtConfig()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
保存并验证
</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
// 将弹窗移到 body 直接子级,确保 fixed 定位基于视口
['refreshSessionModal', 'jwxtConfigModal'].forEach(id => {
const el = document.getElementById(id);
if (el) document.body.appendChild(el);
});
checkSystemStatus();
checkSessionStatus();
// 每30秒刷新一次状态
setInterval(checkSystemStatus, 30000);
setInterval(checkSessionStatus, 60000);
});
// 检查选课系统状态
async function checkSystemStatus() {
try {
const data = await apiRequest('/api/courses/status');
const statusEl = document.getElementById('systemStatus');
if (data.success && data.is_open) {
statusEl.innerHTML = '<span class="text-green-600 dark:text-green-400 flex items-center gap-1"><span class="w-2 h-2 bg-green-500 rounded-full"></span>开放中</span>';
} else {
statusEl.innerHTML = '<span class="text-amber-600 dark:text-amber-400 flex items-center gap-1"><span class="w-2 h-2 bg-amber-500 rounded-full"></span>未开放</span>';
}
} catch (error) {
document.getElementById('systemStatus').innerHTML = '<span class="text-red-600">获取失败</span>';
}
}
// 检查 Session 状态
async function checkSessionStatus() {
try {
const data = await apiRequest('/api/user/session/status');
const infoEl = document.getElementById('sessionStatusInfo');
if (data.is_valid) {
infoEl.innerHTML = `
<span class="text-green-600 dark:text-green-400 flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
登录有效
<span class="text-neutral-400 text-xs">更新时间: ${data.updated_at ? formatTime(data.updated_at) : '未知'}</span>
</span>
`;
} else {
infoEl.innerHTML = `
<span class="text-red-600 dark:text-red-400 flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
登录已过期
${data.error_msg ? `<span class="text-neutral-400 text-xs">${data.error_msg}</span>` : ''}
</span>
`;
}
} catch (error) {
document.getElementById('sessionStatusInfo').innerHTML = '<span class="text-red-600">检查失败</span>';
}
}
// 显示刷新 Session 模态框
function refreshSession() {
document.getElementById('refreshResult').innerHTML = '';
const modal = document.getElementById('refreshSessionModal');
modal.classList.remove('opacity-0', 'pointer-events-none');
modal.classList.add('opacity-100', 'pointer-events-auto');
document.documentElement.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
}
function closeRefreshSessionModal() {
const modal = document.getElementById('refreshSessionModal');
modal.classList.add('opacity-0', 'pointer-events-none');
modal.classList.remove('opacity-100', 'pointer-events-auto');
document.documentElement.style.overflow = '';
document.body.style.overflow = '';
}
// 执行刷新 Session
async function doRefreshSession() {
const btn = document.querySelector('#refreshSessionModal button[onclick="doRefreshSession()"]');
if (btn) { btn.disabled = true; btn.textContent = '刷新中…'; }
const loadingToast = showToast('正在刷新登录状态…', 'info', 30000);
try {
const data = await apiRequest('/api/user/session/refresh', {
method: 'POST',
body: JSON.stringify({})
});
loadingToast.remove();
if (data.success) {
showToast(data.message || '刷新成功', 'success');
document.getElementById('refreshResult').innerHTML = `<div class="p-3 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 rounded-lg text-sm">${data.message}</div>`;
setTimeout(() => {
closeRefreshSessionModal();
checkSessionStatus();
}, 1500);
} else {
showToast(data.message || '刷新失败', 'error');
document.getElementById('refreshResult').innerHTML = `<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">${data.message}</div>`;
}
} catch (error) {
loadingToast.remove();
showToast('刷新失败,请稍后重试', 'error');
document.getElementById('refreshResult').innerHTML = '<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">刷新失败</div>';
} finally {
if (btn) { btn.disabled = false; btn.textContent = '刷新'; }
}
}
// 显示配置模态框
function showJwxtConfigModal() {
document.getElementById('configJwxtUsername').value = '';
document.getElementById('configJwxtPassword').value = '';
document.getElementById('configJwxtName').value = '';
document.getElementById('configResult').innerHTML = '';
const modal = document.getElementById('jwxtConfigModal');
modal.classList.remove('opacity-0', 'pointer-events-none');
modal.classList.add('opacity-100', 'pointer-events-auto');
document.documentElement.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
}
function closeJwxtConfigModal() {
const modal = document.getElementById('jwxtConfigModal');
modal.classList.add('opacity-0', 'pointer-events-none');
modal.classList.remove('opacity-100', 'pointer-events-auto');
document.documentElement.style.overflow = '';
document.body.style.overflow = '';
}
// 保存教务系统配置
async function saveJwxtConfig() {
const username = document.getElementById('configJwxtUsername').value.trim();
const password = document.getElementById('configJwxtPassword').value.trim();
const name = document.getElementById('configJwxtName').value.trim();
if (!username || !password) {
document.getElementById('configResult').innerHTML = '<div class="p-3 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200 rounded-lg text-sm">请填写学号和密码</div>';
return;
}
const btn = document.querySelector('#jwxtConfigModal button[onclick="saveJwxtConfig()"]');
if (btn) { btn.disabled = true; btn.textContent = '登录中…'; }
const loadingToast = showToast('正在登录教务系统…', 'info', 30000);
try {
const data = await apiRequest('/api/user/jwxt/config', {
method: 'POST',
body: JSON.stringify({
jwxt_username: username,
jwxt_password: password,
jwxt_name: name
})
});
loadingToast.remove();
if (data.success) {
showToast(data.message || '登录成功', 'success');
document.getElementById('configResult').innerHTML = `<div class="p-3 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 rounded-lg text-sm">${data.message}</div>`;
setTimeout(() => {
closeJwxtConfigModal();
checkSessionStatus();
}, 1500);
} else {
showToast(data.message || '登录失败', 'error');
document.getElementById('configResult').innerHTML = `<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">${data.message}</div>`;
}
} catch (error) {
loadingToast.remove();
showToast('配置失败,请稍后重试', 'error');
document.getElementById('configResult').innerHTML = '<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">配置失败</div>';
} finally {
if (btn) { btn.disabled = false; btn.textContent = '保存并验证'; }
}
}
</script>
{% endblock %}
+116
View File
@@ -0,0 +1,116 @@
{% 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; }
@media (prefers-reduced-motion: reduce) { .row-animate, .list-item-enter { animation: none !important; opacity: 1 !important; } }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 9999px; font-size: 11px; font-weight: 500; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.dark .badge-green { background: #14532d; color: #bbf7d0; }
.dark .badge-yellow { background: #713f12; color: #fef08a; }
.dark .badge-gray { background: #374151; color: #d1d5db; }
.change-type-btn { display: inline-flex; align-items: center; padding: 6px 14px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 13px; cursor: pointer; transition: all .15s; background: transparent; }
.change-type-btn:hover { border-color: #000; background: #f5f5f5; }
.dark .change-type-btn { border-color: #404040; color: #ccc; }
.dark .change-type-btn:hover { border-color: #fff; background: #262626; color: #fff; }
</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"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
学籍异动申请
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">2025-2026学年2学期的学籍异动申请</p>
</div>
<button onclick="loadData()" 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"><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 class="glass rounded-2xl p-4 mb-4 list-item-enter" style="animation-delay:50ms;">
<p class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">可申请的异动类别:</p>
<div id="changeTypesContainer" class="flex flex-wrap gap-2">
<span class="text-gray-400 text-sm">加载中...</span>
</div>
</div>
<div id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden list-item-enter" style="animation-delay:100ms;">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap">申请状态</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap">审核状态</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap">异动学年</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap">异动学期</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap">异动类别</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap">异动原因</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap">申请理由</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap">联系电话</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无学籍异动申请记录</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/enrollment-change');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
// 显示可申请的异动类型
const ctContainer = document.getElementById('changeTypesContainer');
if (data.change_types && data.change_types.length > 0) {
ctContainer.innerHTML = data.change_types.map(t =>
`<span class="change-type-btn">${escHtml(t.label||t.value)}</span>`
).join('');
} else {
ctContainer.innerHTML = '<span class="text-gray-400 text-sm">无非当前可申请的异动类型</span>';
}
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
const sqzt = item.sqztmc || item.申请状态 || '--';
const shzt = item.shztmc || item.审核状态 || '--';
const shBadge = shzt.includes('通过') ? 'badge-green' : shzt.includes('待审') ? 'badge-yellow' : 'badge-gray';
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors row-animate" style="animation-delay:${i*30}ms;">
<td class="py-3 px-4 text-xs">${escHtml(sqzt)}</td>
<td class="py-3 px-4"><span class="badge ${shBadge}">${escHtml(shzt)}</span></td>
<td class="py-3 px-4 text-xs text-gray-500">${escHtml(item.ydxn||item.异动学年||'--')}</td>
<td class="py-3 px-4 text-xs text-gray-500">${escHtml(item.ydxq||item.异动学期||'--')}</td>
<td class="py-3 px-4 text-xs">${escHtml(item.ydlbmc||item.异动类别||'--')}</td>
<td class="py-3 px-4 text-xs text-gray-500">${escHtml(item.ydyy||item.异动原因||'--')}</td>
<td class="py-3 px-4 text-xs text-gray-500 max-w-[200px] truncate">${escHtml(item.sqly||item.申请理由||'--')}</td>
<td class="py-3 px-4 text-xs">${escHtml(item.lxdh||item.联系电话||'--')}</td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+218
View File
@@ -0,0 +1,218 @@
{% 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; }
@media (prefers-reduced-motion: reduce) { .row-animate, .list-item-enter { animation: none !important; opacity: 1 !important; } }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 1800px; }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 9999px; font-size: 11px; font-weight: 500; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.dark .badge-green { background: #14532d; color: #bbf7d0; }
.dark .badge-yellow { background: #713f12; color: #fef08a; }
.dark .badge-gray { background: #374151; color: #d1d5db; }
.dark .badge-blue { background: #1e3a5f; color: #93c5fd; }
.modal-overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; }
.modal-box { background: #fff; border-radius: 16px; max-width: 95vw; max-height: 85vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 25px 60px rgba(0,0,0,.3); }
.dark .modal-box { background: #1a1a1a; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #e5e5e5; }
.dark .modal-header { border-color: #333; }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
</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"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>
考级项目报名
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">等级考试报名信息查询</p>
</div>
<div class="flex items-center gap-2">
<span id="semesterLabel" class="text-sm font-medium text-gray-600 dark:text-gray-400"></span>
<button onclick="loadExpired()" class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-xs font-medium hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors">✉ 本学期过期项目报名信息</button>
<button onclick="loadData()" class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-xs font-medium hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors flex items-center gap-1"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden list-item-enter" style="animation-delay:100ms;">
<div class="glass rounded-2xl overflow-hidden">
<div class="table-wrap">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">流程跟踪</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">审核状态</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">缴费状态</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">报名学年</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">报名学期</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">报名批次</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">项目类别</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">项目名称</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">项目成绩</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">成绩明细</th>
<th class="text-right py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">报名费用</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">证件类型</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">证件号码</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">准考证号</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">考试时间</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">考试地点</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">考场号</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">座位号</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">手机号码</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">校区</th>
<th class="text-left py-3 px-3 font-semibold text-gray-700 dark:text-gray-300 whitespace-nowrap text-xs">备注</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无考级报名信息</p></div>
</div>
<!-- 过期项目弹窗 -->
<div id="expiredModal" class="modal-overlay hidden" onclick="if(event.target===this)closeExpiredModal()">
<div class="modal-box w-full max-w-4xl">
<div class="modal-header">
<h3 class="text-lg font-bold">查询过期项目</h3>
<button onclick="closeExpiredModal()" class="p-1 hover:bg-gray-100 dark:hover:bg-gray-800 rounded transition-colors text-xl leading-none">&times;</button>
</div>
<div class="modal-body">
<div id="expiredLoading" class="text-center py-8"><div class="w-8 h-8 border-2 border-black dark:border-white border-t-transparent rounded-full animate-spin mx-auto mb-3"></div><p class="text-gray-500 text-sm">加载中...</p></div>
<div id="expiredError" class="text-center py-8 text-red-500 hidden"></div>
<div id="expiredContent" class="hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">报名学年</th>
<th class="text-left py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">报名学期</th>
<th class="text-left py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">项目类别</th>
<th class="text-left py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">项目名称</th>
<th class="text-left py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">报名批次</th>
<th class="text-right py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">人数限制</th>
<th class="text-left py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">开始时间</th>
<th class="text-left py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">结束时间</th>
<th class="text-right py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">费用</th>
<th class="text-center py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">可退</th>
<th class="text-center py-2 px-3 font-semibold text-xs text-gray-700 dark:text-gray-300">可补考</th>
</tr>
</thead>
<tbody id="expiredTableBody"></tbody>
</table>
</div>
<div id="expiredSummary" class="text-xs text-gray-500 text-right mt-3"></div>
</div>
</div>
<div class="flex justify-end px-5 py-3 border-t border-gray-100 dark:border-gray-800">
<button onclick="closeExpiredModal()" class="px-6 py-2 rounded-lg bg-black dark:bg-white text-white dark:text-black text-sm font-medium hover:opacity-85 transition-opacity">关 闭</button>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
function v(item, keys) {
for (const k of keys) { const val = item[k]; if (val != null && val !== '') return val; }
return '--';
}
async function loadData() {
showLoading();
try {
const res = await fetch('/api/jwxt/exam-registration');
const data = await res.json();
hideLoading();
if (!data.success) { showError(data.message); return; }
const items = data.items || [];
if (!items.length) { showEmpty('暂无考级报名信息'); return; }
renderTable(items);
} catch(e) { hideLoading(); showError('网络错误: '+e.message); }
}
function renderTable(items) {
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
const shzt = v(item, ['shztmc', 'shzt', '审核状态']);
const jfzt = v(item, ['jfzt', 'jfztmc', '缴费状态']);
const shBadge = shzt.includes('通过') ? 'badge-green' : shzt.includes('待审') ? 'badge-yellow' : shzt.includes('缴费') ? 'badge-blue' : 'badge-gray';
const jfBadge = jfzt.includes('已缴') ? 'badge-green' : jfzt.includes('未缴') ? 'badge-yellow' : 'badge-gray';
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors row-animate" style="animation-delay:${i*30}ms;">
<td class="py-2.5 px-3 text-xs">${escHtml(v(item,['lczz','流程跟踪']))}</td>
<td class="py-2.5 px-3"><span class="badge ${shBadge}">${escHtml(shzt)}</span></td>
<td class="py-2.5 px-3"><span class="badge ${jfBadge}">${escHtml(jfzt)}</span></td>
<td class="py-2.5 px-3 text-xs text-gray-500">${escHtml(v(item,['bmdxnm','xnm','报名学年']))}</td>
<td class="py-2.5 px-3 text-xs text-gray-500">${escHtml(v(item,['bmdxqm','xqm','报名学期']))}</td>
<td class="py-2.5 px-3 text-xs text-gray-500">${escHtml(v(item,['bmpc','bmpcmc','报名批次']))}</td>
<td class="py-2.5 px-3 text-xs">${escHtml(v(item,['xmlbmc','xmlb','项目类别']))}</td>
<td class="py-2.5 px-3 font-medium">${escHtml(v(item,['xmmc','项目名称']))}</td>
<td class="py-2.5 px-3 text-xs">${escHtml(v(item,['xmcj','项目成绩']))}</td>
<td class="py-2.5 px-3 text-xs text-blue-500">${escHtml(v(item,['cjmx','成绩明细']))}</td>
<td class="py-2.5 px-3 text-right text-xs font-medium">${escHtml(v(item,['bmfy','报名费用(元)','fy','费用']))}</td>
<td class="py-2.5 px-3 text-xs text-gray-500">${escHtml(v(item,['zjlxmc','zjlx','证件类型']))}</td>
<td class="py-2.5 px-3 text-xs">${escHtml(v(item,['zjhm','证件号码']))}</td>
<td class="py-2.5 px-3 text-xs">${escHtml(v(item,['zkzh','准考证号']))}</td>
<td class="py-2.5 px-3 text-xs text-gray-500">${escHtml(v(item,['kssj','考试时间']))}</td>
<td class="py-2.5 px-3 text-xs">${escHtml(v(item,['ksdd','kscd','考试地点']))}</td>
<td class="py-2.5 px-3 text-xs text-gray-500">${escHtml(v(item,['kch','考场号']))}</td>
<td class="py-2.5 px-3 text-xs text-gray-500">${escHtml(v(item,['zwh','座位号']))}</td>
<td class="py-2.5 px-3 text-xs">${escHtml(v(item,['sjhm','手机号码']))}</td>
<td class="py-2.5 px-3 text-xs text-gray-500">${escHtml(v(item,['xqmc','校区']))}</td>
<td class="py-2.5 px-3 text-xs text-gray-400 max-w-[120px] truncate">${escHtml(v(item,['bz','备注']))}</td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('emptyState').classList.add('hidden');
}
async function loadExpired() {
document.getElementById('expiredModal').classList.remove('hidden');
document.getElementById('expiredLoading').classList.remove('hidden');
document.getElementById('expiredError').classList.add('hidden');
document.getElementById('expiredContent').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/exam-registration/expired');
const data = await res.json();
document.getElementById('expiredLoading').classList.add('hidden');
if (!data.success) { document.getElementById('expiredError').textContent = data.message; document.getElementById('expiredError').classList.remove('hidden'); return; }
const items = data.items || [];
if (!items.length) { document.getElementById('expiredError').textContent = '暂无过期报名信息'; document.getElementById('expiredError').classList.remove('hidden'); return; }
const tbody = document.getElementById('expiredTableBody');
tbody.innerHTML = items.map((item, i) => `
<tr class="border-b border-gray-100 dark:border-gray-800 row-animate" style="animation-delay:${i*30}ms;">
<td class="py-2 px-3 text-xs">${escHtml(item.xnmc||'--')}</td>
<td class="py-2 px-3 text-xs">${escHtml(item.xqmmc||'--')}</td>
<td class="py-2 px-3 text-xs">${escHtml(item.xmlbmc||'--')}</td>
<td class="py-2 px-3 text-xs font-medium">${escHtml(item.xmmc||'--')}</td>
<td class="py-2 px-3 text-xs">${escHtml(item.bmpc||'--')}</td>
<td class="py-2 px-3 text-xs text-right">${escHtml(item.rszgxz||'--')}</td>
<td class="py-2 px-3 text-xs text-gray-500">${escHtml(item.kssj||'--')}</td>
<td class="py-2 px-3 text-xs text-gray-500">${escHtml(item.jssj||'--')}</td>
<td class="py-2 px-3 text-xs text-right font-medium">${escHtml(item.bmfy||'--')}</td>
<td class="py-2 px-3 text-xs text-center">${item.sfkt==='1'?'✅':'❌'}</td>
<td class="py-2 px-3 text-xs text-center">${item.sfkbk==='1'?'✅':'❌'}</td>
</tr>
`).join('');
document.getElementById('expiredSummary').textContent = `共 ${items.length} 条记录`;
document.getElementById('expiredContent').classList.remove('hidden');
} catch(e) { document.getElementById('expiredLoading').classList.add('hidden'); document.getElementById('expiredError').textContent = '加载失败: '+e.message; document.getElementById('expiredError').classList.remove('hidden'); }
}
function closeExpiredModal() { document.getElementById('expiredModal').classList.add('hidden'); }
function showLoading() { document.getElementById('loadingIndicator').classList.remove('hidden'); document.getElementById('errorMessage').classList.add('hidden'); document.getElementById('dataContainer').classList.add('hidden'); document.getElementById('emptyState').classList.add('hidden'); }
function hideLoading() { document.getElementById('loadingIndicator').classList.add('hidden'); }
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function showEmpty(msg) { document.getElementById('emptyState').classList.remove('hidden'); document.getElementById('emptyState').querySelector('p').textContent = msg; }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+452
View File
@@ -0,0 +1,452 @@
{% 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 %}
+16
View File
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>正在跳转...</title>
<script>
// 自动跳转到新的购买页面
window.location.href = '/buy';
</script>
</head>
<body>
<p>正在跳转到购买页面...</p>
<p>如果未自动跳转,请<a href="/buy">点击这里</a></p>
</body>
</html>
+74
View File
@@ -0,0 +1,74 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M16 2v6h6"/><path d="M12 18v-4"/><path d="M12 10v-1"/></svg>
成绩复查申请
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">对课程成绩有疑问时申请复查</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">课程名称</th><th class="text-left py-3 px-4 font-semibold">原成绩</th><th class="text-left py-3 px-4 font-semibold">申请原因</th><th class="text-left py-3 px-4 font-semibold">审核状态</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无复查申请记录</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/grade-review');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.kcmc||item.课程名称||'--')}</td>
<td class="py-3 px-4">${escHtml(item.ycj||item.原成绩||'--')}</td>
<td class="py-3 px-4 text-gray-500 text-xs">${escHtml(item.sqyy||item.申请原因||'--')}</td>
<td class="py-3 px-4"><span class="px-2 py-0.5 rounded text-xs ${(item.shztmc||item.审核状态||'').includes('通过')?'bg-green-100 text-green-700':(item.shztmc||'').includes('待审')?'bg-yellow-100 text-yellow-700':'bg-gray-100 text-gray-600'}">${escHtml(item.shztmc||item.审核状态||'--')}</span></td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+622
View File
@@ -0,0 +1,622 @@
{% extends "base_tailwind.html" %}
{% block title %}成绩查询 - {{ brand_name }}{% endblock %}
{% block extra_css %}
<style>
.grade-a-plus { color: #22c55e; }
.grade-a { color: #16a34a; }
.grade-b { color: #2563eb; }
.grade-c { color: #d97706; }
.grade-d { color: #dc2626; }
.grade-fail { color: #991b1b; }
.grade-retake { color: #2563eb; } /* 补考/重修通过 */
.dark .grade-a-plus { color: #4ade80; }
.dark .grade-a { color: #22c55e; }
.dark .grade-b { color: #60a5fa; }
.dark .grade-c { color: #fbbf24; }
.dark .grade-d { color: #f87171; }
.dark .grade-fail { color: #ef4444; }
.dark .grade-retake { color: #60a5fa; }
@keyframes fadeSlideIn {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
.row-animate {
animation: fadeSlideIn 0.3s ease both;
}
@keyframes shimmer {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
.skeleton {
background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
background-size: 200% 100%;
animation: shimmer 1.5s infinite;
border-radius: 0.5rem;
}
.dark .skeleton {
background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
background-size: 200% 100%;
}
.stat-card {
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.stat-card:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(0,0,0,0.08);
}
.dark .stat-card:hover {
box-shadow: 0 8px 25px rgba(0,0,0,0.4);
}
@media (prefers-reduced-motion: reduce) {
.stat-card { transition: none !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">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
<line x1="16" y1="13" x2="8" y2="13"/>
<line x1="16" y1="17" x2="8" y2="17"/>
<polyline points="10 9 9 9 8 9"/>
</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="yearSelect"
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>
<select id="termSelect"
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>
<select id="courseMarkSelect"
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>
<option value="0">主修</option>
<option value="1">辅修</option>
<option value="2">二专业</option>
<option value="3">二学位</option>
<option value="4">非学位</option>
<option value="8">二学位转一专</option>
</select>
<button onclick="refreshGrades()"
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="colorLegend" class="mb-4 list-item-enter hidden" style="animation-delay: 25ms;">
<div class="glass rounded-2xl px-4 py-2.5 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs">
<span class="text-gray-400 dark:text-gray-500">图例:</span>
<span class="flex items-center gap-1.5"><span class="w-2.5 h-2.5 rounded-full bg-red-500 inline-block"></span>不合格(红)</span>
<span class="flex items-center gap-1.5"><span class="w-2.5 h-2.5 rounded-full bg-blue-500 inline-block"></span>补考/重修通过(蓝)</span>
<span class="flex items-center gap-1.5"><span class="w-2.5 h-2.5 rounded-full bg-green-500 inline-block"></span>正常通过(绿)</span>
</div>
</div>
<!-- 统计卡片 -->
<div id="statsRow" class="grid grid-cols-2 md:grid-cols-5 gap-3 mb-6 list-item-enter hidden" style="animation-delay: 50ms;">
<div class="stat-card glass rounded-2xl p-4 text-center">
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">课程总数</div>
<div id="statTotal" class="text-2xl font-bold">--</div>
</div>
<div class="stat-card glass rounded-2xl p-4 text-center">
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">总学分</div>
<div id="statCredits" class="text-2xl font-bold">--</div>
</div>
<div class="stat-card glass rounded-2xl p-4 text-center">
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">平均绩点</div>
<div id="statGPA" class="text-2xl font-bold">--</div>
</div>
<div class="stat-card glass rounded-2xl p-4 text-center">
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">加权平均分</div>
<div id="statAvg" class="text-2xl font-bold">--</div>
</div>
<div class="stat-card glass rounded-2xl p-4 text-center">
<div class="text-xs text-gray-500 dark:text-gray-400 mb-1">总学分绩点</div>
<div id="statXfjd" class="text-2xl font-bold">--</div>
</div>
</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="scoreDistChart" 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="courseTypeChart" class="h-64"></div>
</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="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="gradesContainer" class="hidden list-item-enter" style="animation-delay: 150ms;">
<div id="gradesTableWrapper" class="glass rounded-2xl overflow-hidden hidden">
<div class="overflow-x-auto">
<table class="w-full text-xs whitespace-nowrap">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">序号</th>
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">学年学期</th>
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">课程代码</th>
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">课程名称</th>
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">课程性质</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">学分</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">成绩</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">成绩备注</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">绩点</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">成绩性质</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">学位课</th>
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">开课学院</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">课程标记</th>
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">课程类别</th>
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">课程归属</th>
<th class="text-left py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">任课教师</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">考核方式</th>
<th class="text-center py-2.5 px-2 font-semibold text-gray-700 dark:text-gray-300">学分绩点</th>
</tr>
</thead>
<tbody id="gradesTableBody">
</tbody>
</table>
</div>
</div>
<!-- 空状态 -->
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden">
<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">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
</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>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
let allGrades = [];
let scoreDistChart = null;
let courseTypeChart = null;
let currentPage = 1;
let pageSize = 100;
let gradesTotal = 0;
// ── 深色模式判断 ──
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;
}
}
// 成绩等级 → 绩点映射
function gradeToPoint(grade) {
const g = String(grade || '').trim().toUpperCase();
const map = {
'A+': 4.0, 'A': 4.0, 'A-': 3.7,
'B+': 3.3, 'B': 3.0, 'B-': 2.7,
'C+': 2.3, 'C': 2.0, 'C-': 1.7,
'D+': 1.3, 'D': 1.0, 'D-': 0.7,
'F': 0.0,
};
if (map[g] !== undefined) return map[g];
const num = parseFloat(grade);
if (isNaN(num)) return 0;
if (num >= 95) return 4.0;
if (num >= 90) return 4.0;
if (num >= 85) return 3.7;
if (num >= 80) return 3.3;
if (num >= 75) return 3.0;
if (num >= 70) return 2.7;
if (num >= 65) return 2.3;
if (num >= 60) return 2.0;
return 0;
}
// 判断是否为补考/重修/缓考成绩(用于蓝色标识)
function isRetake(ksxz) {
if (!ksxz) return false;
return /补考|重修|缓考/.test(ksxz);
}
function gradeColorClass(grade, ksxz) {
// 补考/重修通过 → 蓝色标识(对齐教务系统)
if (isRetake(ksxz)) {
const num = parseFloat(grade);
if (!isNaN(num) && num >= 60) return 'grade-retake';
const g = String(grade || '').trim();
if (['优秀','良好','中等','及格'].includes(g)) return 'grade-retake';
}
const g = String(grade || '').trim().toUpperCase();
if (['A+', 'A', 'A-'].includes(g)) return 'grade-a-plus';
if (['B+', 'B', 'B-'].includes(g)) return 'grade-b';
if (['C+', 'C', 'C-'].includes(g)) return 'grade-c';
if (['D+', 'D', 'D-'].includes(g)) return 'grade-d';
if (g === 'F') return 'grade-fail';
const num = parseFloat(grade);
if (!isNaN(num)) {
if (num >= 90) return 'grade-a-plus';
if (num >= 80) return 'grade-a';
if (num >= 70) return 'grade-b';
if (num >= 60) return 'grade-c';
return 'grade-fail';
}
return '';
}
async function loadYears() {
try {
const res = await fetch('/api/jwxt/semesters');
const data = await res.json();
if (data.success && data.years) {
const yearSel = document.getElementById('yearSelect');
const termSel = document.getElementById('termSelect');
// 学年下拉(从近到远)
data.years.sort((a, b) => parseInt(b.value) - parseInt(a.value)).forEach(y => {
const opt = document.createElement('option');
opt.value = y.value;
opt.textContent = y.label;
yearSel.appendChild(opt);
});
// 学期下拉
(data.terms || []).forEach(t => {
const opt = document.createElement('option');
opt.value = t.value;
opt.textContent = t.label;
termSel.appendChild(opt);
});
}
} catch (e) {
console.error('加载筛选条件失败:', e);
}
}
async function refreshGrades(page) {
if (page !== undefined) currentPage = page; else currentPage = 1;
const loading = document.getElementById('loadingIndicator');
const error = document.getElementById('errorMessage');
const container = document.getElementById('gradesContainer');
const statsRow = document.getElementById('statsRow');
const colorLegend = document.getElementById('colorLegend');
const empty = document.getElementById('emptyState');
const chartsRow = document.getElementById('chartsRow');
const tableWrapper = document.getElementById('gradesTableWrapper');
loading.classList.remove('hidden');
error.classList.add('hidden');
container.classList.add('hidden');
statsRow.classList.add('hidden');
colorLegend.classList.add('hidden');
empty.classList.add('hidden');
chartsRow.classList.add('hidden');
if (tableWrapper) tableWrapper.classList.add('hidden');
const year = document.getElementById('yearSelect').value;
const term = document.getElementById('termSelect').value;
const kcbj = document.getElementById('courseMarkSelect').value;
// 构建 API 参数: 学年 + 学期分开(对齐教务系统)
const params = { kcbj, page: currentPage, page_size: pageSize };
if (year) params.xnm = year;
if (term) params.xqm = term;
try {
const res = await fetch('/api/jwxt/grades?' + new URLSearchParams(params));
const data = await res.json();
loading.classList.add('hidden');
if (!data.success) {
showError(data.message || '查询失败');
return;
}
allGrades = data.items || [];
gradesTotal = data.total || allGrades.length;
if (allGrades.length === 0) {
container.classList.remove('hidden');
empty.classList.remove('hidden');
return;
}
renderGrades(allGrades);
container.classList.remove('hidden');
statsRow.classList.remove('hidden');
colorLegend.classList.remove('hidden');
if (tableWrapper) tableWrapper.classList.remove('hidden');
renderPagination();
} catch (e) {
loading.classList.add('hidden');
showError('网络错误: ' + e.message);
}
}
function renderGrades(grades) {
const tbody = document.getElementById('gradesTableBody');
tbody.innerHTML = '';
let totalCredits = 0;
let totalPoints = 0; // 绩点×学分 加权
let totalXfjd = 0; // 官方学分绩点
let totalScore = 0;
let scoreCount = 0;
grades.forEach((item, idx) => {
// 字段映射(兼容大小写和中文别名)
const xnmmc = item.xnmmc || item['学年'] || '';
const xqmmc = item.xqmmc || item['学期'] || '';
const kch = item.kch || item['课程代码'] || '';
const kcmc = item.kcmc || item['课程名称'] || '未知课程';
const kcxzmc = item.kcxzmc || item['课程性质'] || '';
const xf = parseFloat(item.xf || item['学分'] || 0) || 0;
const cj = item.cj || item['成绩'] || item.bfzcj || '--';
const cjbz = item.cjbz || item['成绩备注'] || '';
const jd = parseFloat(item.jd); // 官方绩点
const ksxz = item.ksxz || item['成绩性质'] || '';
const sfxwkc = item.sfxwkc || item['是否学位课程'] || '';
const kkbmmc = item.kkbmmc || item['开课学院'] || '';
const kcbj = item.kcbj || item['课程标记'] || '';
const kclbmc = item.kclbmc || item['课程类别'] || '';
const kcgsmc = item.kcgsmc || item['课程归属'] || '';
const jsxm = item.jsxm || item['任课教师'] || '';
const khfsmc = item.khfsmc || item['考核方式'] || '';
const xfjd = parseFloat(item.xfjd || 0) || 0; // 官方学分绩点
// 绩点取值:优先官方 jd,否则本地计算
const point = isNaN(jd) ? gradeToPoint(cj) : jd;
const pointDisplay = isNaN(jd) ? point.toFixed(1) : jd.toFixed(2);
const numScore = parseFloat(cj);
if (!isNaN(numScore) && numScore > 0) {
totalScore += numScore * xf;
scoreCount += xf;
}
totalCredits += xf;
totalPoints += point * xf;
totalXfjd += xfjd;
// 颜色:根据成绩性质判断是否为补考蓝色
const colorClass = gradeColorClass(cj, ksxz);
const delay = Math.min(idx * 30, 600);
// 学年学期合并显示
const xnxq = xnmmc ? (xnmmc + (xqmmc ? '-' + xqmmc : '')) : '--';
const tr = document.createElement('tr');
tr.className = 'border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors row-animate';
tr.style.animationDelay = delay + 'ms';
tr.innerHTML = `
<td class="py-2.5 px-2 text-gray-400 dark:text-gray-500">${idx + 1}</td>
<td class="py-2.5 px-2">${xnxq}</td>
<td class="py-2.5 px-2 text-gray-500 dark:text-gray-400 font-mono text-xs">${kch}</td>
<td class="py-2.5 px-2 font-medium">${kcmc}</td>
<td class="py-2.5 px-2 text-gray-500 dark:text-gray-400">${kcxzmc}</td>
<td class="py-2.5 px-2 text-center">${xf.toFixed(1)}</td>
<td class="py-2.5 px-2 text-center font-semibold ${colorClass}">${cj}</td>
<td class="py-2.5 px-2 text-center text-gray-400 dark:text-gray-500 text-xs">${cjbz}</td>
<td class="py-2.5 px-2 text-center font-semibold ${colorClass}">${pointDisplay}</td>
<td class="py-2.5 px-2 text-center text-gray-500 dark:text-gray-400">${ksxz}</td>
<td class="py-2.5 px-2 text-center">${sfxwkc}</td>
<td class="py-2.5 px-2 text-gray-500 dark:text-gray-400">${kkbmmc}</td>
<td class="py-2.5 px-2 text-center text-gray-500 dark:text-gray-400">${kcbj}</td>
<td class="py-2.5 px-2 text-gray-500 dark:text-gray-400">${kclbmc}</td>
<td class="py-2.5 px-2 text-gray-500 dark:text-gray-400">${kcgsmc}</td>
<td class="py-2.5 px-2 text-gray-500 dark:text-gray-400">${jsxm}</td>
<td class="py-2.5 px-2 text-center text-gray-500 dark:text-gray-400">${khfsmc}</td>
<td class="py-2.5 px-2 text-center font-semibold">${xfjd > 0 ? xfjd.toFixed(2) : '--'}</td>
`;
tbody.appendChild(tr);
});
// 更新统计
const gpa = totalCredits > 0 ? (totalPoints / totalCredits).toFixed(2) : '--';
const weightedAvg = scoreCount > 0 ? (totalScore / scoreCount).toFixed(1) : '--';
document.getElementById('statTotal').textContent = grades.length;
document.getElementById('statCredits').textContent = totalCredits.toFixed(1);
document.getElementById('statGPA').textContent = gpa;
document.getElementById('statAvg').textContent = weightedAvg;
document.getElementById('statXfjd').textContent = totalXfjd > 0 ? totalXfjd.toFixed(1) : '--';
// 渲染图表
const chartsRow = document.getElementById('chartsRow');
chartsRow.classList.remove('hidden');
renderScoreDistChart(grades);
renderCourseTypeChart(grades);
setupDarkObserver();
}
// ── 分页组件 ──
function renderPagination() {
let container = document.getElementById('paginationBar');
if (!container) {
container = document.createElement('div');
container.id = 'paginationBar';
container.className = 'flex justify-center items-center gap-2 mt-4';
document.getElementById('gradesContainer').appendChild(container);
}
const totalPages = Math.ceil(gradesTotal / pageSize) || 1;
if (totalPages <= 1) { container.innerHTML = ''; return; }
let html = '';
html += `<button onclick="refreshGrades(${currentPage - 1})" ${currentPage <= 1 ? 'disabled' : ''}
class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-xs disabled:opacity-30 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors">上一页</button>`;
html += `<span class="text-xs text-gray-500 dark:text-gray-400">第 ${currentPage} / ${totalPages} 页(共 ${gradesTotal} 条)</span>`;
html += `<button onclick="refreshGrades(${currentPage + 1})" ${currentPage >= totalPages ? 'disabled' : ''}
class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-xs disabled:opacity-30 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors">下一页</button>`;
container.innerHTML = html;
}
function showError(msg) {
const error = document.getElementById('errorMessage');
document.getElementById('errorText').textContent = msg;
error.classList.remove('hidden');
}
// ── 成绩分布柱状图 ──
function renderScoreDistChart(grades) {
const container = document.getElementById('scoreDistChart');
if (!container) return;
if (!scoreDistChart) scoreDistChart = echarts.init(container);
const bins = { '优秀(90-100)': 0, '良好(80-89)': 0, '中等(70-79)': 0, '及格(60-69)': 0, '不及格(0-59)': 0 };
grades.forEach(item => {
const grade = item.cj || item.CJ || item['成绩'] || item.bfzcj || item.BFZCJ || '';
const num = parseFloat(grade);
if (isNaN(num) || num <= 0) return;
if (num >= 90) bins['优秀(90-100)']++;
else if (num >= 80) bins['良好(80-89)']++;
else if (num >= 70) bins['中等(70-79)']++;
else if (num >= 60) bins['及格(60-69)']++;
else bins['不及格(0-59)']++;
});
const dark = isDarkMode();
scoreDistChart.setOption({
tooltip: { trigger: 'axis' },
xAxis: { type: 'category', data: Object.keys(bins), axisLabel: { fontSize: 11 } },
yAxis: { type: 'value', name: '门数', nameTextStyle: { fontSize: 11 } },
series: [{
type: 'bar', data: Object.values(bins),
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: dark ? '#60a5fa' : '#3b82f6' },
{ offset: 1, color: dark ? '#1d4ed8' : '#1e40af' }
])
},
barMaxWidth: 40,
label: { show: true, position: 'top', fontSize: 11, color: dark ? '#9ca3af' : '#6b7280' }
}]
}, true);
}
// ── 课程类别学分饼图 ──
function renderCourseTypeChart(grades) {
const container = document.getElementById('courseTypeChart');
if (!container) return;
if (!courseTypeChart) courseTypeChart = echarts.init(container);
const typeMap = {};
grades.forEach(item => {
const type = item.kclbmc || item.KCLBMC || item['课程类别'] || item.kclx || '其他';
const credits = parseFloat(item.xf || item.XF || item['学分'] || 0) || 0;
typeMap[type] = (typeMap[type] || 0) + credits;
});
const entries = Object.entries(typeMap).sort((a, b) => b[1] - a[1]);
const dark = isDarkMode();
const colors = dark
? ['#60a5fa', '#34d399', '#fbbf24', '#f87171', '#a78bfa', '#f472b6', '#38bdf8', '#fb923c']
: ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#06b6d4', '#f97316'];
courseTypeChart.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() {
if (_darkObserver) return;
_darkObserver = new MutationObserver(() => {
const grades = allGrades;
if (grades.length > 0) {
if (scoreDistChart) renderScoreDistChart(grades);
if (courseTypeChart) renderCourseTypeChart(grades);
}
});
_darkObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
// ── 图表响应式缩放 ──
window.addEventListener('resize', () => {
scoreDistChart?.resize();
courseTypeChart?.resize();
});
// 学年/学期/课程标记切换自动刷新
document.getElementById('yearSelect').addEventListener('change', refreshGrades);
document.getElementById('termSelect').addEventListener('change', refreshGrades);
document.getElementById('courseMarkSelect').addEventListener('change', refreshGrades);
// 初始化:先检查 session,再加载数据
initSession().then(sessionOk => {
if (!sessionOk) {
showError('教务系统 Session 已失效,请尝试<a href="/dashboard" class="underline">重新配置教务账号</a>');
return;
}
loadYears().then(() => refreshGrades());
});
</script>
{% endblock %}
+162
View File
@@ -0,0 +1,162 @@
{% extends "base_tailwind.html" %}
{% block title %}登录 - {{ brand_name }}{% endblock %}
{% block content %}
<div class="min-h-[70vh] flex items-center justify-center">
<div class="w-full max-w-md">
<!-- 登录卡片 -->
<div class="glass rounded-3xl p-8 layer-4 list-item-enter" style="animation-delay: 0ms;">
<!-- Logo -->
<div class="text-center mb-8">
<div class="w-16 h-16 bg-black dark:bg-white rounded-2xl flex items-center justify-center text-white dark:text-black font-bold text-2xl mx-auto mb-4">
S
</div>
<h1 class="text-2xl font-bold text-neutral-900 dark:text-white">欢迎回来</h1>
<p class="text-neutral-500 dark:text-neutral-400 mt-2">登录您的账号继续使用</p>
</div>
<!-- 登录表单 -->
<form id="loginForm" onsubmit="handleLogin(event)" class="space-y-5">
<div>
<label class="input-label">用户名</label>
<input type="text" name="username" id="username" class="input-field" placeholder="请输入用户名" required autofocus>
</div>
<div>
<label class="input-label">密码</label>
<input type="password" name="password" id="password" class="input-field" placeholder="请输入密码" required>
</div>
<div id="errorMessage" class="hidden p-3 bg-red-50 dark:bg-red-900/20 border border-red-100 dark:border-red-800 rounded-xl text-sm text-red-800 dark:text-red-200">
</div>
<!-- 协议勾选 -->
<label class="flex items-start gap-2.5 cursor-pointer select-none group" id="termsLabel">
<div class="relative flex-shrink-0 mt-0.5">
<input type="checkbox" id="agreeTerms" class="sr-only" onchange="updateCheckbox(this)">
<div id="checkboxBox" class="w-[18px] h-[18px] rounded border-2 border-neutral-300 dark:border-neutral-600 transition-all flex items-center justify-center">
<svg id="checkIcon" class="w-2.5 h-2.5 text-white dark:text-black hidden" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/>
</svg>
</div>
</div>
<span class="text-xs text-neutral-500 dark:text-neutral-400 leading-relaxed">
我已阅读并同意
<a href="{{ url_for('main.terms') }}" target="_blank" onclick="event.stopPropagation()" class="text-neutral-800 dark:text-neutral-200 font-medium underline underline-offset-2 hover:text-black dark:hover:text-white">用户服务协议</a>
和
<a href="{{ url_for('main.privacy') }}" target="_blank" onclick="event.stopPropagation()" class="text-neutral-800 dark:text-neutral-200 font-medium underline underline-offset-2 hover:text-black dark:hover:text-white">隐私政策</a>
</span>
</label>
<button type="submit" id="submitBtn" class="w-full btn-primary py-3.5 rounded-full text-sm font-bold">
登录
</button>
</form>
<!-- 分割线 -->
<div class="relative my-6">
<div class="absolute inset-0 flex items-center">
<div class="w-full border-t border-neutral-200 dark:border-neutral-800"></div>
</div>
<div class="relative flex justify-center text-sm">
<span class="px-4 bg-white dark:bg-dark-card text-neutral-500">还没有账号?</span>
</div>
</div>
<!-- 注册按钮 -->
<a href="{{ url_for('main.register') }}" class="block w-full py-3.5 rounded-full text-sm font-bold text-center border-2 border-neutral-200 dark:border-neutral-800 text-neutral-700 dark:text-neutral-300 hover:border-neutral-400 dark:hover:border-neutral-600 transition">
立即注册
</a>
<!-- 购买按钮 -->
<a href="{{ url_for('main.buy') }}" class="block w-full py-3.5 rounded-full text-sm font-bold text-center border-2 border-neutral-200 dark:border-neutral-800 text-neutral-700 dark:text-neutral-300 hover:border-neutral-400 dark:hover:border-neutral-600 transition mt-3">
购买注册码
</a>
</div>
<!-- 返回首页 -->
<div class="text-center mt-6">
<a href="{{ url_for('main.buy') }}" class="text-sm text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition flex items-center justify-center gap-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path>
</svg>
返回首页
</a>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
function updateCheckbox(input) {
const box = document.getElementById('checkboxBox');
const icon = document.getElementById('checkIcon');
const isDark = document.documentElement.classList.contains('dark');
if (input.checked) {
box.classList.remove('border-neutral-300', 'dark:border-neutral-600');
box.classList.add('bg-black', 'border-black', 'dark:bg-white', 'dark:border-white');
icon.classList.remove('hidden');
} else {
box.classList.add('border-neutral-300', 'dark:border-neutral-600');
box.classList.remove('bg-black', 'border-black', 'dark:bg-white', 'dark:border-white');
icon.classList.add('hidden');
}
}
async function handleLogin(event) {
event.preventDefault();
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value;
const submitBtn = document.getElementById('submitBtn');
const errorDiv = document.getElementById('errorMessage');
// 验证协议勾选
if (!document.getElementById('agreeTerms').checked) {
errorDiv.textContent = '请先阅读并同意用户服务协议和隐私政策';
errorDiv.classList.remove('hidden');
return;
}
// 禁用按钮
submitBtn.disabled = true;
submitBtn.innerHTML = '<span class="inline-block w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"></span>登录中...';
errorDiv.classList.add('hidden');
try {
const formData = new FormData();
formData.append('username', username);
formData.append('password', password);
const response = await fetch('{{ url_for('main.login') }}', {
method: 'POST',
body: formData
});
if (response.redirected) {
window.location.href = response.url;
return;
}
const html = await response.text();
// 检查是否有错误消息
if (html.includes('用户名或密码错误') || html.includes('alert-danger')) {
errorDiv.textContent = '用户名或密码错误';
errorDiv.classList.remove('hidden');
submitBtn.disabled = false;
submitBtn.innerHTML = '登录';
} else {
// 登录成功,刷新页面
window.location.href = '{{ url_for('main.dashboard') }}';
}
} catch (error) {
errorDiv.textContent = '网络错误,请稍后重试';
errorDiv.classList.remove('hidden');
submitBtn.disabled = false;
submitBtn.innerHTML = '登录';
}
}
</script>
{% endblock %}
+294
View File
@@ -0,0 +1,294 @@
{% extends "base_tailwind.html" %}
{% block title %}抢课日志 - 教务抢课系统{% endblock %}
{% block content %}
<div>
<!-- 页面标题 -->
<div class="flex justify-between items-center mb-6 list-item-enter" style="animation-delay: 0ms;">
<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"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
抢课日志
</h2>
<div>
<button onclick="clearLogs()"
class="px-4 py-2 border border-red-300 dark:border-red-700 text-red-600 dark:text-red-400 rounded-full hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/></svg>
清空日志
</button>
</div>
</div>
<!-- 筛选栏 -->
<div class="glass rounded-2xl p-6 mb-6 list-item-enter" style="animation-delay: 50ms;">
<div class="flex flex-col md:flex-row gap-4 items-center">
<div class="flex-1 grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<select id="levelFilter" onchange="loadLogs()"
class="w-full px-4 py-2 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-black focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white">
<option value="">全部级别</option>
<option value="info">信息</option>
<option value="success">成功</option>
<option value="warning">警告</option>
<option value="error">错误</option>
</select>
</div>
<div>
<select id="taskFilter" onchange="loadLogs()"
class="w-full px-4 py-2 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-black focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white">
<option value="">全部任务</option>
</select>
</div>
</div>
<div class="flex items-center gap-4">
<button onclick="loadLogs()"
class="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-full hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 21h5v-5"/></svg>
刷新
</button>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="autoRefresh" checked onchange="setupAutoRefresh()"
class="w-4 h-4 accent-black dark:accent-white">
<span class="text-sm">自动刷新</span>
</label>
</div>
</div>
</div>
<!-- 日志列表 -->
<div class="glass rounded-2xl p-6 list-item-enter" style="animation-delay: 100ms;">
<div id="loadingIndicator" class="text-center py-12">
<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="emptyState" class="text-center py-12" style="display: none;">
<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-gray-400"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
<p class="text-gray-500 dark:text-gray-400">暂无日志</p>
</div>
<div id="logsContainer" style="display: none;">
<div id="logsList" class="space-y-2 max-h-[600px] overflow-y-auto font-mono text-sm max-w-4xl mx-auto">
<!-- 日志内容 -->
</div>
</div>
<!-- 分页 -->
<nav id="pagination" class="mt-6" style="display: none;">
<div class="flex justify-center items-center gap-2">
</div>
</nav>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
let currentPage = 1;
let autoRefreshInterval = null;
let lastLogId = 0;
// 加载日志
async function loadLogs(page = 1, incremental = false) {
if (!incremental) {
currentPage = page;
document.getElementById('loadingIndicator').style.display = 'block';
document.getElementById('emptyState').style.display = 'none';
document.getElementById('logsContainer').style.display = 'none';
document.getElementById('pagination').style.display = 'none';
}
const level = document.getElementById('levelFilter').value;
const taskId = document.getElementById('taskFilter').value;
try {
let url;
if (incremental && lastLogId > 0) {
url = `/api/logs/recent?after_id=${lastLogId}`;
if (taskId) url += `&task_id=${taskId}`;
} else {
url = `/api/logs/list?page=${page}&per_page=50`;
if (level) url += `&level=${level}`;
if (taskId) url += `&task_id=${taskId}`;
}
const data = await apiRequest(url);
if (!incremental) {
document.getElementById('loadingIndicator').style.display = 'none';
}
if (!data.success) {
if (!incremental) {
document.getElementById('emptyState').style.display = 'block';
}
return;
}
const logs = data.logs || [];
if (logs.length === 0 && !incremental) {
document.getElementById('emptyState').style.display = 'block';
return;
}
renderLogs(logs, incremental);
if (!incremental) {
document.getElementById('logsContainer').style.display = 'block';
if (data.pages > 1) {
renderPagination(data.total, data.pages, page);
document.getElementById('pagination').style.display = 'block';
}
}
} catch (error) {
if (!incremental) {
document.getElementById('loadingIndicator').style.display = 'none';
showToast('加载失败', 'error');
}
}
}
// 渲染日志
function renderLogs(logs, append = false) {
const container = document.getElementById('logsList');
if (!append) {
container.innerHTML = '';
lastLogId = 0;
}
logs.forEach(log => {
if (log.id > lastLogId) {
lastLogId = log.id;
}
const levelColors = {
'info': 'text-blue-600 dark:text-blue-400',
'success': 'text-green-600 dark:text-green-400',
'warning': 'text-yellow-600 dark:text-yellow-400',
'error': 'text-red-600 dark:text-red-400'
};
const logClass = levelColors[log.level] || 'text-gray-600 dark:text-gray-400';
const taskInfo = log.task_id ? `<span class="text-gray-400">[任务#${log.task_id}]</span> ` : '';
const logHtml = `
<div class="p-3 rounded-lg bg-white/50 dark:bg-black/30 border border-gray-100 dark:border-gray-800 hover:bg-white dark:hover:bg-black transition-colors">
<span class="text-gray-400 text-xs">${formatTime(log.created_at)}</span>
<span class="${logClass} font-bold text-xs">[${log.level.toUpperCase()}]</span>
${taskInfo}<span class="text-gray-700 dark:text-gray-300">${escapeHtml(log.message)}</span>
</div>
`;
container.insertAdjacentHTML('beforeend', logHtml);
// 防 DOM 无限增长(长挂机内存泄漏)
while (container.children.length > 500) container.firstChild.remove();
});
// 滚动到底部(如果是追加模式)
if (append) {
container.scrollTop = container.scrollHeight;
}
}
// 渲染分页
function renderPagination(total, pages, current) {
const nav = document.getElementById('pagination').querySelector('div');
let html = '';
html += `
<button onclick="loadLogs(${current - 1})" ${current === 1 ? 'disabled' : ''}
class="px-3 py-1 rounded-lg border border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors disabled:opacity-50 disabled:cursor-not-allowed">
上一页
</button>
`;
for (let i = 1; i <= pages; i++) {
if (i === 1 || i === pages || (i >= current - 2 && i <= current + 2)) {
html += `
<button onclick="loadLogs(${i})"
class="px-3 py-1 rounded-lg transition-colors ${i === current ? 'bg-black dark:bg-white text-white dark:text-black' : 'border border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800'}">
${i}
</button>
`;
} else if (i === current - 3 || i === current + 3) {
html += `<span class="px-2 text-gray-400">...</span>`;
}
}
html += `
<button onclick="loadLogs(${current + 1})" ${current === pages ? 'disabled' : ''}
class="px-3 py-1 rounded-lg border border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors disabled:opacity-50 disabled:cursor-not-allowed">
下一页
</button>
`;
nav.innerHTML = html;
}
// 加载任务列表(用于筛选)
async function loadTasksForFilter() {
try {
const data = await apiRequest('/api/tasks/list?per_page=100');
if (data.success && data.tasks) {
const select = document.getElementById('taskFilter');
// 保留第一个选项
const firstOption = select.options[0];
select.innerHTML = '';
select.appendChild(firstOption);
data.tasks.forEach(task => {
const option = document.createElement('option');
option.value = task.id;
option.textContent = `#${task.id} ${task.course_name}`;
select.appendChild(option);
});
}
} catch (error) {
console.error('加载任务列表失败:', error);
}
}
// 清空日志
async function clearLogs() {
if (!confirm('确定要清空所有日志吗?此操作不可恢复。')) return;
// 这里可以添加清空日志的API调用
showToast('日志已清空', 'success');
loadLogs();
}
// HTML转义
function escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// 设置自动刷新
function setupAutoRefresh() {
const checkbox = document.getElementById('autoRefresh');
if (checkbox.checked) {
autoRefreshInterval = setInterval(() => {
loadLogs(currentPage, true);
}, 3000);
} else {
if (autoRefreshInterval) {
clearInterval(autoRefreshInterval);
autoRefreshInterval = null;
}
}
}
// 页面加载
document.addEventListener('DOMContentLoaded', function() {
loadLogs();
loadTasksForFilter();
setupAutoRefresh();
});
</script>
{% endblock %}
+606
View File
@@ -0,0 +1,606 @@
<!DOCTYPE html>
<html lang="zh-CN" class="scroll-smooth">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<title>订单状态 - {{ brand_name }}</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
dark: {
bg: '#0a0a0a',
card: '#171717',
border: '#262626'
}
}
}
}
}
</script>
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;800;900&family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap"
rel="stylesheet">
<style>
body {
font-family: 'Inter', 'Noto Sans SC', sans-serif;
transition: background-color 0.3s ease, color 0.3s ease;
}
.glass {
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.9);
}
.dark .glass {
background: rgba(23, 23, 23, 0.85);
border: 1px solid rgba(38, 38, 38, 0.9);
}
.layer-4 {
box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.15);
}
.dark .layer-4 {
box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.7);
}
.bg-grid {
background-size: 40px 40px;
background-image: linear-gradient(to right, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
linear-gradient(to bottom, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
}
.dark .bg-grid {
background-image: linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
20%, 40%, 60%, 80% { transform: translateX(5px); }
}
.shake {
animation: shake 0.5s ease-in-out;
}
@keyframes pulse-warning {
0%, 100% { opacity: 1; }
50% { opacity: 0.6; }
}
.pulse-warning {
animation: pulse-warning 1.5s ease-in-out infinite;
}
/* Toast 通知 */
@media (min-width: 769px) {
.toast-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 9999;
pointer-events: none;
}
.toast {
background: #2c3e50;
color: white;
padding: 14px 22px;
border-radius: 8px;
margin-bottom: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
transform: translateX(100%);
opacity: 0;
transition: all 0.3s ease;
pointer-events: all;
min-width: 250px;
max-width: 350px;
font-size: 14px;
display: flex;
justify-content: space-between;
align-items: center;
}
.toast.show {
transform: translateX(0);
opacity: 1;
}
}
@media (max-width: 768px) {
.toast-container {
position: fixed;
bottom: max(20px, env(safe-area-inset-bottom));
left: 50%;
transform: translateX(-50%);
z-index: 9999;
pointer-events: none;
width: 90%;
max-width: 400px;
}
.toast {
background: #2c3e50;
color: white;
padding: 12px 20px;
border-radius: 24px;
margin-bottom: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
transform: translateY(100px);
opacity: 0;
transition: all 0.3s ease;
pointer-events: all;
width: 100%;
font-size: 14px;
text-align: center;
justify-content: center;
}
.toast.show {
transform: translateY(0);
opacity: 1;
}
}
.toast.error {
background: #e74c3c;
}
.toast.success {
background: #27ae60;
}
.dark .toast.error {
background: #ff6b6b;
}
.dark .toast.success {
background: #4caf50;
}
</style>
</head>
<body class="bg-neutral-50 text-neutral-900 dark:bg-dark-bg dark:text-neutral-100 min-h-screen">
<!-- Toast 通知容器 -->
<div class="toast-container" id="toastContainer"></div>
<!-- 导航 -->
<nav class="fixed w-full z-50 glass border-b border-black/5 dark:border-white/10 transition-colors duration-300">
<div class="max-w-6xl mx-auto px-4 md:px-6 h-16 flex justify-between items-center">
<a href="/buy" class="flex items-center gap-2 md:gap-3 group cursor-pointer">
<div class="w-8 h-8 bg-black dark:bg-white rounded-lg flex items-center justify-center text-white dark:text-black font-bold text-sm group-hover:rotate-12 transition-transform shrink-0">
S</div>
<span class="font-bold tracking-tight text-sm md:text-base truncate">{{ brand_name }}</span>
</a>
</div>
</nav>
<!-- 主内容区 -->
<main class="pt-24 md:pt-32 pb-16 md:pb-24 px-4 md:px-6 bg-grid min-h-screen flex items-center justify-center">
<div class="max-w-md w-full">
<div class="glass rounded-2xl md:rounded-3xl p-8 md:p-12 layer-4 text-center" id="mainCard">
<!-- 加载状态 -->
<div id="loadingState">
<div class="w-20 h-20 md:w-24 md:h-24 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mx-auto mb-6">
<svg class="w-10 h-10 md:w-12 md:h-12 text-blue-500 animate-spin" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
</div>
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">正在查询订单...</h1>
<p class="text-neutral-500 dark:text-neutral-400">请稍候</p>
</div>
<!-- 订单过期状态 -->
<div id="expiredState" class="hidden">
<div class="w-20 h-20 md:w-24 md:h-24 bg-orange-100 dark:bg-orange-900/30 rounded-full flex items-center justify-center mx-auto mb-6">
<svg class="w-10 h-10 md:w-12 md:h-12 text-orange-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">订单已过期</h1>
<p class="text-neutral-500 dark:text-neutral-400 mb-6">
该订单已超过5分钟有效期,请重新下单
</p>
<div class="bg-neutral-100 dark:bg-neutral-800 rounded-xl p-4 mb-6">
<div class="text-xs text-neutral-500 dark:text-neutral-400 mb-1">原订单号</div>
<div class="text-sm font-mono text-neutral-700 dark:text-neutral-300" id="expiredOrderId">-</div>
</div>
<a href="/buy" class="block w-full py-3 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-xl hover:shadow-lg transition-all">
重新购买
</a>
</div>
<!-- 订单取消状态 -->
<div id="cancelledState" class="hidden">
<div class="w-20 h-20 md:w-24 md:h-24 bg-gray-100 dark:bg-gray-800 rounded-full flex items-center justify-center mx-auto mb-6">
<svg class="w-10 h-10 md:w-12 md:h-12 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"></path>
</svg>
</div>
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">订单已取消</h1>
<p class="text-neutral-500 dark:text-neutral-400 mb-2" id="cancelReason">您已取消该订单</p>
<p class="text-neutral-500 dark:text-neutral-400 mb-6">
如需继续购买,请重新下单
</p>
<a href="/buy" class="block w-full py-3 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-xl hover:shadow-lg transition-all">
重新购买
</a>
</div>
<!-- 支付失败状态 -->
<div id="failedState" class="hidden">
<div class="w-20 h-20 md:w-24 md:h-24 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-6 shake">
<svg class="w-10 h-10 md:w-12 md:h-12 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</div>
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">支付失败</h1>
<p class="text-neutral-500 dark:text-neutral-400 mb-6" id="errorMsg">
支付过程中出现问题,请重新尝试
</p>
<div class="bg-neutral-100 dark:bg-neutral-800 rounded-xl p-4 mb-6">
<div class="text-xs text-neutral-500 dark:text-neutral-400 mb-1">订单号</div>
<div class="text-sm font-mono text-neutral-700 dark:text-neutral-300" id="failedOrderId">-</div>
</div>
<div class="space-y-3">
<a href="/buy" class="block w-full py-3 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-xl hover:shadow-lg transition-all">
重新购买
</a>
<a href="/" class="block w-full py-3 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-semibold rounded-xl hover:bg-neutral-300 dark:hover:bg-neutral-700 transition-colors">
返回首页
</a>
</div>
</div>
<!-- 订单待支付状态(5分钟内) -->
<div id="pendingState" class="hidden">
<!-- 倒计时警告 -->
<div class="bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-xl p-4 mb-6 pulse-warning">
<div class="flex items-center gap-3">
<svg class="w-6 h-6 text-orange-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<div class="text-left">
<div class="text-sm font-semibold text-orange-800 dark:text-orange-200">订单即将过期</div>
<div class="text-xs text-orange-600 dark:text-orange-400 mt-0.5">
剩余 <span id="countdown" class="font-bold">--:--</span> 自动失效
</div>
</div>
</div>
</div>
<div class="w-20 h-20 md:w-24 md:h-24 bg-yellow-100 dark:bg-yellow-900/30 rounded-full flex items-center justify-center mx-auto mb-6">
<svg class="w-10 h-10 md:w-12 md:h-12 text-yellow-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
<h1 class="text-2xl md:text-3xl font-bold mb-2 text-neutral-900 dark:text-white">等待支付</h1>
<p class="text-neutral-500 dark:text-neutral-400 mb-6">
订单尚未支付,如需取消请点击下方按钮
</p>
<div class="bg-neutral-100 dark:bg-neutral-800 rounded-xl p-4 mb-6">
<div class="text-xs text-neutral-500 dark:text-neutral-400 mb-1">订单号</div>
<div class="text-sm font-mono text-neutral-700 dark:text-neutral-300" id="pendingOrderId">-</div>
<div class="text-xs text-neutral-500 dark:text-neutral-400 mt-2 mb-1">应付金额</div>
<div class="text-lg font-bold text-neutral-900 dark:text-white">¥<span id="pendingAmount">-</span></div>
</div>
<div class="space-y-3">
<button id="retryPayBtn" onclick="retryPay()" class="w-full py-3 bg-black dark:bg-white text-white dark:text-black font-semibold rounded-xl hover:shadow-lg transition-all">
继续支付
</button>
<button id="cancelOrderBtn" onclick="cancelOrder()" class="w-full py-3 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-semibold rounded-xl hover:bg-neutral-300 dark:hover:bg-neutral-700 transition-colors">
取消订单
</button>
</div>
</div>
</div>
</div>
</main>
<script>
// 全局变量
let orderId = null;
let countdownTimer = null;
let currentOrderStatus = null;
// Toast 通知
function showToast(message, type = 'info', duration = 3000) {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
toast.innerHTML = `<span>${message}</span>`;
container.appendChild(toast);
setTimeout(() => toast.classList.add('show'), 10);
setTimeout(() => {
toast.classList.remove('show');
setTimeout(() => toast.remove(), 400);
}, duration);
}
// 主题初始化
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
}
// 从URL获取订单号
function getOrderIdFromUrl() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('orderNo') || urlParams.get('order_id') || '{{ order_id }}';
}
// 查询订单状态
async function fetchOrderStatus(orderId) {
try {
const response = await fetch(`/api/orders/${orderId}/status`);
const data = await response.json();
return data;
} catch (error) {
console.error('查询订单状态失败:', error);
return null;
}
}
// 获取订单详情
async function fetchOrder(orderId) {
try {
const response = await fetch(`/api/orders/${orderId}`);
const data = await response.json();
return data.order;
} catch (error) {
console.error('获取订单详情失败:', error);
return null;
}
}
// 获取支付参数并跳转
async function retryPay() {
if (!orderId) return;
const btn = document.getElementById('retryPayBtn');
btn.disabled = true;
btn.textContent = '正在获取支付信息...';
try {
const response = await fetch(`/api/api/orders/${orderId}/payment_params`);
const data = await response.json();
if (!data.success) {
showToast(data.message || '获取支付信息失败', 'error');
btn.disabled = false;
btn.textContent = '继续支付';
return;
}
// 构建支付表单
const form = document.createElement('form');
form.method = 'POST';
form.action = 'https://api-4ndv48ogy5fk.zhifu.fm.it88168.com/api/startOrder';
form.target = '_self';
form.style.display = 'none';
const fields = ['merchantNum', 'orderNo', 'amount', 'notifyUrl', 'returnUrl', 'payType', 'sign', 'returnType', 'subject'];
fields.forEach(field => {
if (data.params && data.params[field]) {
const input = document.createElement('input');
input.type = 'hidden';
input.name = field;
input.value = data.params[field];
form.appendChild(input);
}
});
document.body.appendChild(form);
form.submit();
} catch (error) {
console.error('支付跳转失败:', error);
showToast('支付跳转失败,请重试', 'error');
btn.disabled = false;
btn.textContent = '继续支付';
}
}
// 取消订单
async function cancelOrder() {
if (!orderId) return;
if (!confirm('确定要取消这个订单吗?取消后无法恢复。')) {
return;
}
const btn = document.getElementById('cancelOrderBtn');
btn.disabled = true;
btn.textContent = '正在取消...';
try {
const response = await fetch(`/api/orders/${orderId}/cancel`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ reason: '用户主动取消' })
});
const data = await response.json();
if (data.success) {
showToast('订单已取消', 'success');
// 停止倒计时
if (countdownTimer) {
clearInterval(countdownTimer);
}
// 更新UI
document.getElementById('pendingState').classList.add('hidden');
document.getElementById('cancelledState').classList.remove('hidden');
} else {
showToast(data.message || '取消订单失败', 'error');
btn.disabled = false;
btn.textContent = '取消订单';
}
} catch (error) {
console.error('取消订单失败:', error);
showToast('取消订单失败,请重试', 'error');
btn.disabled = false;
btn.textContent = '取消订单';
}
}
// 更新倒计时显示
function updateCountdown(remainingSeconds) {
const countdownEl = document.getElementById('countdown');
if (remainingSeconds <= 0) {
countdownEl.textContent = '00:00';
// 停止倒计时
if (countdownTimer) {
clearInterval(countdownTimer);
}
// 刷新状态
checkOrderStatus();
return;
}
const minutes = Math.floor(remainingSeconds / 60);
const seconds = remainingSeconds % 60;
countdownEl.textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
}
// 检查订单状态
async function checkOrderStatus() {
if (!orderId) return;
const data = await fetchOrderStatus(orderId);
if (!data) {
showFailedState('无法获取订单状态');
return;
}
currentOrderStatus = data;
// 根据状态显示不同UI
if (data.status === 'pending') {
if (data.is_expired || data.remaining_seconds <= 0) {
showExpiredState();
} else {
showPendingState(data, await fetchOrder(orderId));
}
} else if (data.status === 'cancelled' || data.status === 'expired') {
if (data.status === 'cancelled') {
showCancelledState(data.cancel_reason);
} else {
showExpiredState();
}
} else if (data.status === 'paid' || data.status === 'processed') {
// 订单已支付,跳转到成功页面
window.location.href = `/success/${orderId}`;
} else {
// 其他状态(如 failed)
showFailedState();
}
}
// 显示加载状态
function showLoadingState() {
document.getElementById('loadingState').classList.remove('hidden');
document.getElementById('expiredState').classList.add('hidden');
document.getElementById('cancelledState').classList.add('hidden');
document.getElementById('failedState').classList.add('hidden');
document.getElementById('pendingState').classList.add('hidden');
}
// 显示订单过期状态
function showExpiredState() {
document.getElementById('loadingState').classList.add('hidden');
document.getElementById('expiredState').classList.remove('hidden');
document.getElementById('cancelledState').classList.add('hidden');
document.getElementById('failedState').classList.add('hidden');
document.getElementById('pendingState').classList.add('hidden');
document.getElementById('expiredOrderId').textContent = orderId;
}
// 显示订单取消状态
function showCancelledState(reason) {
document.getElementById('loadingState').classList.add('hidden');
document.getElementById('expiredState').classList.add('hidden');
document.getElementById('cancelledState').classList.remove('hidden');
document.getElementById('failedState').classList.add('hidden');
document.getElementById('pendingState').classList.add('hidden');
document.getElementById('cancelReason').textContent = reason || '您已取消该订单';
}
// 显示支付失败状态
function showFailedState(errorMsg) {
document.getElementById('loadingState').classList.add('hidden');
document.getElementById('expiredState').classList.add('hidden');
document.getElementById('cancelledState').classList.add('hidden');
document.getElementById('failedState').classList.remove('hidden');
document.getElementById('pendingState').classList.add('hidden');
if (errorMsg) {
document.getElementById('errorMsg').textContent = errorMsg;
}
document.getElementById('failedOrderId').textContent = orderId;
}
// 显示待支付状态
async function showPendingState(statusData, orderData) {
document.getElementById('loadingState').classList.add('hidden');
document.getElementById('expiredState').classList.add('hidden');
document.getElementById('cancelledState').classList.add('hidden');
document.getElementById('failedState').classList.add('hidden');
document.getElementById('pendingState').classList.remove('hidden');
document.getElementById('pendingOrderId').textContent = orderId;
if (orderData) {
document.getElementById('pendingAmount').textContent = orderData.final_amount || orderData.amount || '-';
}
// 启动倒计时
if (countdownTimer) {
clearInterval(countdownTimer);
}
let remaining = statusData.remaining_seconds || 0;
updateCountdown(remaining);
countdownTimer = setInterval(() => {
remaining--;
updateCountdown(remaining);
}, 1000);
}
// 页面加载时查询订单状态
window.addEventListener('load', async () => {
orderId = getOrderIdFromUrl();
if (!orderId || orderId === '{{ order_id }}') {
// 没有订单号,跳转到购买页面
window.location.href = '/buy';
return;
}
showLoadingState();
// 延迟一点再查询,让用户看到加载状态
await new Promise(resolve => setTimeout(resolve, 500));
checkOrderStatus();
});
// 页面离开时清理定时器
window.addEventListener('beforeunload', () => {
if (countdownTimer) {
clearInterval(countdownTimer);
}
});
</script>
</body>
</html>
+321
View File
@@ -0,0 +1,321 @@
<!DOCTYPE html>
<html lang="zh-CN" class="scroll-smooth">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% if pending %}支付确认中{% else %}支付成功 - 兑换码领取{% endif %}</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
dark: {
bg: '#0a0a0a',
card: '#171717',
border: '#262626'
}
}
}
}
}
</script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;800;900&family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', 'Noto Sans SC', sans-serif;
transition: background-color 0.3s ease, color 0.3s ease;
}
.glass {
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.9);
}
.dark .glass {
background: rgba(23, 23, 23, 0.85);
border: 1px solid rgba(38, 38, 38, 0.9);
}
.layer-3 {
box-shadow: 0 12px 40px -5px rgba(0, 0, 0, 0.12);
}
.dark .layer-3 {
box-shadow: 0 12px 40px -5px rgba(0, 0, 0, 0.6);
}
.bg-grid {
background-size: 40px 40px;
background-image: linear-gradient(to right, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
linear-gradient(to bottom, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
}
.dark .bg-grid {
background-image: linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
}
.btn-primary {
background: #111;
color: #fff;
position: relative;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.dark .btn-primary {
background: #fff;
color: #000;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px -5px rgba(0, 0 0, 0.3);
}
.dark .btn-primary:hover {
box-shadow: 0 10px 30px -5px rgba(255, 255, 255, 0.2);
}
.code-card {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
overflow: hidden;
}
.code-card:hover {
transform: translateY(-2px);
border-color: #111;
}
.dark .code-card:hover {
border-color: #fff;
}
.code-card:active {
transform: scale(0.98);
}
.code-card.copied {
border-color: #10b981 !important;
background: rgba(16, 185, 129, 0.05) !important;
}
.code-card.copied::after {
content: "已复制";
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
background: #10b981;
color: white;
padding: 4px 12px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-50%) translateX(10px); }
to { opacity: 1; transform: translateY(-50%) translateX(0); }
}
@keyframes slideUp {
from { opacity: 0; transform: translateY(30px); }
to { opacity: 1; transform: translateY(0); }
}
.animate-slide-up {
animation: slideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.success-check {
animation: scaleIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes scaleIn {
from { transform: scale(0); opacity: 0; }
to { transform: scale(1); opacity: 1; }
}
.spinner {
width: 50px;
height: 50px;
border: 4px solid #e5e5e5;
border-top: 4px solid #111;
border-radius: 50%;
animation: spin 1s linear infinite;
}
.dark .spinner {
border-color: #262626;
border-top-color: #fff;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body class="bg-neutral-50 text-neutral-900 dark:bg-dark-bg dark:text-neutral-100 min-h-screen flex items-center justify-center p-4 bg-grid">
{% if status == 'pending' %}
<!-- 等待支付确认状态 -->
<div class="glass rounded-3xl p-10 layer-3 text-center max-w-md w-full animate-slide-up">
<div class="spinner mx-auto mb-6"></div>
<h2 class="text-2xl font-bold mb-2 text-neutral-900 dark:text-white">正在确认支付结果...</h2>
<p class="text-neutral-500 dark:text-neutral-400 mb-6">请稍候,系统正在处理您的订单</p>
<div class="inline-flex items-center gap-2 px-4 py-2 bg-neutral-100 dark:bg-neutral-800 rounded-full">
<span class="w-2 h-2 bg-neutral-400 rounded-full animate-pulse"></span>
<span class="text-xs text-neutral-500 dark:text-neutral-400 font-mono">{{ order_id }}</span>
</div>
<p class="mt-6 text-xs text-neutral-400 dark:text-neutral-500">页面将在 3 秒后自动刷新</p>
</div>
<script>
setTimeout(() => location.reload(), 3000);
</script>
{% else %}
<!-- 支付成功状态 -->
<!-- Toast 容器 -->
<div class="toast-container" id="toastContainer"></div>
<div class="w-full max-w-lg animate-slide-up">
<!-- 成功状态卡片 -->
<div class="glass rounded-3xl p-8 md:p-10 layer-3 mb-6 text-center">
<!-- 成功图标 -->
<div class="success-check w-20 h-20 bg-black dark:bg-white rounded-full flex items-center justify-center mx-auto mb-6 text-white dark:text-black shadow-lg">
<svg class="w-10 h-10" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"></path>
</svg>
</div>
<h1 class="text-3xl md:text-4xl font-black tracking-tight mb-2 text-neutral-900 dark:text-white">支付成功</h1>
<p class="text-neutral-500 dark:text-neutral-400 mb-8">您的授权兑换码已生成</p>
<!-- 订单信息 -->
<div class="bg-neutral-100 dark:bg-neutral-800/50 rounded-2xl p-6 mb-8 text-left space-y-3">
<div class="flex justify-between items-center text-sm">
<span class="text-neutral-500 dark:text-neutral-400">订单编号</span>
<span class="font-mono font-medium text-neutral-900 dark:text-white text-xs tracking-wider">{{ order.order_id }}</span>
</div>
<div class="flex justify-between items-center text-sm">
<span class="text-neutral-500 dark:text-neutral-400">支付金额</span>
<span class="font-bold text-lg text-neutral-900 dark:text-white">¥{{ order.amount }}</span>
</div>
<div class="flex justify-between items-center text-sm">
<span class="text-neutral-500 dark:text-neutral-400">购买份数</span>
<div class="flex items-center gap-2">
<span class="font-medium text-neutral-900 dark:text-white">{{ order.quantity }} 份</span>
<span class="px-2 py-0.5 bg-neutral-200 dark:bg-neutral-700 text-neutral-600 dark:text-neutral-300 text-[10px] font-bold rounded-full">有效期至本学期结束</span>
</div>
</div>
</div>
<!-- 兑换码区域 -->
<div class="text-left mb-6">
<div class="flex items-center justify-between mb-4">
<h3 class="text-sm font-bold uppercase tracking-wider text-neutral-500 dark:text-neutral-400">兑换码列表</h3>
<span class="text-xs text-neutral-400 dark:text-neutral-500">点击复制</span>
</div>
<div class="space-y-3" id="codesContainer">
{% for code in codes %}
<div class="code-card bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-xl p-4 font-mono text-sm md:text-base tracking-wider text-center text-neutral-900 dark:text-white cursor-pointer select-all" onclick="copyCode(this, '{{ code }}')">
{{ code }}
</div>
{% endfor %}
</div>
</div>
<!-- 下载按钮 -->
<a href="{{ download_url }}" class="btn-primary w-full py-4 rounded-full font-bold text-sm tracking-wide inline-flex items-center justify-center gap-2 group">
<svg class="w-5 h-5 transition-transform group-hover:-translate-y-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path>
</svg>
立即下载软件
</a>
<p class="mt-3 text-xs text-neutral-400 dark:text-neutral-500">
Windows 10/11 64位 · 版本 {{ version }}
</p>
</div>
<!-- 提示信息 -->
<div class="glass rounded-2xl p-6 layer-1 border-l-4 border-l-yellow-500 dark:border-l-yellow-600">
<div class="flex items-start gap-3">
<svg class="w-5 h-5 text-yellow-600 dark:text-yellow-500 mt-0.5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>
</svg>
<div class="text-sm text-neutral-600 dark:text-neutral-300 leading-relaxed">
<strong class="text-neutral-900 dark:text-white block mb-1">重要提示</strong>
首个兑换码已自动复制到剪贴板。每个兑换码仅限激活一台设备,激活后当前选课周期内有效。请妥善保存订单编号以便日后查询。
</div>
</div>
</div>
</div>
<script>
// 主题初始化(跟随系统)
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
}
// Toast 通知
function showToast(message) {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = 'toast';
toast.innerHTML = `<span>${message}</span>`;
container.appendChild(toast);
setTimeout(() => toast.classList.add('show'), 10);
setTimeout(() => {
toast.classList.remove('show');
setTimeout(() => toast.remove(), 400);
}, 3000);
}
// 复制功能
async function copyToClipboard(text) {
try {
await navigator.clipboard.writeText(text);
showToast(`已复制: ${text}`);
} catch (err) {
const input = document.createElement('input');
input.value = text;
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
showToast('已复制到剪贴板');
}
}
function copyCode(element, text) {
copyToClipboard(text);
element.classList.add('copied');
setTimeout(() => element.classList.remove('copied'), 2000);
}
// 页面加载后自动复制第一个兑换码
window.addEventListener('load', () => {
setTimeout(() => {
const firstCode = document.querySelector('.code-card');
if (firstCode) {
const codeText = firstCode.textContent.trim();
copyToClipboard(codeText);
firstCode.classList.add('copied');
setTimeout(() => firstCode.classList.remove('copied'), 2000);
}
}, 800);
});
</script>
{% endif %}
</body>
</html>
+139
View File
@@ -0,0 +1,139 @@
{% extends "base_tailwind.html" %}
{% block title %}个人信息 - {{ brand_name }}{% endblock %}
{% block extra_css %}
<style>
.info-label { color: #6b7280; }
.dark .info-label { color: #9ca3af; }
.info-value { font-weight: 500; }
@keyframes fadeSlideIn {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
.row-animate { animation: fadeSlideIn 0.3s ease both; }
</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">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/>
<circle cx="12" cy="7" r="4"/>
</svg>
个人信息
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">查看学籍基本信息</p>
</div>
<button onclick="refreshInfo()"
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 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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden list-item-enter">
<p id="errorText" class="text-red-500"></p>
</div>
<div id="infoContainer" class="hidden list-item-enter" style="animation-delay: 150ms;">
<div class="glass rounded-2xl p-6">
<div id="infoGrid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"></div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
// ── 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; }
}
const LABEL_MAP = {
'xh': '学号', 'xm': '姓名', 'xbm': '性别', 'csrq': '出生日期',
'mzm': '民族', 'zym': '专业', 'jg': '籍贯', 'bjm': '班级',
'yxm': '院系', 'nj': '年级', 'xz': '学制', 'rxrq': '入学日期',
'sfzh': '身份证号', 'lxsj': '联系电话', 'email': '电子邮箱',
'jtdz': '家庭地址', 'BJ': '班级', 'NJ': '年级', 'ZY': '专业',
'YX': '院系', 'XM': '姓名', 'XH': '学号', 'XB': '性别',
};
async function refreshInfo() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('infoContainer').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/personal-info');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) {
document.getElementById('errorText').textContent = data.message || '查询失败';
document.getElementById('errorMessage').classList.remove('hidden');
return;
}
renderInfo(data.info || {});
document.getElementById('infoContainer').classList.remove('hidden');
} catch (e) {
document.getElementById('loadingIndicator').classList.add('hidden');
document.getElementById('errorText').textContent = '网络错误: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
function renderInfo(info) {
const grid = document.getElementById('infoGrid');
if (!info || !Object.keys(info).length) {
grid.innerHTML = '<p class="text-center text-gray-400 col-span-full">暂无数据</p>';
return;
}
const entries = [];
for (const [key, value] of Object.entries(info)) {
const label = LABEL_MAP[key] || key;
if (key.startsWith('_') || value === null || value === '' || typeof value === 'object') continue;
if (key.toLowerCase().includes('password') || key.toLowerCase().includes('pwd')) continue;
entries.push({ label, value });
}
if (!entries.length) {
grid.innerHTML = '<p class="text-center text-gray-400 col-span-full">暂无有效字段</p>';
return;
}
grid.innerHTML = entries.map((e, i) => `
<div class="row-animate flex flex-col gap-1 p-3 rounded-xl bg-gray-50/50 dark:bg-gray-800/30" style="animation-delay:${i * 30}ms;">
<span class="info-label text-xs">${e.label}</span>
<span class="info-value text-sm">${e.value}</span>
</div>
`).join('');
}
initSession().then(sessionOk => {
if (!sessionOk) console.warn('教务 Session 可能已失效');
refreshInfo();
});
</script>
{% endblock %}
+91
View File
@@ -0,0 +1,91 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
个人信息编辑
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">编辑个人基本信息</p>
</div>
</div>
<div id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="formContainer" class="hidden">
<div class="glass rounded-2xl p-6 max-w-2xl mx-auto">
<form id="editForm">
<div id="formFields"></div>
<div class="mt-6 flex gap-3">
<button type="submit" class="px-6 py-2.5 rounded-lg bg-black dark:bg-white text-white dark:text-black text-sm font-medium hover:opacity-85 transition-opacity">保存修改</button>
<button type="button" onclick="loadData()" class="px-4 py-2.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm font-medium">刷新</button>
</div>
</form>
<div id="resultMessage" class="mt-4 hidden"></div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">无可编辑字段</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('formContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/personal-info-editable');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const fields = data.fields || [];
if (!fields.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const container = document.getElementById('formFields');
container.innerHTML = fields.map(f => {
if (f.readonly) return '';
let input;
if (f.type === 'select') {
input = `<select name="${escAttr(f.name)}" class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">${f.options.map(o => `<option value="${escAttr(o.value)}" ${o.selected?'selected':''}>${escHtml(o.label)}</option>`).join('')}</select>`;
} else {
input = `<input type="text" name="${escAttr(f.name)}" value="${escAttr(f.value)}" class="w-full rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 px-3 py-2 text-sm">`;
}
return `<div class="mb-4"><label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">${escHtml(f.label)}</label>${input}</div>`;
}).join('');
document.getElementById('formContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
document.getElementById('editForm').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const data = Object.fromEntries(formData.entries());
const resultEl = document.getElementById('resultMessage');
resultEl.classList.remove('hidden');
resultEl.innerHTML = '<p class="text-gray-500">提交中...</p>';
try {
const res = await fetch('/api/jwxt/personal-info/update', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(data) });
const result = await res.json();
resultEl.innerHTML = result.success ? '<p class="text-green-600">✅ 更新成功</p>' : '<p class="text-red-500">❌ ' + escHtml(result.message) + '</p>';
} catch(e) { resultEl.innerHTML = '<p class="text-red-500">❌ 网络错误</p>'; }
});
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function escAttr(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+67
View File
@@ -0,0 +1,67 @@
{% extends "base_tailwind.html" %}
{% block title %}隐私政策 - {{ brand_name }}{% endblock %}
{% block extra_css %}
<style>
.prose h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }
.prose h2 { font-size: 1.1rem; font-weight: 700; margin-top: 2rem; margin-bottom: 0.75rem; padding-bottom: 0.4rem; border-bottom: 1px solid rgba(0,0,0,0.08); }
.dark .prose h2 { border-bottom-color: rgba(255,255,255,0.08); }
.prose h3 { font-size: 0.95rem; font-weight: 600; margin-top: 1.25rem; margin-bottom: 0.5rem; }
.prose p { margin-bottom: 0.75rem; line-height: 1.75; color: #4b5563; }
.dark .prose p { color: #9ca3af; }
.prose ul, .prose ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.prose li { margin-bottom: 0.35rem; line-height: 1.7; color: #4b5563; }
.dark .prose li { color: #9ca3af; }
.prose ul li { list-style-type: disc; }
.prose strong { font-weight: 600; color: #111827; }
.dark .prose strong { color: #f3f4f6; }
.prose table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.875rem; }
.prose th { background: #f3f4f6; font-weight: 600; padding: 0.6rem 0.8rem; text-align: left; border: 1px solid #e5e7eb; }
.dark .prose th { background: #1f2937; border-color: #374151; }
.prose td { padding: 0.6rem 0.8rem; border: 1px solid #e5e7eb; }
.dark .prose td { border-color: #374151; }
.prose hr { border: none; border-top: 1px solid #e5e7eb; margin: 1.5rem 0; }
.dark .prose hr { border-top-color: #374151; }
.prose code { background: #f3f4f6; padding: 0.1em 0.4em; border-radius: 4px; font-size: 0.85em; }
.dark .prose code { background: #1f2937; }
.prose blockquote { border-left: 3px solid #e5e7eb; padding-left: 1rem; color: #6b7280; margin: 1rem 0; }
.dark .prose blockquote { border-color: #374151; color: #9ca3af; }
</style>
{% endblock %}
{% block content %}
<div class="max-w-3xl mx-auto py-4">
<!-- 返回 -->
<div class="mb-6 list-item-enter" style="animation-delay:0ms">
<a href="javascript:history.back()" class="inline-flex items-center gap-1.5 text-sm text-neutral-500 hover:text-neutral-800 dark:hover:text-neutral-200 transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
返回
</a>
</div>
<div class="glass rounded-3xl p-6 md:p-10 layer-3 list-item-enter" style="animation-delay:50ms">
<!-- 头部 -->
<div class="flex items-start gap-4 mb-8 pb-6 border-b border-neutral-200 dark:border-neutral-800">
<div class="w-12 h-12 rounded-2xl bg-black dark:bg-white flex items-center justify-center text-white dark:text-black font-bold text-lg flex-shrink-0">S</div>
<div>
<h1 class="text-xl md:text-2xl font-bold text-neutral-900 dark:text-white">隐私政策</h1>
<p class="text-sm text-neutral-500 dark:text-neutral-400 mt-1">{{ brand_name }}</p>
</div>
</div>
<!-- 正文:由后端读取 docs/privacy.md 渲染 -->
<div class="prose text-sm md:text-base text-neutral-800 dark:text-neutral-200">
{{ content | safe }}
</div>
<!-- 底部链接 -->
<div class="mt-8 pt-6 border-t border-neutral-200 dark:border-neutral-800 flex gap-4 text-sm text-neutral-500">
<a href="{{ url_for('main.terms') }}" class="hover:text-black dark:hover:text-white transition-colors underline underline-offset-2">用户服务协议</a>
<a href="{{ url_for('main.buy') }}" class="hover:text-black dark:hover:text-white transition-colors underline underline-offset-2">购买页面</a>
</div>
</div>
</div>
{% endblock %}
+275
View File
@@ -0,0 +1,275 @@
{% extends "base_tailwind.html" %}
{% block title %}注册 - {{ brand_name }}{% endblock %}
{% block content %}
<div class="min-h-[70vh] flex items-center justify-center py-8">
<div class="w-full max-w-md">
<!-- 注册卡片 -->
<div class="glass rounded-3xl p-8 layer-4 list-item-enter" style="animation-delay: 0ms;">
<!-- Logo -->
<div class="text-center mb-8">
<div class="w-16 h-16 bg-black dark:bg-white rounded-2xl flex items-center justify-center text-white dark:text-black font-bold text-2xl mx-auto mb-4">
S
</div>
<h1 class="text-2xl font-bold text-neutral-900 dark:text-white">创建账号</h1>
<p class="text-neutral-500 dark:text-neutral-400 mt-2">填写以下信息完成注册</p>
</div>
<!-- 注册表单 -->
<form id="registerForm" onsubmit="handleRegister(event)" class="space-y-4">
<!-- 注册码 -->
<div>
<label class="input-label">
注册码
<span class="text-red-500">*</span>
</label>
<div class="relative">
<input type="text" name="ticket_code" id="ticket_code" class="input-field font-mono uppercase" placeholder="XXXX-XXXX-XXXX-XXXX" required>
<a href="{{ url_for('main.buy') }}" class="absolute right-3 top-1/2 -translate-y-1/2 text-xs text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition">
购买注册码
</a>
</div>
<p class="text-xs text-neutral-500 mt-1" id="ticketSchoolHint">输入注册码后将显示可选学校</p>
</div>
<div>
<label class="input-label" for="school_id">学校 <span class="text-red-500">*</span></label>
<select id="school_id" name="school_id" class="input-field" required>
<option value="">请选择学校</option>
{% for school in schools %}<option value="{{ school.id }}">{{ school.name }}</option>{% endfor %}
</select>
<p class="text-xs text-neutral-500 mt-1">注册后学校不可修改</p>
</div>
<!-- 网站账号 -->
<div class="border-t border-neutral-200 dark:border-neutral-800 pt-4">
<h3 class="text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-3">网站登录账号</h3>
<div class="space-y-4">
<div>
<label class="input-label">用户名</label>
<input type="text" name="username" id="username" class="input-field" placeholder="设置登录用户名" required>
</div>
<div>
<label class="input-label">密码</label>
<input type="password" name="password" id="password" class="input-field" placeholder="设置登录密码" required>
</div>
</div>
</div>
<!-- 教务系统账号 -->
<div class="border-t border-neutral-200 dark:border-neutral-800 pt-4">
<h3 class="text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-3">教务系统账号(用于抢课)</h3>
<div class="space-y-4">
<div>
<label class="input-label">学号</label>
<input type="text" name="jwxt_username" id="jwxt_username" class="input-field" placeholder="请输入学号" required>
</div>
<div>
<label class="input-label">密码</label>
<input type="password" name="jwxt_password" id="jwxt_password" class="input-field" placeholder="请输入教务系统密码" required>
</div>
<div>
<label class="input-label">姓名(选填)</label>
<input type="text" name="jwxt_name" id="jwxt_name" class="input-field" placeholder="请输入姓名">
</div>
</div>
</div>
<div id="errorMessage" class="hidden p-3 bg-red-50 dark:bg-red-900/20 border border-red-100 dark:border-red-800 rounded-xl text-sm text-red-800 dark:text-red-200">
</div>
<div id="successMessage" class="hidden p-3 bg-green-50 dark:bg-green-900/20 border border-green-100 dark:border-green-800 rounded-xl text-sm text-green-800 dark:text-green-200">
</div>
<!-- 协议勾选 -->
<label class="flex items-start gap-2.5 cursor-pointer select-none" id="termsLabel">
<div class="relative flex-shrink-0 mt-0.5">
<input type="checkbox" id="agreeTerms" class="sr-only" onchange="updateCheckbox(this)">
<div id="checkboxBox" class="w-[18px] h-[18px] rounded border-2 border-neutral-300 dark:border-neutral-600 transition-all flex items-center justify-center">
<svg id="checkIcon" class="w-2.5 h-2.5 text-white dark:text-black hidden" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"/>
</svg>
</div>
</div>
<span class="text-xs text-neutral-500 dark:text-neutral-400 leading-relaxed">
我已阅读并同意
<a href="{{ url_for('main.terms') }}" target="_blank" onclick="event.stopPropagation()" class="text-neutral-800 dark:text-neutral-200 font-medium underline underline-offset-2 hover:text-black dark:hover:text-white">用户服务协议</a>
和
<a href="{{ url_for('main.privacy') }}" target="_blank" onclick="event.stopPropagation()" class="text-neutral-800 dark:text-neutral-200 font-medium underline underline-offset-2 hover:text-black dark:hover:text-white">隐私政策</a>,包括本服务收集并使用我的教务系统账号信息
</span>
</label>
<button type="submit" id="submitBtn" class="w-full btn-primary py-3.5 rounded-full text-sm font-bold mt-6">
注册
</button>
</form>
<!-- 分割线 -->
<div class="relative my-6">
<div class="absolute inset-0 flex items-center">
<div class="w-full border-t border-neutral-200 dark:border-neutral-800"></div>
</div>
<div class="relative flex justify-center text-sm">
<span class="px-4 bg-white dark:bg-dark-card text-neutral-500">已有账号?</span>
</div>
</div>
<!-- 登录按钮 -->
<a href="{{ url_for('main.login') }}" class="block w-full py-3.5 rounded-full text-sm font-bold text-center border-2 border-neutral-200 dark:border-neutral-800 text-neutral-700 dark:text-neutral-300 hover:border-neutral-400 dark:hover:border-neutral-600 transition">
立即登录
</a>
<!-- 购买按钮 -->
<a href="{{ url_for('main.buy') }}" class="block w-full py-3.5 rounded-full text-sm font-bold text-center border-2 border-neutral-200 dark:border-neutral-800 text-neutral-700 dark:text-neutral-300 hover:border-neutral-400 dark:hover:border-neutral-600 transition mt-3">
购买注册码
</a>
</div>
<!-- 返回首页 -->
<div class="text-center mt-6">
<a href="{{ url_for('main.buy') }}" class="text-sm text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition flex items-center justify-center gap-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path>
</svg>
返回首页
</a>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
function updateCheckbox(input) {
const box = document.getElementById('checkboxBox');
const icon = document.getElementById('checkIcon');
if (input.checked) {
box.classList.remove('border-neutral-300', 'dark:border-neutral-600');
box.classList.add('bg-black', 'border-black', 'dark:bg-white', 'dark:border-white');
icon.classList.remove('hidden');
} else {
box.classList.add('border-neutral-300', 'dark:border-neutral-600');
box.classList.remove('bg-black', 'border-black', 'dark:bg-white', 'dark:border-white');
icon.classList.add('hidden');
}
}
// 格式化注册码输入
document.getElementById('ticket_code').addEventListener('input', function(e) {
let value = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, '');
let formatted = '';
for (let i = 0; i < value.length && i < 16; i++) {
if (i > 0 && i % 4 === 0) formatted += '-';
formatted += value[i];
}
e.target.value = formatted;
});
const allSchools = {{ schools | map(attribute='id') | list | tojson }};
let ticketCheckTimer;
document.getElementById('ticket_code').addEventListener('input', () => {
clearTimeout(ticketCheckTimer);
ticketCheckTimer = setTimeout(checkTicketSchools, 350);
});
async function checkTicketSchools() {
const code = document.getElementById('ticket_code').value.replace(/[^A-Z0-9]/gi, '').toUpperCase();
const select = document.getElementById('school_id');
const hint = document.getElementById('ticketSchoolHint');
const choices = [...select.options].slice(1);
if (code.length !== 16) {
choices.forEach(option => option.hidden = false);
select.disabled = false;
hint.textContent = '输入注册码后将显示可选学校';
return;
}
try {
const response = await fetch('/api/tickets/schools/' + encodeURIComponent(code));
const data = await response.json();
if (code !== document.getElementById('ticket_code').value.replace(/[^A-Z0-9]/gi, '').toUpperCase()) return;
if (!data.success) {
choices.forEach(option => option.hidden = false);
select.disabled = false;
hint.textContent = data.message;
return;
}
const allowed = data.school_ids === null ? allSchools : data.school_ids;
choices.forEach(option => option.hidden = !allowed.includes(option.value));
if (!allowed.includes(select.value)) select.value = allowed.length === 1 ? allowed[0] : '';
select.disabled = allowed.length === 1;
hint.textContent = allowed.length === 1 ? '该注册码仅限所选学校,学校已锁定' :
(data.school_ids === null ? '该注册码适用于全部学校' : '请从注册码允许的学校中选择');
} catch (error) { hint.textContent = '暂时无法检查注册码适用学校'; }
}
async function handleRegister(event) {
event.preventDefault();
// 验证协议勾选
if (!document.getElementById('agreeTerms').checked) {
const errorDiv = document.getElementById('errorMessage');
errorDiv.textContent = '请先阅读并同意用户服务协议和隐私政策';
errorDiv.classList.remove('hidden');
return;
}
// 去掉注册码中的横线,只保留字母和数字
const ticketCode = document.getElementById('ticket_code').value.replace(/[^A-Z0-9]/gi, '').toUpperCase();
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value;
const jwxtUsername = document.getElementById('jwxt_username').value.trim();
const jwxtPassword = document.getElementById('jwxt_password').value;
const jwxtName = document.getElementById('jwxt_name').value.trim();
const schoolId = document.getElementById('school_id').value;
const submitBtn = document.getElementById('submitBtn');
const errorDiv = document.getElementById('errorMessage');
const successDiv = document.getElementById('successMessage');
// 禁用按钮
submitBtn.disabled = true;
submitBtn.innerHTML = '<span class="inline-block w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"></span>注册中...';
errorDiv.classList.add('hidden');
successDiv.classList.add('hidden');
try {
const response = await fetch('{{ url_for('main.register') }}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
ticket_code: ticketCode,
username: username,
password: password,
jwxt_username: jwxtUsername,
jwxt_password: jwxtPassword,
jwxt_name: jwxtName,
school_id: schoolId
})
});
const data = await response.json();
if (data.success) {
successDiv.textContent = data.message || '注册成功,即将跳转到登录页面...';
successDiv.classList.remove('hidden');
setTimeout(() => {
window.location.href = '{{ url_for('main.login') }}';
}, 1500);
} else {
errorDiv.textContent = data.message || '注册失败';
errorDiv.classList.remove('hidden');
submitBtn.disabled = false;
submitBtn.innerHTML = '注册';
}
} catch (error) {
errorDiv.textContent = '网络错误,请稍后重试';
errorDiv.classList.remove('hidden');
submitBtn.disabled = false;
submitBtn.innerHTML = '注册';
}
}
</script>
{% endblock %}
+314
View File
@@ -0,0 +1,314 @@
{% 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; }
</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">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</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="xnmSelect" class="px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部学年</option>
</select>
<select id="xqmSelect" class="px-4 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部学期</option>
<option value="3">第一学期</option>
<option value="12">第二学期</option>
</select>
<label class="flex items-center gap-2 text-sm cursor-pointer select-none">
<input type="checkbox" id="myFailedOnly" checked onchange="refresh()"
class="w-4 h-4 rounded border-gray-300 dark:border-gray-600 text-black dark:text-white focus:ring-black dark:focus:ring-white">
<span class="text-gray-600 dark:text-gray-400">仅显示我的不及格课程</span>
</label>
<button onclick="refresh()"
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">
刷新
</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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden">
<p id="errorText" class="text-red-500"></p>
</div>
<div id="dataContainer" class="hidden list-item-enter" style="animation-delay: 150ms;">
<!-- ECharts 图表 -->
<div id="chartsRow" class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4 hidden">
<div class="glass rounded-2xl p-4">
<h3 class="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">开课学院分布</h3>
<div id="deptChart" style="height:300px;"></div>
</div>
<div class="glass rounded-2xl p-4">
<h3 class="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">重修状态分布</h3>
<div id="statusChart" style="height:300px;"></div>
</div>
</div>
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">序号</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">重修学年</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">重修学期</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">课程代码</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">课程名称</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">学分</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">开课学院</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">课程类别</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300" id="thOriginalCj" style="display:none;">原成绩</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">重修状态</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden">
<p class="text-gray-500 dark:text-gray-400 text-lg">暂无可重修课程</p>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
// ── 深色模式 ──
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; }
}
// 动态计算当前学年学期
function getCurrentSemester() {
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1; // 1-12
// 第一学期:9月-次年2月;第二学期:3月-8月
if (month >= 9) {
return { xnm: year, xqm: '3', label: year + '-' + (year + 1) + ' 第一学期' };
} else if (month >= 3) {
return { xnm: year - 1, xqm: '12', label: (year - 1) + '-' + year + ' 第二学期' };
} else {
return { xnm: year - 1, xqm: '3', label: (year - 1) + '-' + year + ' 第一学期' };
}
}
// 填充学年选项
function initYearSelects() {
const current = getCurrentSemester();
const xnmSelect = document.getElementById('xnmSelect');
const xqmSelect = document.getElementById('xqmSelect');
// 生成最近5个学年
for (let y = current.xnm; y >= current.xnm - 4; y--) {
const opt = document.createElement('option');
opt.value = y;
opt.textContent = y + '-' + (y + 1);
xnmSelect.appendChild(opt);
}
// 设置默认值
xnmSelect.value = current.xnm;
xqmSelect.value = current.xqm;
}
initYearSelects();
async function refresh() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
await initSession();
const xnm = document.getElementById('xnmSelect').value;
const xqm = document.getElementById('xqmSelect').value;
const showAll = document.getElementById('myFailedOnly').checked ? '0' : '1';
try {
const params = new URLSearchParams({ page_size: 500, show_all: showAll });
if (xnm) params.set('xnm', xnm);
if (xqm) params.set('xqm', xqm);
const res = await fetch('/api/jwxt/retake-courses?' + params);
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) {
document.getElementById('errorText').textContent = data.message || '查询失败';
document.getElementById('errorMessage').classList.remove('hidden');
return;
}
const items = data.items || [];
const isMatched = data.matched && !showAll;
// 显示/隐藏原成绩列
document.getElementById('thOriginalCj').style.display = isMatched ? '' : 'none';
if (!items.length) {
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('emptyState').classList.remove('hidden');
document.getElementById('tableBody').innerHTML = '';
document.getElementById('chartsRow').classList.add('hidden');
if (isMatched && (!data.failed_courses || !data.failed_courses.length)) {
document.getElementById('emptyState').querySelector('p').textContent = '没有不及格课程';
} else if (isMatched) {
document.getElementById('emptyState').querySelector('p').textContent = '当前学期没有你不及格课程对应的重修班,试试切换学年或取消"仅显示不及格"';
} else {
document.getElementById('emptyState').querySelector('p').textContent = '暂无可重修课程';
}
return;
}
document.getElementById('emptyState').classList.add('hidden');
renderTable(items, isMatched);
renderCharts(items);
document.getElementById('chartsRow').classList.remove('hidden');
setupDarkObserver();
document.getElementById('dataContainer').classList.remove('hidden');
} catch (e) {
document.getElementById('loadingIndicator').classList.add('hidden');
document.getElementById('errorText').textContent = '网络错误: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
function renderTable(items, showOriginalCj) {
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, idx) => {
const origCj = item._original_cj;
const origCjDisplay = origCj !== undefined
? '<span class="text-red-500 dark:text-red-400 font-semibold">' + origCj + '</span>'
: '--';
const origCjCell = showOriginalCj
? '<td class="py-3 px-4 text-center">' + origCjDisplay + '</td>'
: '';
return '<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors row-animate" style="animation-delay:' + (idx * 40) + 'ms;">' +
'<td class="py-3 px-4 text-gray-400 dark:text-gray-500">' + (idx + 1) + '</td>' +
'<td class="py-3 px-4 text-gray-500 dark:text-gray-400">' + (item.cxxnmc || '--') + '</td>' +
'<td class="py-3 px-4 text-center text-gray-500 dark:text-gray-400">' + (item.cxxqmc || '--') + '</td>' +
'<td class="py-3 px-4 text-gray-500 dark:text-gray-400 font-mono text-xs">' + (item.kch || '--') + '</td>' +
'<td class="py-3 px-4 font-medium">' + (item.kcmc || '--') + '</td>' +
'<td class="py-3 px-4 text-center">' + (item.xf || '--') + '</td>' +
'<td class="py-3 px-4 text-gray-500 dark:text-gray-400">' + (item.kkbmmc || '--') + '</td>' +
'<td class="py-3 px-4 text-gray-500 dark:text-gray-400">' + (item.kclbmc || '--') + '</td>' +
origCjCell +
'<td class="py-3 px-4 text-center text-gray-500 dark:text-gray-400">' + (item.cxzt || '--') + '</td>' +
'</tr>';
}).join('');
}
// ── ECharts 图表渲染 ──
let deptChartInst = null, statusChartInst = null;
let _lastRetakeItems = [];
function renderCharts(items) {
_lastRetakeItems = items;
renderDeptChart(items);
renderStatusChart(items);
}
function renderDeptChart(items) {
const dom = document.getElementById('deptChart');
if (!dom) return;
if (deptChartInst) deptChartInst.dispose();
const counts = {};
items.forEach(it => {
const k = it.kkbmmc || '未知';
counts[k] = (counts[k] || 0) + 1;
});
const keys = Object.keys(counts).sort((a, b) => counts[b] - counts[a]);
deptChartInst = echarts.init(dom);
deptChartInst.setOption({
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
grid: { left: 100, right: 30, top: 10, bottom: 20 },
xAxis: { type: 'value' },
yAxis: { type: 'category', data: keys, axisLabel: { fontSize: 11 } },
series: [{
type: 'bar', data: keys.map(k => counts[k]),
itemStyle: { color: isDarkMode() ? '#818cf8' : '#4f46e5' },
barMaxWidth: 24
}]
});
}
function renderStatusChart(items) {
const dom = document.getElementById('statusChart');
if (!dom) return;
if (statusChartInst) statusChartInst.dispose();
const counts = {};
items.forEach(it => {
const k = it.cxzt || '未知';
counts[k] = (counts[k] || 0) + 1;
});
const data = Object.entries(counts).map(([name, value]) => ({ name, value }));
statusChartInst = echarts.init(dom);
statusChartInst.setOption({
tooltip: { trigger: 'item', formatter: '{b}: {c} ({d}%)' },
legend: { bottom: 0, textStyle: { fontSize: 11, color: isDarkMode() ? '#9ca3af' : '#6b7280' } },
series: [{
type: 'pie', radius: ['45%', '70%'], center: ['50%', '45%'],
data: data,
label: { formatter: '{b}\n{d}%', fontSize: 11 },
itemStyle: { borderColor: isDarkMode() ? '#1f2937' : '#fff', borderWidth: 2 }
}]
});
}
// ── 深色模式观察 ──
let _darkObserverRetake = null;
function setupDarkObserver() {
if (_darkObserverRetake) _darkObserverRetake.disconnect();
_darkObserverRetake = new MutationObserver(() => {
if (deptChartInst) { deptChartInst.dispose(); deptChartInst = null; }
if (statusChartInst) { statusChartInst.dispose(); statusChartInst = null; }
if (_lastRetakeItems.length) renderCharts(_lastRetakeItems);
});
_darkObserverRetake.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
window.addEventListener('resize', () => {
if (deptChartInst) deptChartInst.resize();
if (statusChartInst) statusChartInst.resize();
});
refresh();
</script>
{% endblock %}
+73
View File
@@ -0,0 +1,73 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M22 10v6M2 10l10-5 10 5-10 5z"/><path d="M6 12v5c0 1.66 2.69 3 6 3s6-1.34 6-3v-5"/></svg>
重修报名
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">重修课程报名</p>
</div>
<button onclick="loadData()" 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"><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 id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">课程名称</th><th class="text-left py-3 px-4 font-semibold">课程代码</th><th class="text-left py-3 px-4 font-semibold">学分</th><th class="text-left py-3 px-4 font-semibold">报名状态</th><th class="text-left py-3 px-4 font-semibold">操作</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无重修报名信息</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/retake-registration');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || data.registered || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
const kcmc = item.kcmc || item.课程名称 || '--';
const kch = item.kch_id || item.kch || item.课程代码 || '--';
const xf = item.xf || item.学分 || '--';
const status = item.bmztmc || item.报名状态 || item.state || '--';
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors"><td class="py-3 px-4">${escHtml(kcmc)}</td><td class="py-3 px-4 text-gray-500 text-xs">${escHtml(kch)}</td><td class="py-3 px-4">${escHtml(xf)}</td><td class="py-3 px-4">${escHtml(status)}</td><td class="py-3 px-4">${status.includes('已报')||status.includes('已选')?'<span class="text-xs text-gray-400">已报名</span>':'<button onclick="alert(\'报名功能需在教务系统操作\')" class="text-xs text-blue-500 hover:text-blue-600">报名</button>'}</td></tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+577
View File
@@ -0,0 +1,577 @@
<!DOCTYPE html>
<html lang="zh-CN" class="scroll-smooth">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<title>支付成功 - {{ brand_name }}</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
dark: {
bg: '#0a0a0a',
card: '#171717',
border: '#262626'
}
}
}
}
}
</script>
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;800;900&family=Noto+Sans+SC:wght@300;400;500;700;900&display=swap"
rel="stylesheet">
<style>
* {
-webkit-tap-highlight-color: transparent;
}
body {
font-family: 'Inter', 'Noto Sans SC', sans-serif;
transition: background-color 0.3s ease, color 0.3s ease;
}
.glass {
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.9);
}
.dark .glass {
background: rgba(23, 23, 23, 0.85);
border: 1px solid rgba(38, 38, 38, 0.9);
}
.glass-dark {
background: rgba(17, 17, 17, 0.85);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.dark .glass-dark {
background: rgba(10, 10, 10, 0.9);
border: 1px solid rgba(38, 38, 38, 0.5);
}
.layer-4 {
box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.15);
}
.dark .layer-4 {
box-shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.7);
}
.bg-grid {
background-size: 40px 40px;
background-image: linear-gradient(to right, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
linear-gradient(to bottom, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
}
.dark .bg-grid {
background-image: linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
}
/* 成功动画 */
@keyframes successPop {
0% {
transform: scale(0);
opacity: 0;
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
opacity: 1;
}
}
.success-icon {
animation: successPop 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
/* 注册码卡片样式 */
.ticket-card {
background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
border: 2px solid #86efac;
transition: all 0.3s ease;
}
.dark .ticket-card {
background: linear-gradient(135deg, #14532d 0%, #166534 100%);
border-color: #22c55e;
}
.ticket-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px -5px rgba(34, 197, 94, 0.3);
}
.ticket-code {
font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
letter-spacing: 2px;
}
/* 复制按钮 */
.copy-btn {
transition: all 0.2s ease;
}
.copy-btn:hover {
transform: scale(1.05);
}
.copy-btn:active {
transform: scale(0.95);
}
/* Toast 通知 */
@media (min-width: 769px) {
.toast-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 9999;
pointer-events: none;
}
.toast {
background: #2c3e50;
color: white;
padding: 14px 22px;
border-radius: 8px;
margin-bottom: 10px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
transform: translateX(100%);
opacity: 0;
transition: all 0.3s ease;
pointer-events: all;
min-width: 250px;
max-width: 350px;
font-size: 14px;
}
.toast.show {
transform: translateX(0);
opacity: 1;
}
}
@media (max-width: 768px) {
.toast-container {
position: fixed;
bottom: max(20px, env(safe-area-inset-bottom));
left: 50%;
transform: translateX(-50%);
z-index: 9999;
pointer-events: none;
width: 90%;
max-width: 400px;
}
.toast {
background: #2c3e50;
color: white;
padding: 12px 20px;
border-radius: 24px;
margin-bottom: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
transform: translateY(100px);
opacity: 0;
transition: all 0.3s ease;
pointer-events: all;
width: 100%;
font-size: 14px;
text-align: center;
}
.toast.show {
transform: translateY(0);
opacity: 1;
}
}
.toast.success {
background: #27ae60;
}
.toast.error {
background: #e74c3c;
}
.dark .toast.success {
background: #4caf50;
}
.dark .toast.error {
background: #ff6b6b;
}
/* 步骤指示器 */
.step-item {
position: relative;
}
.step-item::after {
content: '';
position: absolute;
top: 50%;
right: -50%;
width: 100%;
height: 2px;
background: #e5e5e5;
transform: translateY(-50%);
z-index: 0;
}
.dark .step-item::after {
background: #404040;
}
.step-item:last-child::after {
display: none;
}
.step-number {
width: 32px;
height: 32px;
border-radius: 50%;
background: #111;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-weight: 600;
font-size: 14px;
position: relative;
z-index: 1;
}
.dark .step-number {
background: #fff;
color: #000;
}
/* 脉冲动画 */
@keyframes pulse-ring {
0% {
transform: scale(0.8);
opacity: 1;
}
100% {
transform: scale(1.5);
opacity: 0;
}
}
.pulse-ring {
position: absolute;
width: 100%;
height: 100%;
border-radius: 50%;
background: rgba(34, 197, 94, 0.4);
animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
/* 安全区域适配 */
.safe-area-inset-bottom {
padding-bottom: env(safe-area-inset-bottom);
}
</style>
</head>
<body class="bg-neutral-50 text-neutral-900 dark:bg-dark-bg dark:text-neutral-100 min-h-screen">
<!-- Toast 通知容器 -->
<div class="toast-container" id="toastContainer"></div>
<!-- 导航 -->
<nav class="fixed w-full z-50 glass border-b border-black/5 dark:border-white/10 transition-colors duration-300"
id="navbar">
<div class="max-w-6xl mx-auto px-4 md:px-6 h-16 flex justify-between items-center">
<a href="/buy" class="flex items-center gap-2 md:gap-3 group cursor-pointer">
<div
class="w-8 h-8 bg-black dark:bg-white rounded-lg flex items-center justify-center text-white dark:text-black font-bold text-sm group-hover:rotate-12 transition-transform shrink-0">
S</div>
<div class="flex items-center gap-1.5 md:gap-2 min-w-0">
<span class="font-bold tracking-tight text-sm md:text-base truncate">{{ brand_name }}</span>
</div>
</a>
<div class="flex items-center gap-2 md:gap-6">
<button onclick="toggleTheme()"
class="p-2 rounded-full hover:bg-neutral-200 dark:hover:bg-neutral-800 transition-colors shrink-0"
aria-label="切换主题">
<svg id="sun-icon" class="w-5 h-5 hidden dark:block text-neutral-300" fill="none"
stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z">
</path>
</svg>
<svg id="moon-icon" class="w-5 h-5 block dark:hidden text-neutral-600" fill="none"
stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z">
</path>
</svg>
</button>
</div>
</div>
</nav>
<!-- 主内容区 -->
<main class="pt-24 md:pt-32 pb-16 md:pb-24 px-4 md:px-6 bg-grid min-h-screen">
<div class="max-w-3xl mx-auto">
<!-- 成功提示 -->
<div class="text-center mb-8 md:mb-12">
<div class="relative inline-flex items-center justify-center mb-6">
<div class="pulse-ring"></div>
<div class="success-icon w-20 h-20 md:w-24 md:h-24 bg-green-500 rounded-full flex items-center justify-center layer-4">
<svg class="w-10 h-10 md:w-12 md:h-12 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7"></path>
</svg>
</div>
</div>
<h1 class="text-2xl md:text-4xl font-bold mb-2 text-neutral-900 dark:text-white">支付成功!</h1>
<p class="text-neutral-500 dark:text-neutral-400">您的注册码已生成,请妥善保管</p>
</div>
<!-- 注册码卡片 -->
<div class="glass rounded-2xl md:rounded-3xl p-6 md:p-8 layer-4 mb-8">
<div class="flex items-center gap-3 mb-6">
<div class="w-10 h-10 bg-green-100 dark:bg-green-900/30 rounded-xl flex items-center justify-center">
<svg class="w-5 h-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"></path>
</svg>
</div>
<div>
<h2 class="text-lg font-bold text-neutral-900 dark:text-white">您的注册码</h2>
<p class="text-sm text-neutral-500 dark:text-neutral-400">已自动复制到剪贴板</p>
</div>
</div>
<!-- 注册码列表 -->
<div id="ticketList" class="space-y-3 mb-6">
{% for code in ticket_codes %}
<div class="ticket-card rounded-xl p-4 md:p-5 flex items-center justify-between gap-4">
<div class="flex-1 min-w-0">
<div class="text-xs text-green-700 dark:text-green-300 mb-1 font-medium">注册码 {{ loop.index }}</div>
<div class="ticket-code text-lg md:text-xl font-bold text-green-800 dark:text-green-200 truncate" id="ticket-{{ loop.index }}">{{ code }}</div>
</div>
<button onclick="copyTicket('{{ code }}', this)" class="copy-btn flex-shrink-0 p-2.5 bg-white dark:bg-neutral-800 rounded-lg shadow-sm hover:shadow-md transition-all" title="复制">
<svg class="w-5 h-5 text-neutral-600 dark:text-neutral-400 copy-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"></path>
</svg>
<svg class="w-5 h-5 text-green-600 check-icon hidden" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
</button>
</div>
{% endfor %}
</div>
<!-- 复制全部按钮 -->
{% if ticket_codes|length > 1 %}
<button onclick="copyAllTickets()" class="w-full py-3 bg-green-500 hover:bg-green-600 text-white font-semibold rounded-xl transition-colors flex items-center justify-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"></path>
</svg>
复制全部注册码
</button>
{% endif %}
</div>
<!-- 使用步骤 -->
<div class="glass rounded-2xl md:rounded-3xl p-6 md:p-8 layer-4 mb-8">
<h2 class="text-lg font-bold text-neutral-900 dark:text-white mb-6 flex items-center gap-2">
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
使用步骤
</h2>
<div class="grid grid-cols-3 gap-4 mb-8">
<div class="step-item text-center">
<div class="step-number mx-auto mb-3">1</div>
<div class="text-sm font-medium text-neutral-700 dark:text-neutral-300">访问登录页</div>
<div class="text-xs text-neutral-400 mt-1">点击按钮前往</div>
</div>
<div class="step-item text-center">
<div class="step-number mx-auto mb-3">2</div>
<div class="text-sm font-medium text-neutral-700 dark:text-neutral-300">注册账号</div>
<div class="text-xs text-neutral-400 mt-1">使用注册码</div>
</div>
<div class="step-item text-center">
<div class="step-number mx-auto mb-3">3</div>
<div class="text-sm font-medium text-neutral-700 dark:text-neutral-300">开始使用</div>
<div class="text-xs text-neutral-400 mt-1">下载软件</div>
</div>
</div>
<!-- 登录地址 -->
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-4 mb-4">
<div class="flex items-center justify-between gap-4">
<div class="flex-1 min-w-0">
<div class="text-xs text-neutral-500 dark:text-neutral-400 mb-1">登录地址</div>
<div class="text-sm md:text-base font-medium text-neutral-900 dark:text-white truncate" id="loginUrl">{{ login_url or 'https://jwxt.bansonic.top' }}</div>
</div>
<a href="{{ login_url or 'https://jwxt.bansonic.top' }}" target="_blank" class="flex-shrink-0 px-4 py-2 bg-black dark:bg-white text-white dark:text-black text-sm font-semibold rounded-lg hover:shadow-lg transition-all flex items-center gap-2">
前往登录
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
</svg>
</a>
</div>
</div>
<!-- 重要提示 -->
<div class="bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-xl p-4">
<div class="flex items-start gap-3">
<svg class="w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>
</svg>
<div class="text-sm text-amber-800 dark:text-amber-200">
<p class="font-semibold mb-1">重要提示:</p>
<ul class="space-y-1 text-amber-700 dark:text-amber-300">
<li>• 每个注册码只能使用一次,请妥善保管</li>
<li>• 注册码已发送至您的邮箱,请注意查收</li>
<li>• 如遇问题,请联系客服获取帮助</li>
</ul>
</div>
</div>
</div>
</div>
<!-- 返回按钮 -->
<div class="text-center">
<a href="/buy" class="inline-flex items-center gap-2 px-6 py-3 bg-neutral-200 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-semibold rounded-xl hover:bg-neutral-300 dark:hover:bg-neutral-700 transition-colors">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path>
</svg>
返回购买页面
</a>
</div>
</div>
</main>
<script>
// 主题切换
function initTheme() {
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}
function toggleTheme() {
if (document.documentElement.classList.contains('dark')) {
document.documentElement.classList.remove('dark');
localStorage.theme = 'light';
} else {
document.documentElement.classList.add('dark');
localStorage.theme = 'dark';
}
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
if (!localStorage.theme) {
if (e.matches) document.documentElement.classList.add('dark');
else document.documentElement.classList.remove('dark');
}
});
initTheme();
// Toast 通知
function showToast(message, type = 'success', duration = 3000) {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
toast.innerHTML = `<span>${message}</span>`;
container.appendChild(toast);
setTimeout(() => toast.classList.add('show'), 10);
setTimeout(() => {
toast.classList.remove('show');
setTimeout(() => toast.remove(), 400);
}, duration);
}
// 复制单个注册码
async function copyTicket(code, btn) {
try {
await navigator.clipboard.writeText(code);
// 切换图标
const copyIcon = btn.querySelector('.copy-icon');
const checkIcon = btn.querySelector('.check-icon');
copyIcon.classList.add('hidden');
checkIcon.classList.remove('hidden');
showToast('注册码已复制到剪贴板', 'success');
// 2秒后恢复图标
setTimeout(() => {
copyIcon.classList.remove('hidden');
checkIcon.classList.add('hidden');
}, 2000);
} catch (err) {
// 降级方案
const textArea = document.createElement('textarea');
textArea.value = code;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
showToast('注册码已复制到剪贴板', 'success');
}
}
// 复制全部注册码
async function copyAllTickets() {
const ticketElements = document.querySelectorAll('[id^="ticket-"]');
const codes = Array.from(ticketElements).map(el => el.textContent.trim()).join('\n');
try {
await navigator.clipboard.writeText(codes);
showToast('全部注册码已复制到剪贴板', 'success');
} catch (err) {
const textArea = document.createElement('textarea');
textArea.value = codes;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
showToast('全部注册码已复制到剪贴板', 'success');
}
}
// 页面加载完成后自动复制第一个注册码
window.addEventListener('load', () => {
const firstTicket = document.querySelector('.ticket-code');
if (firstTicket) {
const code = firstTicket.textContent.trim();
// 尝试自动复制
navigator.clipboard.writeText(code).then(() => {
showToast('注册码已自动复制到剪贴板', 'success', 4000);
}).catch(() => {
// 静默失败,用户可手动复制
});
}
});
</script>
</body>
</html>
+75
View File
@@ -0,0 +1,75 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
更换指导教师申请
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">申请更换毕业论文(设计)指导教师</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">原指导教师</th><th class="text-left py-3 px-4 font-semibold">更换为</th><th class="text-left py-3 px-4 font-semibold">申请理由</th><th class="text-left py-3 px-4 font-semibold">审核状态</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无记录</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/supervisor-change');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.yjs||item.原指导教师||'--')}</td>
<td class="py-3 px-4">${escHtml(item.xjs||item.更换为||'--')}</td>
<td class="py-3 px-4 text-gray-500 text-xs">${escHtml(item.sqly||item.申请理由||'--')}</td>
<td class="py-3 px-4"><span class="px-2 py-0.5 rounded text-xs ${(item.shztmc||item.审核状态||'').includes('通过')?'bg-green-100':(item.shztmc||'').includes('待审')?'bg-yellow-100':'bg-gray-100'}">${escHtml(item.shztmc||item.审核状态||'--')}</span></td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function escAttr(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+728
View File
@@ -0,0 +1,728 @@
{% extends "base_tailwind.html" %}
{% block title %}抢课任务 - 教务抢课系统{% endblock %}
{% block extra_css %}
<style>
/* 任务详情模态框动画 */
#taskDetailModal {
transition: opacity 0.24s ease;
}
/* 增量刷新闪烁高亮 */
@keyframes cellFlash {
0% { background-color: rgba(34, 197, 94, 0.25); }
100% { background-color: transparent; }
}
.cell-flash {
animation: cellFlash 0.8s ease-out;
border-radius: 4px;
}
.dark .cell-flash {
animation-name: cellFlashDark;
}
@keyframes cellFlashDark {
0% { background-color: rgba(34, 197, 94, 0.3); }
100% { background-color: transparent; }
}
@media (prefers-reduced-motion: reduce) {
.cell-flash, .dark .cell-flash { animation: none !important; }
}
</style>
{% endblock %}
{% block content %}
<div>
<!-- 页面标题 -->
<div class="flex justify-between items-center mb-6 list-item-enter" style="animation-delay: 0ms;">
<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"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>
抢课任务管理
</h2>
<a href="{{ url_for('main.courses') }}"
class="px-6 py-2 bg-black dark:bg-white text-white dark:text-black rounded-full font-medium hover:opacity-80 transition-opacity flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>
新建任务
</a>
</div>
<!-- 管理员查看其他用户任务的提示 -->
<div id="viewingUserBanner" class="hidden mb-4">
<div class="glass rounded-2xl px-4 py-3 flex items-center gap-3 text-sm">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="text-blue-500 flex-shrink-0"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>正在查看 <strong id="viewingUserName">用户</strong> 的任务列表</span>
<a href="/tasks" class="ml-auto px-3 py-1 rounded-full bg-black dark:bg-white text-white dark:text-black text-xs font-medium hover:opacity-80 transition-opacity">返回我的任务</a>
</div>
</div>
<!-- 筛选栏 -->
<div class="glass rounded-2xl p-4 sm:p-6 mb-4 sm:mb-6 list-item-enter" style="animation-delay: 50ms;">
<div class="flex flex-col sm:flex-row gap-3 sm:gap-4 items-stretch sm:items-center">
<div class="flex-1">
<div class="relative">
<select id="statusFilter" onchange="loadTasks()"
class="w-full sm:w-64 px-4 py-2.5 rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-black focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white appearance-none text-sm">
<option value="">📋 全部状态</option>
<option value="pending">⏳ 待执行</option>
<option value="running">🔄 执行中</option>
<option value="success">✅ 成功</option>
<option value="failed">❌ 失败</option>
<option value="cancelled">🚫 已取消</option>
</select>
<span class="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none">
<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"><path d="m6 9 6 6 6-6"/></svg>
</span>
</div>
</div>
<div class="flex gap-2 items-center">
<span id="autoRefreshBadge" class="hidden text-xs text-gray-400 flex items-center gap-1">
<span class="w-1.5 h-1.5 rounded-full bg-green-500 inline-block"></span>
自动刷新中
</span>
<button onclick="loadTasks(1)"
class="btn-outline text-sm px-4 py-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"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 21h5v-5"/></svg>
刷新
</button>
</div>
</div>
</div>
<!-- 任务列表 -->
<div class="glass rounded-2xl p-4 sm:p-6 list-item-enter" style="animation-delay: 100ms;">
<div id="loadingIndicator" class="text-center py-12">
<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="emptyState" class="text-center py-12" style="display: none;">
<div class="w-16 h-16 mx-auto mb-4 rounded-2xl bg-gray-100 dark:bg-gray-800 flex items-center justify-center">
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="text-gray-400"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>
</div>
<p class="text-gray-500 dark:text-gray-400 mb-1 font-medium">暂无任务</p>
<p class="text-sm text-gray-400 dark:text-gray-500 mb-5">去课程列表创建你的第一个抢课任务</p>
<a href="{{ url_for('main.courses') }}"
class="inline-flex items-center gap-2 px-6 py-2.5 bg-black dark:bg-white text-white dark:text-black rounded-full font-medium hover:opacity-80 transition-all hover:shadow-lg">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/></svg>
创建任务
</a>
</div>
<div id="tasksTableContainer" class="max-w-5xl mx-auto" style="display: none;">
<div class="-mx-2 sm:mx-0">
<table class="card-on-mobile data-table w-full">
<thead>
<tr>
<th>ID</th>
<th>课程名称</th>
<th>教师</th>
<th>类型</th>
<th>状态</th>
<th>重试</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="tasksTableBody">
</tbody>
</table>
</div>
</div>
<!-- 分页 -->
<nav id="pagination" class="mt-4 sm:mt-6" style="display: none;">
<div class="flex justify-center items-center gap-1.5 sm:gap-2">
</div>
</nav>
</div>
</div>
<!-- 任务详情模态框 -->
<div id="taskDetailModal" class="fixed inset-0 z-50 flex items-center justify-center p-4 opacity-0 pointer-events-none transition-opacity duration-300">
<div class="absolute inset-0 bg-black/50 backdrop-blur-sm" onclick="closeTaskDetailModal()"></div>
<div class="relative w-full max-w-3xl p-4">
<div class="glass rounded-2xl p-6 max-h-[90vh] overflow-y-auto" onclick="event.stopPropagation()">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold flex items-center gap-2">
<div class="w-8 h-8 rounded-lg bg-gray-100 dark:bg-gray-800 flex items-center justify-center">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>
</div>
任务详情
</h3>
<button onclick="closeTaskDetailModal()" class="p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg transition-colors">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
</button>
</div>
<div id="taskDetailLoading" class="text-center py-8">
<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>
</div>
<div id="taskDetailContent" style="display: none;">
<div class="overflow-x-auto mb-6">
<table class="w-full">
<tbody class="divide-y divide-gray-200 dark:divide-gray-700">
<tr><td class="py-3 text-gray-500 dark:text-gray-400 w-32">课程名称</td><td id="detailCourseName" class="py-3 font-medium"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">教学班</td><td id="detailClassInfo" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">教师</td><td id="detailTeacher" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">学分</td><td id="detailCredit" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">任务类型</td><td id="detailType" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">状态</td><td id="detailStatus" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">重试次数</td><td id="detailRetries" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">创建时间</td><td id="detailCreated" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">开始时间</td><td id="detailStarted" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">完成时间</td><td id="detailCompleted" class="py-3"></td></tr>
<tr><td class="py-3 text-gray-500 dark:text-gray-400">结果消息</td><td id="detailMessage" class="py-3"></td></tr>
</tbody>
</table>
</div>
<!-- 自定义规则展示 -->
<div id="detailRulesContainer" class="mb-6 hidden">
<h6 class="font-semibold mb-3 flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
自定义规则
</h6>
<div id="detailRulesBody" class="space-y-2"></div>
</div>
<h6 class="font-semibold mb-3 flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
实时日志
</h6>
<div id="taskLogs" class="scrollbar-thin space-y-1.5 max-h-[300px] overflow-y-auto font-mono text-sm p-3 sm:p-4 rounded-xl bg-white/50 dark:bg-black/30 border border-gray-200 dark:border-gray-700">
<!-- 日志内容 -->
</div>
</div>
<div class="flex gap-3 justify-end mt-6">
<button onclick="closeTaskDetailModal()"
class="px-6 py-2 border border-gray-300 dark:border-gray-600 rounded-full hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors">
关闭
</button>
<button id="cancelTaskBtn" onclick="cancelCurrentTask()" style="display: none;"
class="px-6 py-2 bg-red-600 text-white rounded-full font-medium hover:bg-red-700 transition-colors flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
取消任务
</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
let currentPage = 1;
let currentTaskId = null;
let logRefreshInterval = null;
let lastLogId = 0;
// 管理员查看指定用户的任务
const viewingUserId = new URLSearchParams(window.location.search).get('user_id') || '';
function openTaskDetailModal() {
const modal = document.getElementById('taskDetailModal');
modal.classList.remove('opacity-0', 'pointer-events-none');
modal.classList.add('opacity-100', 'pointer-events-auto');
document.documentElement.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
}
function closeTaskDetailModal() {
const modal = document.getElementById('taskDetailModal');
modal.classList.add('opacity-0', 'pointer-events-none');
modal.classList.remove('opacity-100', 'pointer-events-auto');
document.documentElement.style.overflow = '';
document.body.style.overflow = '';
if (logRefreshInterval) {
clearInterval(logRefreshInterval);
logRefreshInterval = null;
}
}
// 加载任务列表
async function loadTasks(page = 1) {
currentPage = page;
const status = document.getElementById('statusFilter').value;
document.getElementById('loadingIndicator').style.display = 'block';
document.getElementById('emptyState').style.display = 'none';
document.getElementById('tasksTableContainer').style.display = 'none';
document.getElementById('pagination').style.display = 'none';
try {
let url = `/api/tasks/list?page=${page}&per_page=20`;
if (status) url += `&status=${status}`;
const data = await apiRequest(url);
document.getElementById('loadingIndicator').style.display = 'none';
if (!data.success || !data.tasks || data.tasks.length === 0) {
document.getElementById('emptyState').style.display = 'block';
if (viewingUserId) {
// 管理员查看他人任务:即使空也显示表格区域,方便看横幅
document.getElementById('tasksTableContainer').style.display = 'block';
}
return;
}
renderTasksTable(data.tasks);
renderPagination(data.total, data.pages, page);
document.getElementById('tasksTableContainer').style.display = 'block';
document.getElementById('pagination').style.display = 'block';
// 显示自动刷新 badge
const badge = document.getElementById('autoRefreshBadge');
if (badge) badge.classList.remove('hidden');
// 管理员查看其他用户:显示横幅
if (viewingUserId) {
document.getElementById('viewingUserBanner')?.classList.remove('hidden');
const nameEl = document.getElementById('viewingUserName');
if (data.tasks && data.tasks.length > 0 && data.tasks[0].username) {
nameEl.textContent = data.tasks[0].username;
} else {
nameEl.textContent = 'ID ' + viewingUserId;
}
}
} catch (error) {
document.getElementById('loadingIndicator').style.display = 'none';
if (!silent) showToast('加载失败,请稍后重试', 'error');
}
}
// 渲染任务表格
function renderTasksTable(tasks) {
const tbody = document.getElementById('tasksTableBody');
tbody.innerHTML = tasks.map((task, index) => {
const typeBadge = task.task_type === 'immediate'
? '<span class="status-badge status-info"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg> 立即</span>'
: '<span class="status-badge status-warning"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg> 定时</span>';
const delay = Math.min(index * 30, 300);
return `
<tr data-task-id="${task.id}" class="list-item-enter" style="animation-delay: ${delay}ms;">
<td data-label="ID"><span class="font-mono text-xs sm:text-sm text-gray-500 dark:text-gray-400">#${task.id}</span></td>
<td data-label="课程名称"><strong class="text-sm">${escapeHtml(task.course_name)}</strong></td>
<td data-label="教师"><span class="text-sm">${escapeHtml(task.teacher_name || '-')}</span></td>
<td data-label="类型">${typeBadge}</td>
<td data-label="状态" class="task-status-cell">${getStatusBadge(task.status)}</td>
<td data-label="重试" class="task-retry-cell"><span class="text-xs sm:text-sm">${task.retry_count}/${task.max_retries === 0 ? '∞' : task.max_retries}</span></td>
<td data-label="创建时间"><span class="text-xs sm:text-sm text-gray-500">${formatTime(task.created_at)}</span></td>
<td data-label="操作" class="task-actions-cell">
<div class="flex gap-1.5 sm:gap-2">
<button onclick="viewTaskDetail(${task.id})"
class="p-1.5 sm:p-2 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors" title="查看详情">
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
</button>
${(task.status === 'pending' || task.status === 'running') ? `
<button onclick="cancelTask(${task.id})"
class="p-1.5 sm:p-2 border border-red-300 dark:border-red-700 text-red-600 dark:text-red-400 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors" title="取消任务">
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
</button>
` : ''}
</div>
</td>
</tr>
`;
}).join('');
}
// ── 增量刷新(只更新变化的单元格) ──
let _refreshCount = 0;
async function incrementalRefresh() {
// 仅当表格可见时才刷新
const container = document.getElementById('tasksTableContainer');
if (!container || container.style.display === 'none') return;
const status = document.getElementById('statusFilter').value;
try {
const data = await apiRequest(getTaskListUrl(currentPage) + (status ? '&status=' + status : ''));
if (!data.success || !data.tasks) return;
const tbody = document.getElementById('tasksTableBody');
const existingRows = tbody.querySelectorAll('tr[data-task-id]');
const existingMap = {};
existingRows.forEach(tr => { existingMap[tr.getAttribute('data-task-id')] = tr; });
let changed = false;
data.tasks.forEach((task, idx) => {
const tid = String(task.id);
const oldRow = existingMap[tid];
if (oldRow) {
// 行存在 → 增量更新单元格
if (updateCellIfChanged(oldRow, '.task-status-cell', getStatusBadge(task.status))) changed = true;
if (updateCellIfChanged(oldRow, '.task-retry-cell',
'<span class="text-xs sm:text-sm">' + task.retry_count + '/' + (task.max_retries === 0 ? '∞' : task.max_retries) + '</span>')) changed = true;
// 操作列:如果状态从 pending/running 变了,需隐藏取消按钮
const actionsCell = oldRow.querySelector('.task-actions-cell');
const newActionsHtml = buildActionsHtml(task);
if (actionsCell && actionsCell.innerHTML.trim() !== newActionsHtml.trim()) {
actionsCell.innerHTML = newActionsHtml;
changed = true;
}
} else {
// 新任务出现在本页 → 插入
changed = true;
}
});
if (changed) {
_refreshCount++;
const badge = document.getElementById('autoRefreshBadge');
if (badge) {
badge.classList.remove('hidden');
badge.innerHTML = '<span class="w-1.5 h-1.5 rounded-full bg-green-500 inline-block"></span> 已更新';
clearTimeout(badge._hideTimer);
badge._hideTimer = setTimeout(() => {
badge.innerHTML = '<span class="w-1.5 h-1.5 rounded-full bg-green-500 inline-block"></span> 自动刷新中';
}, 2000);
}
}
} catch (e) {
// 静默失败
}
}
// ── 辅助:仅当值不同时才更新 DOM,并附带闪烁反馈 ──
function updateCellIfChanged(row, selector, newHtml) {
const cell = row.querySelector(selector);
if (!cell) return false;
const old = cell.innerHTML.trim();
if (old === newHtml.trim()) return false;
cell.innerHTML = newHtml;
// 闪烁高亮
cell.classList.remove('cell-flash');
void cell.offsetWidth; // 强制 reflow
cell.classList.add('cell-flash');
setTimeout(() => cell.classList.remove('cell-flash'), 800);
return true;
}
// ── 辅助:构建操作列 HTML ──
function buildActionsHtml(task) {
const viewBtn = '<button onclick="viewTaskDetail(' + task.id + ')" class="p-1.5 sm:p-2 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors" title="查看详情"><svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg></button>';
const cancelBtn = (task.status === 'pending' || task.status === 'running')
? '<button onclick="cancelTask(' + task.id + ')" class="p-1.5 sm:p-2 border border-red-300 dark:border-red-700 text-red-600 dark:text-red-400 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors" title="取消任务"><svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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></button>'
: '';
return '<div class="flex gap-1.5 sm:gap-2">' + viewBtn + cancelBtn + '</div>';
}
function getTaskListUrl(page) {
let url = `/api/tasks/list?page=${page}&per_page=20`;
if (viewingUserId) url += `&user_id=${viewingUserId}`;
return url;
}
// 加载任务列表(全量,仅手动调用时触发 loading) ──
async function loadTasks(page = 1, silent = false) {
currentPage = page;
const status = document.getElementById('statusFilter').value;
if (!silent) {
document.getElementById('loadingIndicator').style.display = 'block';
document.getElementById('emptyState').style.display = 'none';
document.getElementById('tasksTableContainer').style.display = 'none';
document.getElementById('pagination').style.display = 'none';
}
try {
let url = getTaskListUrl(page);
if (status) url += `&status=${status}`;
const data = await apiRequest(url);
if (!silent) {
document.getElementById('loadingIndicator').style.display = 'none';
}
if (!data.success || !data.tasks || data.tasks.length === 0) {
document.getElementById('emptyState').style.display = 'block';
document.getElementById('tasksTableContainer').style.display = 'none';
return;
}
renderTasksTable(data.tasks);
renderPagination(data.total, data.pages, page);
document.getElementById('tasksTableContainer').style.display = 'block';
document.getElementById('pagination').style.display = 'block';
// 显示自动刷新 badge
const badge = document.getElementById('autoRefreshBadge');
if (badge) badge.classList.remove('hidden');
} catch (error) {
if (!silent) {
document.getElementById('loadingIndicator').style.display = 'none';
showToast('加载失败,请稍后重试', 'error');
}
}
}
function renderPagination(total, pages, current) {
const nav = document.getElementById('pagination').querySelector('div');
let html = '';
html += `
<button onclick="loadTasks(${current - 1})" ${current === 1 ? 'disabled' : ''}
class="px-2.5 sm:px-3 py-1.5 text-xs sm:text-sm rounded-lg border border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m15 18-6-6 6-6"/></svg>
<span class="hidden sm:inline">上一页</span>
</button>
`;
for (let i = 1; i <= pages; i++) {
if (i === 1 || i === pages || (i >= current - 2 && i <= current + 2)) {
html += `
<button onclick="loadTasks(${i})"
class="min-w-[32px] sm:min-w-[36px] h-8 sm:h-9 rounded-lg text-xs sm:text-sm font-medium transition-all ${i === current ? 'bg-black dark:bg-white text-white dark:text-black shadow-sm' : 'border border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800'}">
${i}
</button>
`;
} else if (i === current - 3 || i === current + 3) {
html += `<span class="px-1 sm:px-2 text-gray-400 text-xs sm:text-sm">…</span>`;
}
}
html += `
<button onclick="loadTasks(${current + 1})" ${current === pages ? 'disabled' : ''}
class="px-2.5 sm:px-3 py-1.5 text-xs sm:text-sm rounded-lg border border-gray-300 dark:border-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1">
<span class="hidden sm:inline">下一页</span>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>
</button>
`;
nav.innerHTML = html;
}
// 查看任务详情
async function viewTaskDetail(taskId) {
currentTaskId = taskId;
lastLogId = 0;
document.getElementById('taskDetailLoading').style.display = 'block';
document.getElementById('taskDetailContent').style.display = 'none';
document.getElementById('cancelTaskBtn').style.display = 'none';
openTaskDetailModal();
// 清除之前的定时器
if (logRefreshInterval) {
clearInterval(logRefreshInterval);
}
try {
const data = await apiRequest(`/api/tasks/${taskId}`);
document.getElementById('taskDetailLoading').style.display = 'none';
document.getElementById('taskDetailContent').style.display = 'block';
if (data.success) {
const task = data.task;
document.getElementById('detailCourseName').textContent = task.course_name;
document.getElementById('detailClassInfo').textContent = task.class_info || '-';
document.getElementById('detailTeacher').textContent = task.teacher_name || '-';
document.getElementById('detailCredit').textContent = task.credit || '-';
document.getElementById('detailType').innerHTML = task.task_type === 'immediate'
? '<span class="status-badge status-info"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg> 立即抢课</span>'
: '<span class="status-badge status-warning"><svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg> 定时抢课</span> <span class="text-xs text-gray-400">(' + formatTime(task.scheduled_time) + ')</span>';
document.getElementById('detailStatus').innerHTML = getStatusBadge(task.status);
document.getElementById('detailRetries').textContent = `${task.retry_count}/${task.max_retries}`;
document.getElementById('detailCreated').textContent = formatTime(task.created_at);
document.getElementById('detailStarted').textContent = formatTime(task.started_at);
document.getElementById('detailCompleted').textContent = formatTime(task.completed_at);
document.getElementById('detailMessage').textContent = task.result_message || '-';
// 显示自定义规则
renderTaskRules(task.rules);
// 显示取消按钮
if (task.status === 'pending' || task.status === 'running') {
document.getElementById('cancelTaskBtn').style.display = 'inline-flex';
}
// 加载日志
loadTaskLogs(taskId);
// 如果任务正在运行,定时刷新日志
if (task.status === 'running') {
logRefreshInterval = setInterval(() => loadTaskLogs(taskId, true), 2000);
}
}
} catch (error) {
document.getElementById('taskDetailLoading').style.display = 'none';
showToast('加载详情失败', 'error');
}
}
// 加载任务日志
async function loadTaskLogs(taskId, incremental = false) {
try {
let url = `/api/logs/list?task_id=${taskId}&per_page=100`;
if (incremental && lastLogId > 0) {
url = `/api/logs/recent?task_id=${taskId}&after_id=${lastLogId}`;
}
const data = await apiRequest(url);
if (data.success && data.logs) {
const logContainer = document.getElementById('taskLogs');
if (!incremental) {
logContainer.innerHTML = '';
}
const levelColors = {
'info': 'text-blue-600 dark:text-blue-400',
'success': 'text-green-600 dark:text-green-400',
'warning': 'text-yellow-600 dark:text-yellow-400',
'error': 'text-red-600 dark:text-red-400'
};
data.logs.forEach(log => {
if (log.id > lastLogId) {
lastLogId = log.id;
}
const logClass = levelColors[log.level] || 'text-gray-600 dark:text-gray-400';
const logHtml = `
<div class="p-2 rounded-lg bg-white/50 dark:bg-black/30">
<span class="text-gray-400 text-xs">${log.created_at ? formatTime(log.created_at).split(' ').slice(1).join(' ') : ''}</span>
<span class="${logClass} font-bold text-xs">[${log.level.toUpperCase()}]</span>
${escapeHtml(log.message)}
</div>
`;
logContainer.insertAdjacentHTML('beforeend', logHtml);
});
// 滚动到底部
logContainer.scrollTop = logContainer.scrollHeight;
}
} catch (error) {
console.error('加载日志失败:', error);
}
}
// 取消任务
async function cancelTask(taskId) {
if (!confirm('确定要取消这个任务吗?')) return;
try {
const data = await apiRequest(`/api/tasks/${taskId}/cancel`, {
method: 'POST'
});
if (data.success) {
showToast('任务已取消', 'success');
loadTasks(currentPage);
} else {
showToast(data.message || '取消失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 取消当前查看的任务
async function cancelCurrentTask() {
if (currentTaskId) {
await cancelTask(currentTaskId);
closeTaskDetailModal();
}
}
// HTML转义
function escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// ── SVG 图标(用于状态徽章) ──
const ICONS = {
pending: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><path d="M12 2v6l4 4-4 4v6"/><path d="M4 2h16"/><path d="M4 22h16"/></svg>',
running: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5 animate-spin"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',
success: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>',
failed: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>',
cancelled: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><circle cx="12" cy="12" r="10"/><path d="m4.9 4.9 14.2 14.2"/></svg>',
expired: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>',
unknown: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="inline-block -mt-0.5 mr-0.5"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/></svg>',
};
// ── 渲染自定义规则 ──
function renderTaskRules(rules) {
const container = document.getElementById('detailRulesContainer');
const body = document.getElementById('detailRulesBody');
if (!container || !body) return;
if (!rules || !rules.on_has_vacancy || rules.on_has_vacancy.length === 0) {
container.classList.add('hidden');
return;
}
container.classList.remove('hidden');
body.innerHTML = rules.on_has_vacancy.map((rule, i) => {
if (rule.action === 'drop_course') {
return `
<div class="flex items-center gap-2 p-2.5 rounded-xl bg-emerald-50/80 dark:bg-emerald-950/20 border border-emerald-200 dark:border-emerald-800">
<span class="flex-shrink-0 w-6 h-6 rounded-md bg-emerald-100 dark:bg-emerald-900/40 text-emerald-700 dark:text-emerald-300 flex items-center justify-center text-xs font-bold">${i + 1}</span>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="flex-shrink-0 text-emerald-600 dark:text-emerald-400"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/></svg>
<span class="text-sm font-medium text-emerald-800 dark:text-emerald-200">退课</span>
<span class="text-sm text-gray-600 dark:text-gray-400">${escapeHtml(rule.course_name || '未知课程')}</span>
<span class="text-xs text-gray-400 dark:text-gray-500 ml-auto">抢课前执行</span>
</div>
`;
}
if (rule.action === 'wait') {
return `
<div class="flex items-center gap-2 p-2.5 rounded-xl bg-blue-50/80 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800">
<span class="flex-shrink-0 w-6 h-6 rounded-md bg-blue-100 dark:bg-blue-900/40 text-blue-700 dark:text-blue-300 flex items-center justify-center text-xs font-bold">${i + 1}</span>
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="flex-shrink-0 text-blue-600 dark:text-blue-400"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
<span class="text-sm font-medium text-blue-800 dark:text-blue-200">等待</span>
<span class="text-sm text-gray-600 dark:text-gray-400">${rule.seconds || 2} 秒</span>
</div>
`;
}
return '';
}).join('') + `
<div class="flex items-center gap-2 p-2.5 rounded-xl bg-gray-100/80 dark:bg-gray-800/60 border border-dashed border-gray-300 dark:border-gray-700">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="flex-shrink-0 text-gray-500"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>
<span class="text-sm text-gray-500 dark:text-gray-400">→ 然后自动抢课</span>
</div>
`;
}
// 状态徽章
function getStatusBadge(status) {
const statusMap = {
'pending': { class: 'status-pending', icon: ICONS.pending, text: '待执行' },
'running': { class: 'status-running', icon: ICONS.running, text: '执行中' },
'success': { class: 'status-success', icon: ICONS.success, text: '成功' },
'failed': { class: 'status-failed', icon: ICONS.failed, text: '失败' },
'cancelled': { class: 'status-cancelled', icon: ICONS.cancelled, text: '已取消' },
'expired': { class: 'status-cancelled', icon: ICONS.expired, text: '已过期' }
};
const s = statusMap[status] || { class: 'status-pending', icon: ICONS.unknown, text: status };
return '<span class="status-badge ' + s.class + '">' + s.icon + s.text + '</span>';
}
// 页面加载
document.addEventListener('DOMContentLoaded', function() {
// 将弹窗移到 body 直接子级,确保 fixed 定位基于视口
const taskDetailModal = document.getElementById('taskDetailModal');
if (taskDetailModal) document.body.appendChild(taskDetailModal);
loadTasks();
// 每5秒增量刷新(只更新变化的单元格,不重绘整表)
setInterval(() => incrementalRefresh(), 5000);
});
</script>
{% endblock %}
+816
View File
@@ -0,0 +1,816 @@
{% 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; }
/* 课程格子入场动画 */
@keyframes cellFadeIn {
from { opacity: 0; transform: translateY(6px) scale(0.96); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
.course-cell {
animation: cellFadeIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
/* 弹窗 */
#teacherModal {
opacity: 0;
pointer-events: none;
transition: opacity 0.22s ease;
}
#teacherModal.modal-open {
opacity: 1;
pointer-events: auto;
}
#teacherModal .modal-backdrop {
opacity: 0;
transition: opacity 0.22s ease;
}
#teacherModal.modal-open .modal-backdrop {
opacity: 1;
}
#teacherModal .modal-panel {
opacity: 0;
transform: scale(0.94) translateY(12px);
transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}
#teacherModal.modal-open .modal-panel {
opacity: 1;
transform: scale(1) translateY(0);
}
/* 行悬停提示 */
.clickable-row { cursor: pointer; }
</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">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
<circle cx="9" cy="7" r="4"/>
<path d="M23 21v-2a4 4 0 0 0-3-3.87"/>
<path d="M16 3.13a4 4 0 0 1 0 7.75"/>
</svg>
教师课表
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">查询教师授课安排,点击教师行可预览课程表</p>
</div>
<div class="flex gap-2">
<button onclick="refresh()"
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="14" height="14" 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 class="glass rounded-2xl p-4 mb-4 list-item-enter max-w-5xl mx-auto" style="animation-delay: 50ms;">
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3">
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">学年</label>
<select id="fXnm" onchange="refresh()" class="w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="2026" selected>2026-2027</option>
<option value="2025">2025-2026</option>
<option value="2024">2024-2025</option>
<option value="2023">2023-2024</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">学期</label>
<select id="fXqm" onchange="refresh()" class="w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="3" selected>第1学期</option>
<option value="12">第2学期</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">校区</label>
<select id="fXqh" onchange="refresh()" class="w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="1">长清校区</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">职称</label>
<select id="fZcm" onchange="refresh()" class="w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="01">教授</option>
<option value="02">副教授</option>
<option value="03">讲师</option>
<option value="04">助教</option>
<option value="05">未评级</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">部门/学院</label>
<select id="fJg" onchange="refresh()" class="w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="301">劳动关系学院</option>
<option value="302">工商学院</option>
<option value="303">会计学院</option>
<option value="304">艺术学院</option>
<option value="305">信息工程学院</option>
<option value="306">经贸学院</option>
<option value="307">智能工程学院</option>
<option value="308">人文学院</option>
<option value="311">马克思主义学院</option>
<option value="312">体育教学部</option>
<option value="313">国际交流学院</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">开课学院</label>
<select id="fKkbm" onchange="refresh()" class="w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="301">劳动关系学院</option>
<option value="302">工商学院</option>
<option value="303">会计学院</option>
<option value="304">艺术学院</option>
<option value="305">信息工程学院</option>
<option value="306">经贸学院</option>
<option value="307">智能工程学院</option>
<option value="308">人文学院</option>
<option value="311">马克思主义学院</option>
<option value="312">体育教学部</option>
<option value="313">国际交流学院</option>
</select>
</div>
<div>
<label class="block text-xs text-gray-500 dark:text-gray-400 mb-1">教师工号/姓名</label>
<input id="fJgh" type="text" placeholder="可模糊搜索" onkeydown="if(event.key==='Enter')refresh()"
class="w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
</div>
</div>
<div class="flex gap-3 mt-3 items-center flex-wrap">
<label class="flex items-center gap-1.5 text-sm text-gray-600 dark:text-gray-400 cursor-pointer">
<input type="checkbox" id="fZxszjjs" onchange="refresh()" class="w-4 h-4 rounded accent-black dark:accent-white">
只显示主讲教师
</label>
<label class="flex items-center gap-1.5 text-sm text-gray-600 dark:text-gray-400 cursor-pointer">
<input type="checkbox" id="fSfwp" onchange="refresh()" class="w-4 h-4 rounded accent-black dark:accent-white">
仅显示外聘教师
</label>
</div>
</div>
<!-- 图表区域 -->
<div id="chartsRow" class="hidden grid grid-cols-1 md:grid-cols-2 gap-4 mb-4 list-item-enter" style="animation-delay: 120ms;">
<div class="glass rounded-2xl p-4">
<h4 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">职称分布</h4>
<div id="titleChart" style="height: 260px;"></div>
</div>
<div class="glass rounded-2xl p-4">
<h4 class="text-sm font-semibold text-gray-700 dark:text-gray-300 mb-3">学院分布</h4>
<div id="deptChart" style="height: 260px;"></div>
</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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden">
<p id="errorText" class="text-red-500"></p>
</div>
<!-- 结果 -->
<div id="dataContainer" class="hidden list-item-enter" style="animation-delay: 150ms;">
<div class="flex justify-between items-center mb-3 px-1">
<p class="text-sm text-gray-500 dark:text-gray-400">共 <span id="totalCount" class="font-bold text-black dark:text-white">0</span> 条记录</p>
<p class="text-xs text-gray-400 dark:text-gray-500">点击行可预览课程表</p>
</div>
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">#</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">工号</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">姓名</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">职称</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">所属学院</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">校区</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">电话</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden">
<p class="text-gray-500 dark:text-gray-400 text-lg">暂无符合条件的教师</p>
</div>
</div>
</div>
<!-- 教师课表明细弹窗 -->
<div id="teacherModal" class="fixed inset-0 z-50 flex items-center justify-center p-4" aria-labelledby="modal-title" role="dialog" aria-modal="true">
<!-- 背景遮罩 -->
<div class="modal-backdrop fixed inset-0 bg-black/50 backdrop-blur-sm" onclick="closeTeacherModal()"></div>
<!-- 弹窗面板 -->
<div class="modal-panel relative glass rounded-2xl shadow-xl w-full max-w-2xl max-h-[85vh] flex flex-col overflow-hidden">
<!-- 顶部标题区 -->
<div class="flex items-center gap-3 p-5 pb-4 flex-shrink-0 border-b border-gray-200 dark:border-gray-700">
<div id="modalTeacherIcon" class="w-10 h-10 rounded-xl bg-blue-900/50 text-blue-100 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="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
<circle cx="12" cy="7" r="4"></circle>
</svg>
</div>
<div class="min-w-0 flex-1">
<h3 id="modalTeacherName" class="text-lg font-bold text-gray-900 dark:text-white leading-tight truncate">--</h3>
<p id="modalTeacherInfo" class="text-sm text-gray-500 dark:text-gray-400 truncate">--</p>
</div>
<div class="flex items-center gap-2 flex-shrink-0">
<span id="modalCourseCount" class="px-2 py-1 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-300">0门课</span>
<button onclick="closeTeacherModal()" class="p-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-full transition-colors">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<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 id="modalLoading" class="flex-1 flex items-center justify-center py-12">
<div class="w-8 h-8 border-2 border-black dark:border-white border-t-transparent rounded-full animate-spin"></div>
</div>
<!-- 错误提示 -->
<div id="modalError" class="flex-1 flex items-center justify-center py-12 hidden">
<p id="modalErrorText" class="text-red-500 text-sm"></p>
</div>
<!-- 课表内容区 -->
<div id="modalContent" class="flex-1 overflow-y-auto p-4 hidden">
<!-- 视图切换 + 周次选择 -->
<div class="flex items-center justify-between gap-2 mb-3">
<div class="flex items-center gap-2">
<span class="text-xs text-gray-500 dark:text-gray-400">周次:</span>
<select id="modalWeekSelect" onchange="renderTeacherScheduleInModal()" class="px-2 py-1 rounded border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-xs">
</select>
</div>
<div class="flex items-center gap-1 p-0.5 rounded-lg bg-gray-100 dark:bg-gray-800">
<button id="viewGridBtn" onclick="switchView('grid')" class="px-3 py-1 rounded-md text-xs font-medium bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm transition-all">网格</button>
<button id="viewListBtn" onclick="switchView('list')" class="px-3 py-1 rounded-md text-xs font-medium text-gray-500 dark:text-gray-400 transition-all">列表</button>
</div>
</div>
<!-- 课表网格视图 -->
<div id="gridView" class="overflow-x-auto">
<div class="grid gap-1 min-w-[320px]" id="teacherScheduleGrid" style="grid-template-columns: 48px repeat(7, 1fr); grid-template-rows: 32px repeat(11, minmax(48px, auto));">
<!-- 由 JS 动态生成 -->
</div>
</div>
<!-- 列表视图 -->
<div id="listView" class="hidden overflow-x-auto">
<table class="w-full text-xs">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 text-gray-500 dark:text-gray-400">
<th class="py-2 px-2 text-left font-medium">星期</th>
<th class="py-2 px-2 text-left font-medium">节次</th>
<th class="py-2 px-2 text-left font-medium">课程</th>
<th class="py-2 px-2 text-left font-medium">上课班级</th>
<th class="py-2 px-2 text-left font-medium">人数</th>
<th class="py-2 px-2 text-left font-medium">地点</th>
<th class="py-2 px-2 text-left font-medium">周次</th>
<th class="py-2 px-2 text-left font-medium">考核</th>
</tr>
</thead>
<tbody id="listTableBody"></tbody>
</table>
</div>
<!-- 空状态 -->
<div id="modalEmpty" class="text-center py-8 hidden">
<p class="text-gray-400 dark:text-gray-500 text-sm">该周次暂无课程</p>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
// ─── Session 自动刷新 ────────────────────────────────────────────
async function initSession() {
try {
const res = await fetch('/api/jwxt/ping');
const data = await res.json();
if (data.refreshed) console.log('[Session] 已刷新');
return true;
} catch (e) { console.warn('[Session] ping 失败:', e); return false; }
}
function isDarkMode() { return document.documentElement.classList.contains('dark'); }
// ─── 工具函数(复用 timetable.html 逻辑)──────────────────────────────
// 解析周次描述
function parseWeekRange(zcd) {
if (!zcd) return { start: 1, end: 20, isOdd: false, isEven: false };
const isOdd = zcd.includes('(单)');
const isEven = zcd.includes('(双)');
const clean = zcd.replace(/\([^)]*\)/g, '');
const segments = clean.split(',');
let minWeek = 20, maxWeek = 0;
for (const seg of segments) {
const match = seg.match(/(\d+)(?:-(\d+))?/);
if (match) {
const start = parseInt(match[1]);
const end = match[2] ? parseInt(match[2]) : start;
minWeek = Math.min(minWeek, start);
maxWeek = Math.max(maxWeek, end);
}
}
if (minWeek > maxWeek) return { start: 1, end: 20, isOdd, isEven };
return { start: minWeek, end: maxWeek, isOdd, isEven };
}
// 判断课程是否在指定周次
function isCourseInWeek(course, week) {
const zcd = course.zcd;
if (!zcd) return true;
const isOdd = zcd.includes('(单)');
const isEven = zcd.includes('(双)');
const clean = zcd.replace(/\([^)]*\)/g, '');
const segments = clean.split(',');
let inRange = false;
for (const seg of segments) {
const match = seg.match(/(\d+)(?:-(\d+))?/);
if (match) {
const start = parseInt(match[1]);
const end = match[2] ? parseInt(match[2]) : start;
if (start <= week && week <= end) { inRange = true; break; }
}
}
if (!inRange) return false;
if (isOdd && week % 2 === 0) return false;
if (isEven && week % 2 === 1) return false;
return true;
}
// 解析节数范围
function parsePeriodRange(jcor) {
if (!jcor || typeof jcor !== 'string') return { start: 1, end: 1 };
const parts = jcor.split(/[-,\s]+/).filter(p => p.trim());
if (parts.length >= 2) {
const s = parseInt(parts[0]);
const e = parseInt(parts[parts.length - 1]);
if (!isNaN(s) && !isNaN(e) && s > 0 && e > 0) return { start: s, end: e };
}
const p = parseInt(jcor);
if (!isNaN(p) && p > 0) return { start: p, end: p };
return { start: 1, end: 1 };
}
// 课程图标
function getCourseIcon(name) {
const n = name || '';
function has(...keys) { return keys.some(k => n.includes(k)); }
const icons = {
math: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="9" y1="9" x2="15" y2="9"/><line x1="12" y1="6" x2="12" y2="12"/><line x1="9" y1="15" x2="15" y2="15"/></svg>`,
code: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>`,
default: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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>`
};
if (has('数学', '微积分', '线性代数', '概率', '统计学')) return icons.math;
if (has('C语言', 'C++', 'Java', 'Python', '编程', '程序设计', '算法', '数据结构', '计算机', 'Web', '软件')) return icons.code;
return icons.default;
}
// 课程颜色
const COURSE_COLORS = [
{ bg: 'bg-blue-900/50', border: 'border-blue-700/70', text: 'text-blue-100' },
{ bg: 'bg-emerald-900/50', border: 'border-emerald-700/70', text: 'text-emerald-100' },
{ bg: 'bg-violet-900/50', border: 'border-violet-700/70', text: 'text-violet-100' },
{ bg: 'bg-amber-900/50', border: 'border-amber-700/70', text: 'text-amber-100' },
{ bg: 'bg-rose-900/50', border: 'border-rose-700/70', text: 'text-rose-100' },
{ bg: 'bg-cyan-900/50', border: 'border-cyan-700/70', text: 'text-cyan-100' },
{ bg: 'bg-lime-900/50', border: 'border-lime-700/70', text: 'text-lime-100' },
{ bg: 'bg-fuchsia-900/50', border: 'border-fuchsia-700/70', text: 'text-fuchsia-100' },
];
const courseColorMap = new Map();
function getCourseColor(name) {
if (!courseColorMap.has(name)) {
let h = 0; for (let i = 0; i < name.length; i++) h = name.charCodeAt(i) + ((h << 5) - h);
courseColorMap.set(name, Math.abs(h) % COURSE_COLORS.length);
}
return COURSE_COLORS[courseColorMap.get(name)];
}
// 节次时间
const PERIOD_TIMES = {
1: { start: '08:30', end: '09:15' }, 2: { start: '09:20', end: '10:05' },
3: { start: '10:25', end: '11:10' }, 4: { start: '11:15', end: '12:00' },
5: { start: '14:00', end: '14:45' }, 6: { start: '14:55', end: '15:40' },
7: { start: '16:00', end: '16:45' }, 8: { start: '16:55', end: '17:40' },
9: { start: '19:00', end: '19:45' }, 10: { start: '19:55', end: '20:40' },
11: { start: '20:45', end: '21:30' },
};
// 全局变量
let teacherModalData = null; // 当前教师的 kbList
let teacherModalWeek = 1; // 当前选择的周次
let teacherModalWeekCount = 20; // 最大周次
// ─── 弹窗控制 ─────────────────────────────────────────────────────────
function openTeacherModal(jgh_id, jgh, xm, jgmc, zcmc) {
const modal = document.getElementById('teacherModal');
document.getElementById('modalTeacherName').textContent = xm || jgh;
document.getElementById('modalTeacherInfo').textContent = [jgmc, zcmc].filter(Boolean).join(' · ') || jgh;
document.getElementById('modalLoading').classList.remove('hidden');
document.getElementById('modalError').classList.add('hidden');
document.getElementById('modalContent').classList.add('hidden');
document.getElementById('modalEmpty').classList.add('hidden');
// 当前页面的学年学期
const xnm = document.getElementById('fXnm').value || '2026';
const xqm = document.getElementById('fXqm').value || '3';
fetch(`/api/jwxt/teacher-schedule-detail?jgh_id=${encodeURIComponent(jgh_id)}&xnm=${xnm}&xqm=${xqm}`)
.then(r => r.json())
.then(data => {
document.getElementById('modalLoading').classList.add('hidden');
if (!data.success) {
document.getElementById('modalErrorText').textContent = data.message || '加载失败';
document.getElementById('modalError').classList.remove('hidden');
return;
}
teacherModalData = data.kbList || [];
// 计算最大周次
teacherModalWeekCount = 20;
teacherModalData.forEach(item => {
const w = parseWeekRange(item.zcd);
if (w.end > 0 && w.end < 25) teacherModalWeekCount = Math.max(teacherModalWeekCount, w.end);
});
// 填充周次选择
const weekSelect = document.getElementById('modalWeekSelect');
weekSelect.innerHTML = '';
for (let i = 1; i <= teacherModalWeekCount; i++) {
weekSelect.innerHTML += `<option value="${i}">第${i}周</option>`;
}
weekSelect.value = 1;
teacherModalWeek = 1;
document.getElementById('modalCourseCount').textContent = `${teacherModalData.length}门课`;
document.getElementById('modalContent').classList.remove('hidden');
renderTeacherScheduleInModal();
})
.catch(err => {
document.getElementById('modalLoading').classList.add('hidden');
document.getElementById('modalErrorText').textContent = '网络错误: ' + err.message;
document.getElementById('modalError').classList.remove('hidden');
});
modal.classList.add('modal-open');
document.documentElement.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
}
function closeTeacherModal() {
const modal = document.getElementById('teacherModal');
modal.classList.remove('modal-open');
document.documentElement.style.overflow = '';
document.body.style.overflow = '';
teacherModalData = null;
}
function renderTeacherScheduleInModal() {
if (!teacherModalData) return;
const week = parseInt(document.getElementById('modalWeekSelect').value);
teacherModalWeek = week;
const grid = document.getElementById('teacherScheduleGrid');
const emptyDiv = document.getElementById('modalEmpty');
// 表头
let html = `
<!-- 空角 -->
<div class="bg-white/50 dark:bg-gray-900/50 rounded-lg flex items-center justify-center text-[10px] font-bold text-gray-500 dark:text-gray-400" style="grid-column:1;grid-row:1;"></div>
<div class="bg-white/50 dark:bg-gray-900/50 rounded-lg text-center text-[10px] font-bold text-gray-600 dark:text-gray-300 flex items-center justify-center" style="grid-column:2;grid-row:1;">周一</div>
<div class="bg-white/50 dark:bg-gray-900/50 rounded-lg text-center text-[10px] font-bold text-gray-600 dark:text-gray-300 flex items-center justify-center" style="grid-column:3;grid-row:1;">周二</div>
<div class="bg-white/50 dark:bg-gray-900/50 rounded-lg text-center text-[10px] font-bold text-gray-600 dark:text-gray-300 flex items-center justify-center" style="grid-column:4;grid-row:1;">周三</div>
<div class="bg-white/50 dark:bg-gray-900/50 rounded-lg text-center text-[10px] font-bold text-gray-600 dark:text-gray-300 flex items-center justify-center" style="grid-column:5;grid-row:1;">周四</div>
<div class="bg-white/50 dark:bg-gray-900/50 rounded-lg text-center text-[10px] font-bold text-gray-600 dark:text-gray-300 flex items-center justify-center" style="grid-column:6;grid-row:1;">周五</div>
<div class="bg-white/50 dark:bg-gray-900/50 rounded-lg text-center text-[10px] font-bold text-gray-600 dark:text-gray-300 flex items-center justify-center" style="grid-column:7;grid-row:1;">周六</div>
<div class="bg-white/50 dark:bg-gray-900/50 rounded-lg text-center text-[10px] font-bold text-gray-600 dark:text-gray-300 flex items-center justify-center" style="grid-column:8;grid-row:1;">周日</div>
`;
// 节次行
for (let p = 1; p <= 11; p++) {
const ti = PERIOD_TIMES[p] || { start: '', end: '' };
html += `
<div class="bg-white/30 dark:bg-gray-900/30 rounded-lg flex flex-col items-center justify-center text-[9px] text-gray-500 dark:text-gray-400" style="grid-column:1;grid-row:${p+1};">
<div class="font-bold text-gray-700 dark:text-gray-300">${p}</div>
<div>${ti.start}</div>
</div>
`;
}
// 课程格子占位(7列)
for (let d = 0; d < 7; d++) {
for (let p = 1; p <= 11; p++) {
html += `<div class="bg-gray-50/20 dark:bg-gray-800/10 rounded border border-gray-200/30 dark:border-gray-700/20" style="grid-column:${d+2};grid-row:${p+1};"></div>`;
}
}
grid.innerHTML = html;
// 渲染课程
const courseGrid = Array(11).fill(null).map(() => Array(7).fill(null));
let courseCount = 0;
teacherModalData.forEach(item => {
if (!isCourseInWeek(item, week)) return;
const dayIndex = item.xqj - 1;
if (isNaN(dayIndex) || dayIndex < 0 || dayIndex > 6) return;
const pr = parsePeriodRange(item.skjc);
for (let p = pr.start; p <= pr.end; p++) {
if (p >= 1 && p <= 11) {
const pi = p - 1;
if (!courseGrid[pi][dayIndex]) {
courseGrid[pi][dayIndex] = { item, isStart: p === pr.start, rowSpan: pr.end - pr.start + 1 };
}
}
}
courseCount++;
});
// 写入课程
courseGrid.forEach((row, pi) => {
row.forEach((cell, di) => {
if (cell && cell.isStart) {
const color = getCourseColor(cell.item.kcmc);
const delay = Math.min(di * 40 + pi * 15, 300);
const cls = `course-cell rounded-lg overflow-hidden ${color.bg} ${color.text} border-l-4 ${color.border} flex flex-col justify-center p-1`;
const rowStyle = `grid-column:${di+2};grid-row:${pi+2}/span ${cell.rowSpan};animation-delay:${delay}ms;`;
const parts = [cell.item.kcmc, cell.item.cdmc || '无地点', cell.item.zcd || ''];
if (cell.item.jxbzcbjjc) parts.push('班级: ' + cell.item.jxbzcbjjc);
if (cell.item.jxbrs) parts.push('人数: ' + cell.item.jxbrs);
if (cell.item.khfsmc) parts.push(cell.item.khfsmc);
const title = parts.join('\n');
grid.innerHTML += `<div class="${cls}" style="${rowStyle}" title="${title.replace(/\n/g,'&#10;')}">
<div class="font-bold text-[10px] leading-tight mb-0.5">${cell.item.kcmc}</div>
<div class="text-[9px] opacity-80">${cell.item.cdmc || ''}</div>
<div class="text-[9px] opacity-60">${cell.item.skjc}</div>
</div>`;
}
});
});
emptyDiv.classList.toggle('hidden', courseCount > 0);
renderListView(week);
}
// ─── 视图切换 ─────────────────────────────────────────────────────
let currentView = 'grid';
function switchView(view) {
currentView = view;
const grid = document.getElementById('gridView');
const list = document.getElementById('listView');
const gridBtn = document.getElementById('viewGridBtn');
const listBtn = document.getElementById('viewListBtn');
if (view === 'grid') {
grid.classList.remove('hidden');
list.classList.add('hidden');
gridBtn.className = 'px-3 py-1 rounded-md text-xs font-medium bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm transition-all';
listBtn.className = 'px-3 py-1 rounded-md text-xs font-medium text-gray-500 dark:text-gray-400 transition-all';
} else {
grid.classList.add('hidden');
list.classList.remove('hidden');
listBtn.className = 'px-3 py-1 rounded-md text-xs font-medium bg-white dark:bg-gray-700 text-gray-900 dark:text-white shadow-sm transition-all';
gridBtn.className = 'px-3 py-1 rounded-md text-xs font-medium text-gray-500 dark:text-gray-400 transition-all';
}
}
function renderListView(week) {
const tbody = document.getElementById('listTableBody');
if (!tbody) return;
const weekItems = teacherModalData.filter(item => isCourseInWeek(item, week));
const dayNames = ['', '周一', '周二', '周三', '周四', '周五', '周六', '周日'];
if (weekItems.length === 0) {
tbody.innerHTML = '<tr><td colspan="8" class="py-4 text-center text-gray-400 dark:text-gray-500">该周次暂无课程</td></tr>';
return;
}
tbody.innerHTML = weekItems.map((item, idx) => {
const color = getCourseColor(item.kcmc);
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30">
<td class="py-2 px-2 text-gray-600 dark:text-gray-300">${dayNames[item.xqj] || '--'}</td>
<td class="py-2 px-2 text-gray-500 dark:text-gray-400">${item.skjc || '--'}</td>
<td class="py-2 px-2 font-medium text-gray-900 dark:text-white">${escHtml(item.kcmc || '--')}${item.xslxbj ? ' <span class="text-amber-500">' + escHtml(item.xslxbj) + '</span>' : ''}</td>
<td class="py-2 px-2 text-gray-500 dark:text-gray-400">${escHtml(item.jxbzcbjjc || '--')}</td>
<td class="py-2 px-2 text-gray-500 dark:text-gray-400 text-center">${item.jxbrs || '--'}</td>
<td class="py-2 px-2 text-gray-500 dark:text-gray-400">${escHtml(item.cdmc || '--')}</td>
<td class="py-2 px-2 text-gray-500 dark:text-gray-400 whitespace-nowrap">${item.zcd || '--'}</td>
<td class="py-2 px-2 text-gray-500 dark:text-gray-400">${item.khfsmc || '--'}</td>
</tr>`;
}).join('');
}
// ─── ECharts 图表 ─────────────────────────────────────────────────
let titleChart = null;
let deptChart = null;
function renderTitleChart(items) {
const dom = document.getElementById('titleChart');
if (!dom) return;
const titleMap = {};
items.forEach(item => { const t = item.zcmc || '未评级'; titleMap[t] = (titleMap[t] || 0) + 1; });
const data = Object.entries(titleMap).map(([name, value]) => ({ name, value }));
const dark = isDarkMode();
if (!titleChart) titleChart = echarts.init(dom);
titleChart.setOption({
tooltip: { trigger: 'item', formatter: '{b}: {c} 人 ({d}%)' },
legend: { bottom: 0, textStyle: { color: dark ? '#9ca3af' : '#6b7280', fontSize: 11 } },
series: [{
type: 'pie', radius: ['45%', '72%'], center: ['50%', '48%'],
itemStyle: { borderRadius: 6, borderColor: dark ? '#1f2937' : '#fff', borderWidth: 2 },
label: { color: dark ? '#d1d5db' : '#374151', fontSize: 11 },
data: data
}]
}, { notMerge: true });
titleChart.resize();
}
function renderDeptChart(items) {
const dom = document.getElementById('deptChart');
if (!dom) return;
const deptMap = {};
items.forEach(item => { const d = item.jgmc || '未知'; deptMap[d] = (deptMap[d] || 0) + 1; });
const sorted = Object.entries(deptMap).sort((a, b) => b[1] - a[1]);
const dark = isDarkMode();
if (!deptChart) deptChart = echarts.init(dom);
deptChart.setOption({
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
grid: { left: '3%', right: '10%', top: 10, bottom: 30, containLabel: true },
xAxis: {
type: 'value', name: '教师数',
nameTextStyle: { color: dark ? '#9ca3af' : '#6b7280' },
axisLabel: { color: dark ? '#9ca3af' : '#6b7280' }
},
yAxis: {
type: 'category', data: sorted.map(s => s[0]),
axisLabel: { color: dark ? '#9ca3af' : '#6b7280', fontSize: 10 },
inverse: true
},
series: [{
type: 'bar', data: sorted.map(s => s[1]),
itemStyle: { color: dark ? '#818cf8' : '#4f46e5', borderRadius: [0, 6, 6, 0] },
emphasis: { itemStyle: { color: dark ? '#a5b4fc' : '#6366f1' } }
}]
}, { notMerge: true });
deptChart.resize();
}
function setupDarkObserver() {
const observer = new MutationObserver(() => {
if (titleChart) { titleChart.dispose(); titleChart = null; }
if (deptChart) { deptChart.dispose(); deptChart = null; }
const items = window._lastTeacherItems;
if (items && items.length) {
renderCharts(items);
}
});
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
function renderCharts(items) {
const row = document.getElementById('chartsRow');
if (row) row.classList.remove('hidden');
renderTitleChart(items);
renderDeptChart(items);
}
window.addEventListener('resize', () => {
if (titleChart) titleChart.resize();
if (deptChart) deptChart.resize();
});
// ─── 列表渲染 ─────────────────────────────────────────────────────────
async function refresh() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('chartsRow').classList.add('hidden');
const xnm = document.getElementById('fXnm').value;
const xqm = document.getElementById('fXqm').value;
const xqh_id = document.getElementById('fXqh').value;
const zcm = document.getElementById('fZcm').value;
const jg_id = document.getElementById('fJg').value;
const kkbm_id = document.getElementById('fKkbm').value;
const jgh = document.getElementById('fJgh').value;
const zxszjjs = document.getElementById('fZxszjjs').checked ? '1' : '0';
const sfwp = document.getElementById('fSfwp').checked ? '1' : '0';
const params = new URLSearchParams({ page_size: 1000 });
if (xnm) params.set('xnm', xnm);
if (xqm) params.set('xqm', xqm);
if (xqh_id) params.set('xqh_id', xqh_id);
if (zcm) params.set('zcm', zcm);
if (jg_id) params.set('jg_id', jg_id);
if (kkbm_id) params.set('kkbm_id', kkbm_id);
if (jgh) params.set('jgh', jgh);
if (zxszjjs === '1') params.set('zxszjjs', '1');
if (sfwp === '1') params.set('sfwp', '1');
try {
const res = await fetch('/api/jwxt/teacher-schedule?' + params.toString());
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) {
document.getElementById('errorText').textContent = data.message || '查询失败';
document.getElementById('errorMessage').classList.remove('hidden');
return;
}
const items = data.items || [];
window._lastTeacherItems = items;
document.getElementById('totalCount').textContent = data.total || items.length;
if (!items.length) {
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('emptyState').classList.remove('hidden');
return;
}
renderTable(items);
document.getElementById('dataContainer').classList.remove('hidden');
renderCharts(items);
} catch (e) {
document.getElementById('loadingIndicator').classList.add('hidden');
document.getElementById('errorText').textContent = '网络错误: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
function renderTable(items) {
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, idx) => {
const campus = item.xqh_id === '1' ? '长清校区' : (item.xqh_id || '--');
return `<tr class="clickable-row border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors row-animate" style="animation-delay:${idx * 30}ms;"
onclick="openTeacherModal(${JSON.stringify(item.jgh_id||'').replace(/"/g,'&quot;')}, ${JSON.stringify(item.jgh||'').replace(/"/g,'&quot;')}, ${JSON.stringify(item.xm||'').replace(/"/g,'&quot;')}, ${JSON.stringify(item.jgmc||'').replace(/"/g,'&quot;')}, ${JSON.stringify(item.zcmc||'').replace(/"/g,'&quot;')})">
<td class="py-3 px-4 text-gray-400 dark:text-gray-500">${idx + 1}</td>
<td class="py-3 px-4 font-mono text-xs text-gray-500 dark:text-gray-400">${item.jgh || '--'}</td>
<td class="py-3 px-4 font-medium">${escHtml(item.xm || '--')}</td>
<td class="py-3 px-4 text-gray-500 dark:text-gray-400">${item.zcmc || '--'}</td>
<td class="py-3 px-4 text-gray-500 dark:text-gray-400">${escHtml(item.jgmc || '--')}</td>
<td class="py-3 px-4 text-gray-500 dark:text-gray-400">${campus}</td>
<td class="py-3 px-4 text-center text-gray-500 dark:text-gray-400 text-xs">${item.sjhm || '--'}</td>
</tr>`;
}).join('');
}
function escHtml(str) {
return String(str).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
// ─── 初始化 ────────────────────────────────────────────────────────────
document.addEventListener('DOMContentLoaded', function () {
// 将弹窗移到 body 直接子级
const modal = document.getElementById('teacherModal');
if (modal) document.body.appendChild(modal);
setupDarkObserver();
initSession().then(() => refresh());
// ESC 关闭弹窗
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') closeTeacherModal();
});
});
</script>
{% endblock %}
File diff suppressed because it is too large Load Diff
+74
View File
@@ -0,0 +1,74 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>
教学项目报名
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">各类教学项目报名</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">项目名称</th><th class="text-left py-3 px-4 font-semibold">项目类别</th><th class="text-left py-3 px-4 font-semibold">报名时间</th><th class="text-left py-3 px-4 font-semibold">状态</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无教学项目</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/teaching-project');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.xmmc||item.项目名称||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.xmlb||item.项目类别||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.bmsj||item.报名时间||'--')}</td>
<td class="py-3 px-4">${escHtml(item.zt||item.状态||'--')}</td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+68
View File
@@ -0,0 +1,68 @@
{% extends "base_tailwind.html" %}
{% block title %}用户服务协议 - {{ brand_name }}{% endblock %}
{% block extra_css %}
<style>
.prose h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }
.prose h2 { font-size: 1.1rem; font-weight: 700; margin-top: 2rem; margin-bottom: 0.75rem; padding-bottom: 0.4rem; border-bottom: 1px solid rgba(0,0,0,0.08); }
.dark .prose h2 { border-bottom-color: rgba(255,255,255,0.08); }
.prose h3 { font-size: 0.95rem; font-weight: 600; margin-top: 1.25rem; margin-bottom: 0.5rem; }
.prose p { margin-bottom: 0.75rem; line-height: 1.75; color: #4b5563; }
.dark .prose p { color: #9ca3af; }
.prose ul, .prose ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.prose li { margin-bottom: 0.35rem; line-height: 1.7; color: #4b5563; }
.dark .prose li { color: #9ca3af; }
.prose ul li { list-style-type: disc; }
.prose ol li { list-style-type: decimal; }
.prose strong { font-weight: 600; color: #111827; }
.dark .prose strong { color: #f3f4f6; }
.prose table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.875rem; }
.prose th { background: #f3f4f6; font-weight: 600; padding: 0.6rem 0.8rem; text-align: left; border: 1px solid #e5e7eb; }
.dark .prose th { background: #1f2937; border-color: #374151; }
.prose td { padding: 0.6rem 0.8rem; border: 1px solid #e5e7eb; }
.dark .prose td { border-color: #374151; }
.prose hr { border: none; border-top: 1px solid #e5e7eb; margin: 1.5rem 0; }
.dark .prose hr { border-top-color: #374151; }
.prose code { background: #f3f4f6; padding: 0.1em 0.4em; border-radius: 4px; font-size: 0.85em; }
.dark .prose code { background: #1f2937; }
.prose blockquote { border-left: 3px solid #e5e7eb; padding-left: 1rem; color: #6b7280; margin: 1rem 0; }
.dark .prose blockquote { border-color: #374151; color: #9ca3af; }
</style>
{% endblock %}
{% block content %}
<div class="max-w-3xl mx-auto py-4">
<!-- 返回 -->
<div class="mb-6 list-item-enter" style="animation-delay:0ms">
<a href="javascript:history.back()" class="inline-flex items-center gap-1.5 text-sm text-neutral-500 hover:text-neutral-800 dark:hover:text-neutral-200 transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
返回
</a>
</div>
<div class="glass rounded-3xl p-6 md:p-10 layer-3 list-item-enter" style="animation-delay:50ms">
<!-- 头部 -->
<div class="flex items-start gap-4 mb-8 pb-6 border-b border-neutral-200 dark:border-neutral-800">
<div class="w-12 h-12 rounded-2xl bg-black dark:bg-white flex items-center justify-center text-white dark:text-black font-bold text-lg flex-shrink-0">S</div>
<div>
<h1 class="text-xl md:text-2xl font-bold text-neutral-900 dark:text-white">用户服务协议</h1>
<p class="text-sm text-neutral-500 dark:text-neutral-400 mt-1">{{ brand_name }}</p>
</div>
</div>
<!-- 正文:由后端读取 docs/terms.md 渲染 -->
<div class="prose text-sm md:text-base text-neutral-800 dark:text-neutral-200">
{{ content | safe }}
</div>
<!-- 底部链接 -->
<div class="mt-8 pt-6 border-t border-neutral-200 dark:border-neutral-800 flex gap-4 text-sm text-neutral-500">
<a href="{{ url_for('main.privacy') }}" class="hover:text-black dark:hover:text-white transition-colors underline underline-offset-2">隐私政策</a>
<a href="{{ url_for('main.buy') }}" class="hover:text-black dark:hover:text-white transition-colors underline underline-offset-2">购买页面</a>
</div>
</div>
</div>
{% endblock %}
+287
View File
@@ -0,0 +1,287 @@
{% 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; }
.tab-active { border-bottom: 2px solid currentColor; font-weight: 600; }
</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">
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
<path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
</svg>
教材明细查询
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">查看课程使用教材明细</p>
</div>
<button onclick="refresh()"
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 class="flex gap-2 mb-4 flex-wrap" id="tabBar">
<span class="text-sm text-gray-500 dark:text-gray-400 self-center mr-2">学年:</span>
<select id="filterXnm" onchange="refresh()" class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="2025" selected>2025-2026</option>
<option value="2024">2024-2025</option>
<option value="2023">2023-2024</option>
</select>
<select id="filterXqm" onchange="refresh()" class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="3">第1学期</option>
<option value="12">第2学期</option>
</select>
<select id="filterXyzt" onchange="refresh()" class="px-3 py-1.5 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-black/30 text-sm">
<option value="">全部</option>
<option value="1">已选</option>
<option value="0">未选</option>
</select>
</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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden">
<p id="errorText" class="text-red-500"></p>
</div>
<!-- ECharts 图表(独立于 dataContainer,避免在 display:none 中初始化) -->
<div id="chartsRow" class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4 hidden list-item-enter" style="animation-delay: 150ms;">
<div class="glass rounded-2xl p-4">
<h3 class="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">出版社分布</h3>
<div id="publisherChart" style="height:300px;"></div>
</div>
<div class="glass rounded-2xl p-4">
<h3 class="text-sm font-semibold mb-2 text-gray-700 dark:text-gray-300">选用状态分布</h3>
<div id="xkStatusChart" style="height:300px;"></div>
</div>
</div>
<div id="dataContainer" class="hidden list-item-enter" style="animation-delay: 200ms;">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50">
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">#</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">课程名称</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">教材名称</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">ISBN</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">出版社</th>
<th class="text-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">作者</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">定价</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">选用状态</th>
<th class="text-center py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">预订状态</th>
</tr>
</thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden">
<p class="text-gray-500 dark:text-gray-400 text-lg">暂无教材明细</p>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
let publisherChart = null;
let xkStatusChart = null;
function isDarkMode() { return document.documentElement.classList.contains('dark'); }
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 refresh() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('chartsRow').classList.add('hidden');
await initSession();
const xnm = document.getElementById('filterXnm').value;
const xqm = document.getElementById('filterXqm').value;
const xyzt = document.getElementById('filterXyzt').value;
const params = new URLSearchParams({ page_size: 200 });
if (xnm) params.set('xnm', xnm);
if (xqm) params.set('xqm', xqm);
if (xyzt) params.set('xyzt', xyzt);
try {
const res = await fetch('/api/jwxt/textbook-details?' + params.toString());
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) {
document.getElementById('errorText').textContent = data.message || '查询失败';
document.getElementById('errorMessage').classList.remove('hidden');
return;
}
const items = data.items || [];
if (!items.length) {
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('emptyState').classList.remove('hidden');
document.getElementById('chartsRow').classList.add('hidden');
return;
}
renderTable(items);
document.getElementById('dataContainer').classList.remove('hidden');
document.getElementById('chartsRow').classList.remove('hidden');
renderCharts(items);
setupDarkObserver();
} catch (e) {
document.getElementById('loadingIndicator').classList.add('hidden');
document.getElementById('errorText').textContent = '网络错误: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
function renderTable(items) {
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, idx) => {
const price = item.price || item.price_sort || '--';
const zkprice = item.zkprice || '--';
const statusColor = item.xkzt === '已选课'
? 'text-green-600 dark:text-green-400'
: 'text-orange-500 dark:text-orange-400';
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors row-animate" style="animation-delay:${idx * 40}ms;">
<td class="py-3 px-4 text-gray-400 dark:text-gray-500">${idx + 1}</td>
<td class="py-3 px-4 font-medium">${escHtml(item.kcmc || '--')}</td>
<td class="py-3 px-4 max-w-[200px] truncate" title="${escHtml(item.jcmc || '')}">${escHtml(item.jcmc || '--')}</td>
<td class="py-3 px-4 text-gray-500 dark:text-gray-400 font-mono text-xs">${item.isbn || '--'}</td>
<td class="py-3 px-4 text-gray-500 dark:text-gray-400">${escHtml(item.cbs || '--')}</td>
<td class="py-3 px-4 text-gray-500 dark:text-gray-400">${escHtml(item.jczz || '--')}</td>
<td class="py-3 px-4 text-center">${price}${zkprice && zkprice !== price ? `<span class="text-xs text-orange-400 ml-1">(${zkprice})</span>` : ''}</td>
<td class="py-3 px-4 text-center ${statusColor} font-medium">${item.xkzt || '--'}</td>
<td class="py-3 px-4 text-center text-gray-500 dark:text-gray-400">${item.ydzt || '--'}</td>
</tr>`;
}).join('');
}
function escHtml(str) {
return String(str).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}
// ── ECharts 图表渲染 ──
let _lastTextbookItems = [];
function renderCharts(items) {
_lastTextbookItems = items;
renderPublisherChart(items);
renderXkStatusChart(items);
}
function renderPublisherChart(items) {
const dom = document.getElementById('publisherChart');
if (!dom) return;
if (publisherChart) publisherChart.dispose();
const counts = {};
items.forEach(it => {
const k = it.cbs || '未知';
counts[k] = (counts[k] || 0) + 1;
});
const sorted = Object.entries(counts).sort((a, b) => b[1] - a[1]);
// 取前10,其余归为"其他"
let data;
if (sorted.length > 10) {
const top10 = sorted.slice(0, 10);
const otherCount = sorted.slice(10).reduce((s, e) => s + e[1], 0);
data = [...top10.map(([n, v]) => ({ name: n, value: v })), { name: '其他', value: otherCount }];
} else {
data = sorted.map(([name, value]) => ({ name, value }));
}
publisherChart = echarts.init(dom);
publisherChart.setOption({
tooltip: { trigger: 'item', formatter: '{b}: {c} ({d}%)' },
legend: { type: 'scroll', bottom: 0, textStyle: { fontSize: 10, color: isDarkMode() ? '#9ca3af' : '#6b7280' } },
series: [{
type: 'pie', radius: ['35%', '65%'], center: ['50%', '45%'],
data: data,
label: { formatter: '{b}\n{d}%', fontSize: 10 },
itemStyle: { borderColor: isDarkMode() ? '#1f2937' : '#fff', borderWidth: 2 }
}]
});
}
function renderXkStatusChart(items) {
const dom = document.getElementById('xkStatusChart');
if (!dom) return;
if (xkStatusChart) xkStatusChart.dispose();
const counts = {};
items.forEach(it => {
const k = it.xkzt || '未知';
counts[k] = (counts[k] || 0) + 1;
});
const data = Object.entries(counts).map(([name, value]) => ({ name, value }));
xkStatusChart = echarts.init(dom);
xkStatusChart.setOption({
tooltip: { trigger: 'item', formatter: '{b}: {c} ({d}%)' },
legend: { bottom: 0, textStyle: { fontSize: 11, color: isDarkMode() ? '#9ca3af' : '#6b7280' } },
series: [{
type: 'pie', radius: ['45%', '70%'], center: ['50%', '45%'],
data: data,
label: { formatter: '{b}\n{d}%', fontSize: 11 },
itemStyle: { borderColor: isDarkMode() ? '#1f2937' : '#fff', borderWidth: 2 }
}]
});
}
// ── 深色模式观察 ──
let _darkObserverTextbook = null;
function setupDarkObserver() {
if (_darkObserverTextbook) _darkObserverTextbook.disconnect();
_darkObserverTextbook = new MutationObserver(() => {
if (publisherChart) { publisherChart.dispose(); publisherChart = null; }
if (xkStatusChart) { xkStatusChart.dispose(); xkStatusChart = null; }
if (_lastTextbookItems.length) renderCharts(_lastTextbookItems);
});
_darkObserverTextbook.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
window.addEventListener('resize', () => {
if (publisherChart) publisherChart.resize();
if (xkStatusChart) xkStatusChart.resize();
});
refresh();
</script>
{% endblock %}
+485
View File
@@ -0,0 +1,485 @@
{% 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;
}
.tb-card {
transition: all 0.25s ease;
}
.tb-card:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(0,0,0,0.08);
}
.dark .tb-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-ordered {
background: #d1fae5;
color: #065f46;
}
.status-unordered {
background: #fee2e2;
color: #991b1b;
}
.dark .status-ordered {
background: #064e3b;
color: #6ee7b7;
}
.dark .status-unordered {
background: #7f1d1d;
color: #fca5a5;
}
.toast-notification {
position: fixed; top: 20px; right: 20px; z-index: 9999;
transition: all 0.3s ease;
}
</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">
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
<path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
<path d="M8 7h8"/>
<path d="M8 11h6"/>
</svg>
教材预订
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">管理已选课程的教材预订与退订</p>
</div>
<button onclick="refresh()"
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 flex-shrink-0">
<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>
<!-- Toast 通知 -->
<div id="toast" class="toast-notification hidden"></div>
<!-- 筛选栏 -->
<div class="flex flex-wrap gap-3 items-center mb-4 list-item-enter" style="animation-delay: 50ms;">
<select id="filterXnm" onchange="refresh()"
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>
<option value="2026" selected>2026-2027</option>
<option value="2025">2025-2026</option>
<option value="2024">2024-2025</option>
</select>
<select id="filterXqm" onchange="refresh()"
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>
<option value="3">第1学期</option>
<option value="12">第2学期</option>
</select>
<select id="filterStatus" onchange="filterCards()"
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>
<option value="已订">已预订</option>
<option value="未订">未预订</option>
</select>
</div>
<!-- 图表区 -->
<div id="chartsRow" class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6 hidden list-item-enter" style="animation-delay: 120ms;">
<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="courseTypeChart" 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="textbookCoverageChart" class="h-64"></div>
</div>
</div>
<!-- 统计卡片 -->
<div id="statsRow" class="grid grid-cols-2 md:grid-cols-4 gap-3 mb-4 hidden list-item-enter" style="animation-delay: 100ms;">
<div class="glass rounded-xl p-4 text-center">
<div class="text-2xl font-bold" id="statTotal">0</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">总课程数</div>
</div>
<div class="glass rounded-xl p-4 text-center">
<div class="text-2xl font-bold text-green-600 dark:text-green-400" id="statOrdered">0</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">已预订</div>
</div>
<div class="glass rounded-xl p-4 text-center">
<div class="text-2xl font-bold text-red-500 dark:text-red-400" id="statUnordered">0</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">未预订</div>
</div>
<div class="glass rounded-xl p-4 text-center">
<div class="text-2xl font-bold text-blue-600 dark:text-blue-400" id="statHasTextbook">0</div>
<div class="text-xs text-gray-500 dark:text-gray-400 mt-1">有教材信息</div>
</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="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="cardsContainer" class="hidden grid grid-cols-1 lg:grid-cols-2 gap-4 list-item-enter" 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">
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
<path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
</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 allItems = [];
let courseTypeChart = null;
let textbookCoverageChart = null;
function isDarkMode() { return document.documentElement.classList.contains('dark'); }
function showToast(message, type) {
const toast = document.getElementById('toast');
const colors = {
success: 'bg-green-500 text-white',
error: 'bg-red-500 text-white',
info: 'bg-blue-500 text-white',
};
toast.className = `toast-notification ${colors[type] || colors.info} px-6 py-3 rounded-lg shadow-lg text-sm font-medium`;
toast.textContent = message;
toast.classList.remove('hidden');
setTimeout(() => toast.classList.add('hidden'), 3000);
}
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 refresh() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('cardsContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
document.getElementById('statsRow').classList.add('hidden');
document.getElementById('chartsRow').classList.add('hidden');
await initSession();
const xnm = document.getElementById('filterXnm').value;
const xqm = document.getElementById('filterXqm').value;
const params = new URLSearchParams({ page_size: 1500 });
if (xnm) params.set('xnm', xnm);
if (xqm) params.set('xqm', xqm);
try {
const res = await fetch('/api/jwxt/textbook-orders?' + params.toString());
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) {
document.getElementById('errorText').textContent = data.message || '查询失败';
document.getElementById('errorMessage').classList.remove('hidden');
return;
}
allItems = data.items || [];
if (!allItems.length) {
document.getElementById('emptyState').classList.remove('hidden');
document.getElementById('chartsRow').classList.add('hidden');
return;
}
renderStats(allItems);
renderCards(allItems);
document.getElementById('cardsContainer').classList.remove('hidden');
document.getElementById('statsRow').classList.remove('hidden');
document.getElementById('chartsRow').classList.remove('hidden');
// 确保容器可见后再初始化 ECharts(避免 display:none 下 0 尺寸)
setTimeout(() => renderCharts(allItems), 50);
} catch (e) {
document.getElementById('loadingIndicator').classList.add('hidden');
document.getElementById('errorText').textContent = '网络错误: ' + e.message;
document.getElementById('errorMessage').classList.remove('hidden');
}
}
function renderStats(items) {
const total = items.length;
const ordered = items.filter(i => i.zdzt === '已订').length;
const unordered = total - ordered;
const hasTextbook = items.filter(i => i.jcxx && i.jcxx.trim()).length;
document.getElementById('statTotal').textContent = total;
document.getElementById('statOrdered').textContent = ordered;
document.getElementById('statUnordered').textContent = unordered;
document.getElementById('statHasTextbook').textContent = hasTextbook;
}
function filterCards() {
const status = document.getElementById('filterStatus').value;
if (!status) {
renderCards(allItems);
} else {
renderCards(allItems.filter(i => i.zdzt === status));
}
}
function renderCards(items) {
const container = document.getElementById('cardsContainer');
container.innerHTML = '';
items.forEach((item, idx) => {
const ordered = item.zdzt === '已订';
const statusClass = ordered ? 'status-ordered' : 'status-unordered';
const statusLabel = ordered ? '✓ 已预订' : '✗ 未预订';
const textbookInfo = item.jcxx || '';
// 解析教材信息: "书名/作者/出版社/版次"
const tbParts = textbookInfo.split('/');
const tbName = tbParts[0] || '';
const tbAuthor = tbParts[1] || '';
const tbPublisher = tbParts[2] || '';
const delay = idx * 60;
const hasTextbook = textbookInfo.trim().length > 0;
const card = document.createElement('div');
card.className = 'tb-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="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
<path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
</svg>
</div>
<div class="min-w-0">
<h3 class="text-base font-semibold truncate">${escHtml(item.kcmc || '--')}</h3>
<div class="flex flex-wrap gap-x-4 gap-y-1 mt-1 text-xs text-gray-500 dark:text-gray-400">
<span>${escHtml(item.kcxzmc || '--')}</span>
<span>${escHtml(item.jsxx || '--')}</span>
</div>
</div>
</div>
<div class="grid grid-cols-2 sm:grid-cols-3 gap-3">
<div>
<div class="text-xs text-gray-400 dark:text-gray-500 mb-0.5">上课地点</div>
<div class="text-sm font-medium truncate">${escHtml(item.jxdd || '--')}</div>
</div>
<div>
<div class="text-xs text-gray-400 dark:text-gray-500 mb-0.5">选课时间</div>
<div class="text-sm font-medium">${item.xksj || '--'}</div>
</div>
<div>
<div class="text-xs text-gray-400 dark:text-gray-500 mb-0.5">预订时间</div>
<div class="text-sm font-medium">${item.jcydsj || '--'}</div>
</div>
</div>
${hasTextbook ? `
<div class="mt-3 pt-3 border-t border-gray-100 dark:border-gray-800">
<div class="text-xs text-gray-400 dark:text-gray-500 mb-1">教材信息</div>
<div class="text-sm text-gray-700 dark:text-gray-300">
<span class="font-medium">${escHtml(tbName)}</span>
${tbAuthor ? `<span class="text-gray-400 mx-1">/</span><span class="text-gray-500 dark:text-gray-400 text-xs">${escHtml(tbAuthor)}</span>` : ''}
${tbPublisher ? `<span class="text-gray-400 mx-1">/</span><span class="text-gray-500 dark:text-gray-400 text-xs">${escHtml(tbPublisher)}</span>` : ''}
</div>
</div>
` : ''}
</div>
<!-- 右侧操作区域 -->
<div class="flex sm:flex-col items-center sm:items-end gap-3 sm:gap-2 flex-shrink-0">
<span class="status-badge ${statusClass}">${statusLabel}</span>
${ordered
? `<button onclick="toggleOrder('${item.jxb_id}', 'cancel')" class="px-4 py-1.5 rounded-lg text-xs font-medium border border-orange-300 dark:border-orange-700 text-orange-600 dark:text-orange-400 hover:bg-orange-50 dark:hover:bg-orange-900/30 transition-colors whitespace-nowrap">退订</button>`
: `<button onclick="toggleOrder('${item.jxb_id}', 'order')" class="px-4 py-1.5 rounded-lg text-xs font-medium bg-blue-500 text-white hover:bg-blue-600 transition-colors whitespace-nowrap">预订</button>`
}
</div>
</div>
`;
container.appendChild(card);
});
}
function escHtml(str) {
return String(str).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
}
async function toggleOrder(jxbId, action) {
const actionName = action === 'order' ? '预订' : '退订';
if (!confirm(`确定${actionName}该课程的教材吗?`)) return;
try {
const res = await fetch('/api/jwxt/textbook-order', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ jxb_id: jxbId, action: action }),
});
const data = await res.json();
if (data.success) {
showToast(data.message || `${actionName}成功`, 'success');
refresh();
} else {
showToast(data.message || `${actionName}失败`, 'error');
}
} catch (e) {
showToast('网络错误: ' + e.message, 'error');
}
}
// ── ECharts 图表渲染 ──
function renderCharts(items) {
renderCourseTypeChart(items);
renderTextbookCoverageChart(items);
setupDarkObserver(items);
}
function renderCourseTypeChart(items) {
const dom = document.getElementById('courseTypeChart');
if (!dom) return;
if (courseTypeChart) courseTypeChart.dispose();
const counts = {};
items.forEach(it => {
const k = it.kcxzmc || '其他';
counts[k] = (counts[k] || 0) + 1;
});
const entries = Object.entries(counts).sort((a, b) => b[1] - a[1]);
const dark = isDarkMode();
const colors = dark
? ['#60a5fa', '#34d399', '#fbbf24', '#f87171', '#a78bfa', '#f472b6', '#38bdf8']
: ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#0ea5e9'];
courseTypeChart = echarts.init(dom);
courseTypeChart.setOption({
tooltip: { trigger: 'item', formatter: '{b}: {c} 门 ({d}%)' },
legend: { bottom: 0, type: 'scroll', textStyle: { fontSize: 11, color: dark ? '#d1d5db' : '#374151' } },
series: [{
type: 'pie', radius: ['40%', '70%'], center: ['50%', '45%'],
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);
}
function renderTextbookCoverageChart(items) {
const dom = document.getElementById('textbookCoverageChart');
if (!dom) return;
if (textbookCoverageChart) textbookCoverageChart.dispose();
const has = items.filter(i => i.jcxx && i.jcxx.trim()).length;
const none = items.length - has;
const dark = isDarkMode();
const colors = dark ? ['#34d399', '#6b7280'] : ['#10b981', '#9ca3af'];
textbookCoverageChart = echarts.init(dom);
textbookCoverageChart.setOption({
tooltip: { trigger: 'item', formatter: '{b}: {c} 门 ({d}%)' },
legend: { bottom: 0, textStyle: { fontSize: 11, color: dark ? '#d1d5db' : '#374151' } },
series: [{
type: 'pie', radius: ['45%', '70%'], center: ['50%', '45%'],
itemStyle: { borderRadius: 4, borderColor: dark ? '#1f2937' : '#fff', borderWidth: 2 },
label: { fontSize: 11, color: dark ? '#d1d5db' : '#374151' },
data: [
{ name: '有教材信息', value: has, itemStyle: { color: colors[0] } },
{ name: '无教材信息', value: none, itemStyle: { color: colors[1] } }
]
}]
}, true);
}
// ── 深色模式观察 ──
let _darkObserverTextbook = null;
function setupDarkObserver(items) {
if (_darkObserverTextbook) _darkObserverTextbook.disconnect();
_darkObserverTextbook = new MutationObserver(() => {
if (courseTypeChart) { courseTypeChart.dispose(); courseTypeChart = null; }
if (textbookCoverageChart) { textbookCoverageChart.dispose(); textbookCoverageChart = null; }
renderCharts(items);
});
_darkObserverTextbook.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
}
window.addEventListener('resize', () => {
courseTypeChart?.resize();
textbookCoverageChart?.resize();
});
// 初始化
initSession().then(sessionOk => {
if (!sessionOk) {
document.getElementById('errorText').innerHTML = '教务系统 Session 已失效,请尝试<a href="/dashboard" class="underline">重新配置教务账号</a>';
document.getElementById('errorMessage').classList.remove('hidden');
return;
}
refresh();
});
</script>
{% endblock %}
+78
View File
@@ -0,0 +1,78 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M22 10v6M2 10l10-5 10 5-10 5z"/><path d="M6 12v5c3 3 9 3 12 0v-5"/></svg>
毕业论文成绩
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">查看毕业论文(设计)成绩</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">课题名称</th><th class="text-left py-3 px-4 font-semibold">指导教师</th><th class="text-left py-3 px-4 font-semibold">成绩</th><th class="text-left py-3 px-4 font-semibold">等级</th><th class="text-left py-3 px-4 font-semibold">评语</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无成绩信息</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/thesis-grades');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
const score = item.cj||item.成绩||item.zcj||'--';
const grade = item.dj||item.等级||'--';
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.ktmc||item.课题名称||'--')}</td>
<td class="py-3 px-4">${escHtml(item.zdjs||item.指导教师||item.xm||'--')}</td>
<td class="py-3 px-4 font-medium ${parseFloat(score)>=90?'text-green-600':parseFloat(score)>=80?'text-blue-600':parseFloat(score)>=70?'text-yellow-600':'text-gray-600'}">${escHtml(score)}</td>
<td class="py-3 px-4">${escHtml(grade)}</td>
<td class="py-3 px-4 text-gray-500 text-xs max-w-xs truncate">${escHtml(item.py||item.评语||'--')}</td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function escAttr(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
@@ -0,0 +1,88 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/><line x1="8" y1="11" x2="14" y2="11"/></svg>
论文查重
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">毕业论文(设计)查重检测</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 id="statusBar" class="glass rounded-2xl p-4 mb-4 hidden">
<div class="flex items-center gap-2 text-sm">
<span class="text-xs font-medium text-gray-500 dark:text-gray-400">查重状态</span>
<span id="checkStatus" class="px-2 py-0.5 rounded text-xs bg-gray-100">加载中...</span>
</div>
</div>
<div id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">检测论文</th><th class="text-left py-3 px-4 font-semibold">检测时间</th><th class="text-left py-3 px-4 font-semibold">相似比</th><th class="text-left py-3 px-4 font-semibold">检测结果</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无查重记录</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
document.getElementById('statusBar').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/thesis-plagiarism-check');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
if (data.check_status) {
document.getElementById('statusBar').classList.remove('hidden');
const st = document.getElementById('checkStatus');
st.textContent = data.check_status;
st.className = 'px-2 py-0.5 rounded text-xs ' + (data.check_status.includes('通过')||data.check_status.includes('合格')?'bg-green-100 text-green-700':data.check_status.includes('待检')||data.check_status.includes('未检')?'bg-yellow-100 text-yellow-700':'bg-gray-100 text-gray-600');
}
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.lwmc||item.论文名称||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.jcsj||item.检测时间||'--')}</td>
<td class="py-3 px-4">${escHtml(item.xsb||item.相似比||item.查重率||'--')}</td>
<td class="py-3 px-4">${escHtml(item.jcjg||item.检测结果||'--')}</td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function escAttr(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+76
View File
@@ -0,0 +1,76 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><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>
过程资料
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">提交和查看毕业论文(设计)过程文档</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">文档名称</th><th class="text-left py-3 px-4 font-semibold">文档类型</th><th class="text-left py-3 px-4 font-semibold">提交时间</th><th class="text-left py-3 px-4 font-semibold">审核状态</th><th class="text-left py-3 px-4 font-semibold">操作</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无过程资料</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/thesis-process-docs');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || [];
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.wdmc||item.文档名称||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.wdlxmc||item.文档类型||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.tjsj||item.提交时间||'--')}</td>
<td class="py-3 px-4">${escHtml(item.shztmc||item.审核状态||'--')}</td>
<td class="py-3 px-4"><a href="${item.file_url||'#'}" class="text-xs text-blue-500 hover:text-blue-600 ${item.file_url?'':'pointer-events-none text-gray-400'}" target="_blank">${item.file_url?'查看':'未上传'}</a></td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function escAttr(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
+84
View File
@@ -0,0 +1,84 @@
{% 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; }
@media (prefers-reduced-motion: reduce) {
.row-animate { animation: none !important; opacity: 1 !important; }
.list-item-enter { 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">
<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"><path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/><line x1="8" y1="7" x2="16" y2="7"/><line x1="8" y1="11" x2="14" y2="11"/></svg>
学生选题
</h2>
<p class="text-sm text-gray-500 dark:text-gray-400 mt-1">毕业论文(设计)选题</p>
</div>
<button onclick="loadData()" class="px-4 py-2 rounded-lg border"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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 class="glass rounded-2xl p-4 mb-4">
<div class="flex items-center gap-2 text-sm">
<span class="text-xs font-medium text-gray-500 dark:text-gray-400 mr-2">选题状态</span>
<span id="topicStatus" class="px-2 py-0.5 rounded text-xs bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400">加载中...</span>
</div>
</div>
<div id="loadingIndicator" class="text-center py-12 hidden"><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="errorMessage" class="glass rounded-2xl p-6 mb-4 text-center hidden"><p id="errorText" class="text-red-500"></p></div>
<div id="dataContainer" class="hidden">
<div class="glass rounded-2xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-gray-800/50"><th class="text-left py-3 px-4 font-semibold">课题名称</th><th class="text-left py-3 px-4 font-semibold">指导教师</th><th class="text-left py-3 px-4 font-semibold">课题来源</th><th class="text-left py-3 px-4 font-semibold">选题状态</th></tr></thead>
<tbody id="tableBody"></tbody>
</table>
</div>
</div>
</div>
<div id="emptyState" class="glass rounded-2xl p-12 text-center hidden"><p class="text-gray-500 dark:text-gray-400 text-lg">暂无选题信息</p></div>
</div>
{% endblock %}
{% block extra_js %}
<script>
async function loadData() {
document.getElementById('loadingIndicator').classList.remove('hidden');
document.getElementById('errorMessage').classList.add('hidden');
document.getElementById('dataContainer').classList.add('hidden');
document.getElementById('emptyState').classList.add('hidden');
try {
const res = await fetch('/api/jwxt/thesis-topic');
const data = await res.json();
document.getElementById('loadingIndicator').classList.add('hidden');
if (!data.success) { showError(data.message); return; }
const items = data.items || data.available_topics || [];
const statusText = data.status || (items.length > 0 ? '已选题' : '未选题');
document.getElementById('topicStatus').textContent = statusText;
document.getElementById('topicStatus').className = 'px-2 py-0.5 rounded text-xs ' + (statusText.includes('已选')?'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400':'bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400');
if (!items.length) { document.getElementById('emptyState').classList.remove('hidden'); return; }
const tbody = document.getElementById('tableBody');
tbody.innerHTML = items.map((item, i) => {
return `<tr class="border-b border-gray-100 dark:border-gray-800 hover:bg-gray-50/50 dark:hover:bg-gray-800/30 transition-colors">
<td class="py-3 px-4">${escHtml(item.ktmc||item.课题名称||'--')}</td>
<td class="py-3 px-4">${escHtml(item.zdjs||item.指导教师||item.xm||'--')}</td>
<td class="py-3 px-4 text-gray-500">${escHtml(item.ktlymc||item.课题来源||'--')}</td>
<td class="py-3 px-4">${escHtml(item.xtztmc||item.选题状态||'--')}</td>
</tr>`;
}).join('');
document.getElementById('dataContainer').classList.remove('hidden');
} catch(e) { document.getElementById('loadingIndicator').classList.add('hidden'); showError('网络错误: '+e.message); }
}
function showError(msg) { document.getElementById('errorText').textContent = msg; document.getElementById('errorMessage').classList.remove('hidden'); }
function escHtml(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
function escAttr(s) { if(s==null) return ''; return String(s).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); }
document.addEventListener('DOMContentLoaded', () => loadData());
</script>
{% endblock %}
File diff suppressed because it is too large Load Diff
+28
View File
@@ -0,0 +1,28 @@
{% extends "base_tailwind.html" %}
{% block title %}选课模式进行中 - {{ brand_name }}{% endblock %}
{% block content %}
<div class="min-h-[60vh] flex items-center justify-center px-4">
<div class="glass rounded-2xl p-8 md:p-12 max-w-lg w-full text-center layer-2">
<div class="w-16 h-16 mx-auto rounded-2xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center">
<svg class="w-8 h-8 text-amber-600 dark:text-amber-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
<h1 class="text-xl md:text-2xl font-bold text-neutral-900 dark:text-white mt-6">选课模式进行中</h1>
<p class="text-neutral-500 dark:text-neutral-400 mt-3 leading-relaxed">
为了选课需求,选课时间段内暂时关闭其他服务。<br>
课程搜索、选课、退课、已选查询和抢课任务不受影响,<br>
其他功能将在选课结束后自动恢复。
</p>
<div class="mt-8 flex gap-3 justify-center flex-wrap">
<a href="{% if current_user.is_authenticated %}{{ url_for('main.courses') }}{% else %}{{ url_for('main.login') }}{% endif %}"
class="btn-primary px-6 py-2.5 rounded-full text-sm font-bold inline-block">{% if current_user.is_authenticated %}去选课{% else %}先登录{% endif %}</a>
<a href="{{ url_for('main.dashboard') }}"
class="px-6 py-2.5 rounded-full text-sm font-bold border border-neutral-300 dark:border-neutral-600 text-neutral-700 dark:text-neutral-200 inline-block">返回首页</a>
</div>
</div>
</div>
{% endblock %}