初版:教务抢课系统 jwxt(从线上实例导出)
This commit is contained in:
@@ -0,0 +1,638 @@
|
||||
{% 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; }
|
||||
select.filter-select {
|
||||
appearance: none;
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 10px center;
|
||||
padding-right: 28px;
|
||||
}
|
||||
.dark select.filter-select {
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
|
||||
}
|
||||
.jyfs-radio { transition: all 0.2s; user-select: none; }
|
||||
.jyfs-radio:not(.active) { background: transparent; color: inherit; }
|
||||
.jyfs-radio.active { background: #000; color: #fff; }
|
||||
.dark .jyfs-radio.active { background: #fff; color: #000; }
|
||||
.time-chip {
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
min-width: 34px; height: 30px; padding: 0 8px;
|
||||
border-radius: 6px; border: 1px solid #d1d5db;
|
||||
font-size: 12px; cursor: pointer; user-select: none;
|
||||
transition: all 0.15s; background: transparent;
|
||||
}
|
||||
.dark .time-chip { border-color: #374151; }
|
||||
.time-chip:hover { border-color: #6b7280; }
|
||||
.time-chip.selected { background: #000; color: #fff; border-color: #000; }
|
||||
.dark .time-chip.selected { background: #fff; color: #000; border-color: #fff; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.row-animate { animation: none !important; opacity: 1 !important; }
|
||||
}
|
||||
</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">
|
||||
<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>
|
||||
<button onclick="doSearch()"
|
||||
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>
|
||||
|
||||
<!-- Filter Bar -->
|
||||
<div class="glass rounded-2xl p-4 mb-4 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 lg:grid-cols-5 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_xqh_id" class="filter-select 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_lh" class="filter-select 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_cdlb_id" class="filter-select 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_cdejlb_id" class="filter-select 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>
|
||||
<input id="filter_qszws" type="number" min="0" placeholder="不限"
|
||||
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">
|
||||
</div>
|
||||
<div class="w-full">
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">座位 ≤</label>
|
||||
<input id="filter_jszws" type="number" min="0" placeholder="不限"
|
||||
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">
|
||||
</div>
|
||||
<div class="w-full">
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">教室名称</label>
|
||||
<input id="filter_cdmc" type="text" placeholder="模糊搜索"
|
||||
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">
|
||||
</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>
|
||||
|
||||
<!-- jyfs 模式选择 -->
|
||||
<div class="glass rounded-2xl p-4 mb-4 list-item-enter" style="animation-delay: 80ms;">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-xs font-medium text-gray-500 dark:text-gray-400 mr-2">查询模式</span>
|
||||
<div class="flex rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden">
|
||||
<label class="jyfs-radio px-4 py-1.5 text-sm cursor-pointer border-r border-gray-200 dark:border-gray-700 bg-black dark:bg-white text-white dark:text-black" data-jyfs="0">
|
||||
<input type="radio" name="jyfs" value="0" class="hidden"> 按周次
|
||||
</label>
|
||||
<label class="jyfs-radio px-4 py-1.5 text-sm cursor-pointer border-r border-gray-200 dark:border-gray-700" data-jyfs="1">
|
||||
<input type="radio" name="jyfs" value="1" class="hidden" checked> 连续
|
||||
</label>
|
||||
<label class="jyfs-radio px-4 py-1.5 text-sm cursor-pointer" data-jyfs="2">
|
||||
<input type="radio" name="jyfs" value="2" class="hidden"> 按节次
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 时间选择器区域 -->
|
||||
<div id="timeSelectors" class="hidden">
|
||||
<!-- jyfs=0: 周次 + 星期 + 节次 -->
|
||||
<div id="timeSection_0" class="hidden">
|
||||
<div class="glass rounded-2xl p-4 mb-4">
|
||||
<div class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">周次</div>
|
||||
<div class="flex gap-1 flex-wrap mb-1">
|
||||
<button class="week-select-all text-xs text-blue-500 hover:text-blue-600 px-2 py-0.5" data-select="all">全选</button>
|
||||
<button class="week-select-all text-xs text-gray-400 hover:text-gray-500 px-2 py-0.5" data-select="none">清空</button>
|
||||
</div>
|
||||
<div id="weekCheckboxes" class="flex flex-wrap gap-1.5"></div>
|
||||
</div>
|
||||
<div class="glass rounded-2xl p-4 mb-4">
|
||||
<div class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">星期</div>
|
||||
<div class="flex gap-1 flex-wrap mb-1">
|
||||
<button class="day-select-all text-xs text-blue-500 hover:text-blue-600 px-2 py-0.5" data-select="all">全选</button>
|
||||
<button class="day-select-all text-xs text-gray-400 hover:text-gray-500 px-2 py-0.5" data-select="none">清空</button>
|
||||
</div>
|
||||
<div id="dayCheckboxes" class="flex flex-wrap gap-1.5"></div>
|
||||
</div>
|
||||
<div class="glass rounded-2xl p-4 mb-4">
|
||||
<div class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">节次</div>
|
||||
<div class="flex gap-1 flex-wrap mb-1">
|
||||
<button class="period-select-all text-xs text-blue-500 hover:text-blue-600 px-2 py-0.5" data-select="all">全选</button>
|
||||
<button class="period-select-all text-xs text-gray-400 hover:text-gray-500 px-2 py-0.5" data-select="none">清空</button>
|
||||
</div>
|
||||
<div id="periodCheckboxes_0" class="flex flex-wrap gap-1.5"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- jyfs=2: 仅节次 -->
|
||||
<div id="timeSection_2" class="hidden">
|
||||
<div class="glass rounded-2xl p-4 mb-4">
|
||||
<div class="text-xs font-medium text-gray-500 dark:text-gray-400 mb-2">节次</div>
|
||||
<div class="flex gap-1 flex-wrap mb-1">
|
||||
<button class="period-select-all2 text-xs text-blue-500 hover:text-blue-600 px-2 py-0.5" data-select="all">全选</button>
|
||||
<button class="period-select-all2 text-xs text-gray-400 hover:text-gray-500 px-2 py-0.5" data-select="none">清空</button>
|
||||
</div>
|
||||
<div id="periodCheckboxes_2" class="flex flex-wrap gap-1.5"></div>
|
||||
</div>
|
||||
</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="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="buildingChart" class="h-72"></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>
|
||||
|
||||
<!-- Data Container -->
|
||||
<div id="dataContainer" class="hidden list-item-enter" style="animation-delay: 150ms;">
|
||||
<div class="glass rounded-2xl overflow-hidden">
|
||||
<div id="resultSummary" class="px-5 py-3 text-sm text-gray-500 dark:text-gray-400 border-b border-gray-200 dark:border-gray-700 hidden"></div>
|
||||
<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-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-left py-3 px-4 font-semibold text-gray-700 dark:text-gray-300">学院</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tableBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<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>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
|
||||
<script>
|
||||
let paramsReady = false;
|
||||
let defaultXnm = '', defaultXqm = '', defaultXqhId = '1';
|
||||
let buildingChart = 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; }
|
||||
}
|
||||
|
||||
// ── jyfs mode management ──
|
||||
let currentJyfs = '1'; // 默认连续
|
||||
let periodData = null; // 节次数据缓存
|
||||
|
||||
function setJyfs(mode) {
|
||||
currentJyfs = mode;
|
||||
// 更新 radio 样式
|
||||
document.querySelectorAll('.jyfs-radio').forEach(el => {
|
||||
el.classList.toggle('active', el.dataset.jyfs === mode);
|
||||
const inp = el.querySelector('input');
|
||||
if (inp) inp.checked = (el.dataset.jyfs === mode);
|
||||
});
|
||||
// 显示/隐藏时间选择器
|
||||
const ts = document.getElementById('timeSelectors');
|
||||
document.querySelectorAll('[id^="timeSection_"]').forEach(s => s.classList.add('hidden'));
|
||||
if (mode === '0') {
|
||||
ts.classList.remove('hidden');
|
||||
document.getElementById('timeSection_0').classList.remove('hidden');
|
||||
} else if (mode === '2') {
|
||||
ts.classList.remove('hidden');
|
||||
document.getElementById('timeSection_2').classList.remove('hidden');
|
||||
} else {
|
||||
ts.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// ── 节次/周次 chip 渲染 ──
|
||||
function renderPeriodChips(periods, containerId, defaultSelected) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return;
|
||||
// 按时段分组
|
||||
let html = '';
|
||||
let lastRsd = '';
|
||||
periods.forEach(p => {
|
||||
const jcmc = p.JCMC; // 1-11
|
||||
const sjd = p.SJD;
|
||||
const rsd = p.RSDMC; // 上午/下午/晚上
|
||||
if (rsd !== lastRsd) {
|
||||
if (lastRsd) html += '<div class="w-full h-0"></div>'; // break line
|
||||
html += `<span class="text-[10px] text-gray-400 dark:text-gray-500 mr-1 self-center">${rsd}</span>`;
|
||||
lastRsd = rsd;
|
||||
}
|
||||
const sel = defaultSelected ? ' selected' : '';
|
||||
html += `<span class="time-chip${sel}" data-value="${jcmc}" data-label="${jcmc}节 ${sjd}" title="${jcmc}节 ${sjd}">${jcmc}</span>`;
|
||||
});
|
||||
container.innerHTML = html;
|
||||
// 绑定点击
|
||||
container.querySelectorAll('.time-chip').forEach(chip => {
|
||||
chip.addEventListener('click', () => chip.classList.toggle('selected'));
|
||||
});
|
||||
}
|
||||
|
||||
function renderWeekChips(weeks, containerId, defaultSelected) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return;
|
||||
container.innerHTML = weeks.map(w => {
|
||||
const n = w.dxqzc;
|
||||
const sel = defaultSelected ? ' selected' : '';
|
||||
return `<span class="time-chip${sel}" data-value="${n}" title="第${n}周">${n}</span>`;
|
||||
}).join('');
|
||||
container.querySelectorAll('.time-chip').forEach(chip => {
|
||||
chip.addEventListener('click', () => chip.classList.toggle('selected'));
|
||||
});
|
||||
}
|
||||
|
||||
function renderDayChips(containerId, defaultSelected) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return;
|
||||
const days = [
|
||||
{v: 1, l: '一'}, {v: 2, l: '二'}, {v: 3, l: '三'},
|
||||
{v: 4, l: '四'}, {v: 5, l: '五'}, {v: 6, l: '六'}, {v: 7, l: '日'}
|
||||
];
|
||||
const defSet = defaultSelected ? new Set([1,2,3,4,5]) : new Set();
|
||||
container.innerHTML = days.map(d => {
|
||||
const sel = defSet.has(d.v) ? ' selected' : '';
|
||||
return `<span class="time-chip${sel}" data-value="${d.v}" title="星期${d.l}">${d.l}</span>`;
|
||||
}).join('');
|
||||
container.querySelectorAll('.time-chip').forEach(chip => {
|
||||
chip.addEventListener('click', () => chip.classList.toggle('selected'));
|
||||
});
|
||||
}
|
||||
|
||||
// ── 位掩码计算 ──
|
||||
function calcBitmask(containerId) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return '';
|
||||
let mask = 0;
|
||||
container.querySelectorAll('.time-chip.selected').forEach(chip => {
|
||||
mask += Math.pow(2, parseInt(chip.dataset.value) - 1);
|
||||
});
|
||||
return mask > 0 ? String(mask) : '';
|
||||
}
|
||||
|
||||
function calcCommaList(containerId) {
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return '';
|
||||
const vals = [];
|
||||
container.querySelectorAll('.time-chip.selected').forEach(chip => {
|
||||
vals.push(chip.dataset.value);
|
||||
});
|
||||
return vals.join(',');
|
||||
}
|
||||
|
||||
// ── Init: load dropdowns from教务 page ──
|
||||
async function loadParams() {
|
||||
try {
|
||||
const res = await fetch('/api/jwxt/classroom/params');
|
||||
const data = await res.json();
|
||||
if (!data.success || !data.selects) {
|
||||
throw new Error(data.message || '获取下拉框参数失败');
|
||||
}
|
||||
fillSelect('filter_xqh_id', data.selects.xqh_id, true);
|
||||
fillSelect('filter_lh', data.selects.lh, true);
|
||||
fillSelect('filter_cdlb_id', data.selects.cdlb_id, true);
|
||||
fillSelect('filter_cdejlb_id', data.selects.cdejlb_id, true);
|
||||
defaultXnm = data.default_xnm || '';
|
||||
defaultXqm = data.default_xqm || '';
|
||||
// 获取默认校区ID用于节次查询
|
||||
const xqhSel = data.selects.xqh_id;
|
||||
if (xqhSel && xqhSel.default) defaultXqhId = xqhSel.default;
|
||||
|
||||
// 并行加载周次和节次数据
|
||||
await Promise.all([loadWeekData(), loadPeriodData()]);
|
||||
paramsReady = true;
|
||||
document.getElementById('searchBtn').disabled = false;
|
||||
doSearch();
|
||||
} catch (e) {
|
||||
document.getElementById('errorText').textContent = '加载参数失败: ' + e.message;
|
||||
document.getElementById('errorMessage').classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadWeekData() {
|
||||
try {
|
||||
const res = await fetch(`/api/jwxt/classroom-filter-options?xnm=${defaultXnm}&xqm=${defaultXqm}`);
|
||||
const data = await res.json();
|
||||
if (data.success && data.items && data.items.nxqzcList) {
|
||||
const weeks = data.items.nxqzcList;
|
||||
const dqzcxq = data.items.dqzcxq || {};
|
||||
const dqzc = parseInt(dqzcxq.DQZC) || 1;
|
||||
// 默认选中当前周
|
||||
const isDefault = true;
|
||||
renderWeekChips(weeks, 'weekCheckboxes', isDefault);
|
||||
// 全选/清空按钮
|
||||
bindSelectAll('weekCheckboxes', '.week-select-all');
|
||||
}
|
||||
} catch (e) { console.warn('加载周次数据失败:', e); }
|
||||
}
|
||||
|
||||
async function loadPeriodData() {
|
||||
try {
|
||||
const res = await fetch(`/api/jwxt/classroom-periods?xnm=${defaultXnm}&xqm=${defaultXqm}&xqh_id=${defaultXqhId}`);
|
||||
const data = await res.json();
|
||||
if (data.success && data.jcList) {
|
||||
periodData = data.jcList;
|
||||
renderPeriodChips(periodData, 'periodCheckboxes_0', true);
|
||||
renderPeriodChips(periodData, 'periodCheckboxes_2', true);
|
||||
bindSelectAll('periodCheckboxes_0', '.period-select-all');
|
||||
bindSelectAll('periodCheckboxes_2', '.period-select-all2');
|
||||
renderDayChips('dayCheckboxes', true);
|
||||
bindSelectAll('dayCheckboxes', '.day-select-all');
|
||||
}
|
||||
} catch (e) { console.warn('加载节次数据失败:', e); }
|
||||
}
|
||||
|
||||
function bindSelectAll(containerId, btnSelector) {
|
||||
document.querySelectorAll(btnSelector).forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
const action = btn.dataset.select;
|
||||
const container = document.getElementById(containerId);
|
||||
if (!container) return;
|
||||
container.querySelectorAll('.time-chip').forEach(chip => {
|
||||
if (action === 'all') chip.classList.add('selected');
|
||||
else chip.classList.remove('selected');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function fillSelect(id, selectData, addAll) {
|
||||
const el = document.getElementById(id);
|
||||
if (!selectData || !selectData.options || !selectData.options.length) {
|
||||
el.innerHTML = '<option value="">--</option>';
|
||||
return;
|
||||
}
|
||||
const defaultVal = selectData.default || '';
|
||||
let html = '';
|
||||
if (addAll) html += '<option value="">全部</option>';
|
||||
html += selectData.options.map(o =>
|
||||
`<option value="${escAttr(o.value)}" ${o.value === defaultVal ? 'selected' : ''}>${escHtml(o.label)}</option>`
|
||||
).join('');
|
||||
el.innerHTML = html;
|
||||
}
|
||||
|
||||
// ── jyfs radio event binding ──
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('.jyfs-radio').forEach(el => {
|
||||
el.addEventListener('click', () => setJyfs(el.dataset.jyfs));
|
||||
});
|
||||
// init with default mode
|
||||
setJyfs('1');
|
||||
});
|
||||
|
||||
// ── Search ──
|
||||
async function doSearch() {
|
||||
if (!paramsReady) return;
|
||||
showLoading();
|
||||
|
||||
const params = new URLSearchParams();
|
||||
if (defaultXnm) params.append('xnm', defaultXnm);
|
||||
if (defaultXqm) params.append('xqm', defaultXqm);
|
||||
params.append('page_size', '200');
|
||||
params.append('jyfs', currentJyfs);
|
||||
|
||||
// Append filter values (only non-empty)
|
||||
['xqh_id','lh','cdlb_id','cdejlb_id','qszws','jszws','cdmc'].forEach(name => {
|
||||
const val = document.getElementById('filter_' + name).value.trim();
|
||||
if (val) params.append(name, val);
|
||||
});
|
||||
|
||||
// Time selectors based on jyfs mode
|
||||
if (currentJyfs === '0') {
|
||||
// 按周次: zcd(bitmask) + xqj(comma) + jcd(bitmask)
|
||||
const zcd = calcBitmask('weekCheckboxes');
|
||||
const xqj = calcCommaList('dayCheckboxes');
|
||||
const jcd = calcBitmask('periodCheckboxes_0');
|
||||
if (zcd) params.append('zcd', zcd);
|
||||
if (xqj) params.append('xqj', xqj);
|
||||
if (jcd) params.append('jcd', jcd);
|
||||
} else if (currentJyfs === '2') {
|
||||
// 按节次: jcd(bitmask)
|
||||
const jcd = calcBitmask('periodCheckboxes_2');
|
||||
if (jcd) params.append('jcd', jcd);
|
||||
}
|
||||
// jyfs=1 (连续): 不需要额外时间参数
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/jwxt/classrooms?' + params.toString());
|
||||
const data = await res.json();
|
||||
hideLoading();
|
||||
|
||||
if (!data.success) {
|
||||
showError(data.message || '查询失败');
|
||||
return;
|
||||
}
|
||||
|
||||
const items = data.items || [];
|
||||
if (!items.length) {
|
||||
showEmpty('暂无符合条件的空闲教室');
|
||||
return;
|
||||
}
|
||||
|
||||
renderTable(items);
|
||||
} catch (e) {
|
||||
hideLoading();
|
||||
showError('网络错误: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Render ──
|
||||
function renderTable(items) {
|
||||
const summary = document.getElementById('resultSummary');
|
||||
summary.textContent = `共 ${items.length} 间教室`;
|
||||
summary.classList.remove('hidden');
|
||||
|
||||
const tbody = document.getElementById('tableBody');
|
||||
tbody.innerHTML = items.map((item, idx) => {
|
||||
const xqmc = item.xqmc || item.xqhmc || item.XQHMC || '--';
|
||||
const jxlmc = item.jxlmc || item.JXLMC || '--';
|
||||
const cdmc = item.cdmc || item.CDMC || '--';
|
||||
const cdbh = item.cdbh || '--';
|
||||
const cdlbmc = item.cdlbmc || item.CDLBMC || '--';
|
||||
const zws = item.zws || item.kszws1 || item.ZWS || '--';
|
||||
const lch = item.lch || '--';
|
||||
const jgmc = item.jgmc || item.JGMC || '--';
|
||||
|
||||
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 * 30}ms;">
|
||||
<td class="py-3 px-4 text-gray-400 dark:text-gray-500">${idx + 1}</td>
|
||||
<td class="py-3 px-4">${escHtml(xqmc)}</td>
|
||||
<td class="py-3 px-4">${escHtml(jxlmc)}</td>
|
||||
<td class="py-3 px-4 font-medium">${escHtml(cdmc)}</td>
|
||||
<td class="py-3 px-4 text-gray-500 text-xs">${escHtml(cdbh)}</td>
|
||||
<td class="py-3 px-4 text-gray-500">${escHtml(cdlbmc)}</td>
|
||||
<td class="py-3 px-4 text-center">${escHtml(zws)}</td>
|
||||
<td class="py-3 px-4 text-gray-400 dark:text-gray-500 text-xs">${escHtml(lch)}</td>
|
||||
<td class="py-3 px-4 text-gray-500 text-xs">${escHtml(jgmc)}</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
document.getElementById('dataContainer').classList.remove('hidden');
|
||||
document.getElementById('emptyState').classList.add('hidden');
|
||||
|
||||
// 渲染图表
|
||||
const chartsRow = document.getElementById('chartsRow');
|
||||
chartsRow.classList.remove('hidden');
|
||||
renderBuildingChart(items);
|
||||
setupDarkObserver(items);
|
||||
}
|
||||
|
||||
// ── Helpers ──
|
||||
function showLoading() {
|
||||
document.getElementById('loadingIndicator').classList.remove('hidden');
|
||||
document.getElementById('errorMessage').classList.add('hidden');
|
||||
document.getElementById('dataContainer').classList.add('hidden');
|
||||
document.getElementById('emptyState').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.add('hidden');
|
||||
document.getElementById('emptyState').classList.remove('hidden');
|
||||
document.getElementById('emptyState').querySelector('p').textContent = msg;
|
||||
}
|
||||
// ── 各楼栋空闲教室数量柱状图 ──
|
||||
function renderBuildingChart(items) {
|
||||
const container = document.getElementById('buildingChart');
|
||||
if (!container) return;
|
||||
if (!buildingChart) buildingChart = echarts.init(container);
|
||||
|
||||
const buildingCount = {};
|
||||
items.forEach(item => {
|
||||
const building = item.jxlmc || item.JXLMC || '未知';
|
||||
buildingCount[building] = (buildingCount[building] || 0) + 1;
|
||||
});
|
||||
const entries = Object.entries(buildingCount).sort((a, b) => b[1] - a[1]);
|
||||
const dark = isDarkMode();
|
||||
|
||||
buildingChart.setOption({
|
||||
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
|
||||
grid: { left: '3%', right: '4%', bottom: '3%', top: '5%', containLabel: true },
|
||||
xAxis: { type: 'value', name: '间数', minInterval: 1, nameTextStyle: { fontSize: 11 } },
|
||||
yAxis: { type: 'category', data: entries.map(e => e[0]), axisLabel: { fontSize: 11 }, inverse: true },
|
||||
series: [{
|
||||
type: 'bar', data: entries.map(e => e[1]),
|
||||
itemStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
|
||||
{ offset: 0, color: dark ? '#a78bfa' : '#8b5cf6' },
|
||||
{ offset: 1, color: dark ? '#60a5fa' : '#3b82f6' }
|
||||
])
|
||||
},
|
||||
barMaxWidth: 28,
|
||||
label: { show: true, position: 'right', fontSize: 11, color: dark ? '#9ca3af' : '#6b7280' }
|
||||
}]
|
||||
}, true);
|
||||
}
|
||||
|
||||
// ── 深色模式观察者 ──
|
||||
let _darkObserver = null;
|
||||
let _lastClassroomItems = null;
|
||||
function setupDarkObserver(items) {
|
||||
_lastClassroomItems = items;
|
||||
if (_darkObserver) return;
|
||||
_darkObserver = new MutationObserver(() => {
|
||||
if (_lastClassroomItems && _lastClassroomItems.length > 0) {
|
||||
renderBuildingChart(_lastClassroomItems);
|
||||
}
|
||||
});
|
||||
_darkObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
||||
}
|
||||
|
||||
window.addEventListener('resize', () => { buildingChart?.resize(); });
|
||||
|
||||
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, '<').replace(/>/g, '>');
|
||||
}
|
||||
|
||||
// ── Start ──
|
||||
initSession().then(sessionOk => {
|
||||
if (!sessionOk) {
|
||||
showError('教务系统 Session 已失效,请尝试<a href="/dashboard">重新配置教务账号</a>');
|
||||
return;
|
||||
}
|
||||
loadParams();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user