623 lines
30 KiB
HTML
623 lines
30 KiB
HTML
{% 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 %}
|