初版:教务抢课系统 jwxt(从线上实例导出)
This commit is contained in:
@@ -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 %}
|
||||
Reference in New Issue
Block a user