468 lines
21 KiB
HTML
468 lines
21 KiB
HTML
{% extends "base_tailwind.html" %}
|
|
|
|
{% block title %}学业预警 - {{ brand_name }}{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<style>
|
|
@keyframes fadeSlideIn {
|
|
from { opacity: 0; transform: translateY(8px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
.row-animate { animation: fadeSlideIn 0.3s ease both; }
|
|
|
|
.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, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
}
|
|
function escAttr(s) {
|
|
if (s == null) return '';
|
|
return String(s).replace(/&/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
}
|
|
|
|
// ── 各类别学分完成度柱状图 ──
|
|
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 %}
|