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