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