改进课表校对为缩小原图和半透明按钮浮层
This commit is contained in:
Vendored
+51
-19
@@ -1253,18 +1253,22 @@
|
||||
const cells = item.structure.cells;
|
||||
const slots = timetableData.slots, days = timetableData.days;
|
||||
const statusLabels = { unknown: '待确认', busy: '有课', free: '无课' };
|
||||
const counts = {busy:0, free:0, unknown:0}; cells.forEach(cell => counts[cell.status]++);
|
||||
const recognitionSummary = `${counts.busy}个有课时段 · ${counts.free}个无课时段${counts.unknown ? ' · ' + counts.unknown + '个待确认' : ''}`;
|
||||
modal(`<h3>${weekLabel(item.week_type)}课表 · ${editable ? '核对与修改' : '查看'}</h3><p class="modal-sub muted">只记录周一至周五四个值班时段的有课/无课状态。请对照原图核对后确认。</p>
|
||||
<div class="timetable-source"><img id="timetable-source-image" alt="课表原图" /><p class="muted" id="timetable-image-status">正在加载原图…</p></div>
|
||||
<p class="muted">${recognitionSummary}</p><div class="timetable-warnings">${item.structure.warnings.map(esc).join('<br />')}</div>
|
||||
<form id="timetable-correction-form"><div class="timetable-grid-wrap"><table class="timetable-grid"><thead><tr><th scope="col">值班时段</th>${days.map(day => `<th scope="col">${esc(day)}</th>`).join('')}</tr></thead><tbody>${slots.map(slot => `<tr><th scope="row">${esc(slot.label)}<br />${slot.start}–${slot.end}</th>${days.map((_, i) => {
|
||||
const index = cells.findIndex(cell => cell.day === i+1 && cell.slot === slot.id), cell = cells[index];
|
||||
return `<td data-status="${cell.status}">${editable ? `<select aria-label="${days[i]}${slot.label}状态" data-cell="${index}">${Object.entries(statusLabels).map(([value,label]) => `<option value="${value}" ${cell.status === value ? 'selected' : ''}>${label}</option>`).join('')}</select>` : `<strong>${statusLabels[cell.status]}</strong>`}</td>`;
|
||||
}).join('')}</tr>`).join('')}</tbody></table></div>
|
||||
${editable ? '<button class="btn sm" type="button" id="timetable-fill-free">将其余待确认设为无课</button>' : ''}
|
||||
<div class="form-error" role="alert"></div><p class="muted" id="timetable-confirmation-state">${item.confirmed_at ? '已核对,确认时间:' + fmtDate(item.confirmed_at) : '尚未核对,暂不能作为可值班依据。'}</p>
|
||||
<div class="form-actions"><button class="btn" type="button" id="timetable-download-image">下载原图</button><button class="btn" type="button" id="timetable-editor-close">关闭</button>${editable ? '<button class="btn" type="submit" data-confirm="false">保存草稿</button><button class="btn primary" type="submit" data-confirm="true">核对无误并确认</button>' : ''}</div></form>`);
|
||||
modal(`<h3>${weekLabel(item.week_type)}课表 · ${editable ? '核对与修改' : '查看'}</h3><p class="modal-sub muted">${editable ? '点击“校对课表”打开半透明校对层,再点时段按钮切换有课/无课。' : '点击“查看时段”对照原图查看有课/无课状态。'}</p>
|
||||
<div class="timetable-review-toolbar"><button class="btn primary" type="button" id="timetable-review-toggle" aria-expanded="false" aria-controls="timetable-review-panel">${editable ? '校对课表' : '查看时段'}</button><button class="btn" type="button" id="timetable-image-zoom" aria-pressed="false">放大原图</button><span class="muted" id="timetable-recognition-summary" role="status"></span></div>
|
||||
<div class="timetable-review-stage" id="timetable-review-stage">
|
||||
<div class="timetable-source"><img id="timetable-source-image" alt="课表原图" /><p class="muted" id="timetable-image-status">正在加载原图…</p></div>
|
||||
<form id="timetable-correction-form" class="timetable-review-panel" hidden><div id="timetable-review-panel">
|
||||
<div class="timetable-grid-wrap"><table class="timetable-grid"><thead><tr><th scope="col">值班时段</th>${days.map(day => `<th scope="col">${esc(day)}</th>`).join('')}</tr></thead><tbody>${slots.map(slot => `<tr><th scope="row">${esc(slot.label)}<small>${slot.start}<br />${slot.end}</small></th>${days.map((_, i) => {
|
||||
const index = cells.findIndex(cell => cell.day === i+1 && cell.slot === slot.id), cell = cells[index];
|
||||
return `<td data-status="${cell.status}"><button type="button" class="timetable-status-button" aria-label="${days[i]}${slot.label}:${statusLabels[cell.status]}" aria-pressed="${cell.status === 'unknown' ? 'mixed' : cell.status === 'busy'}" data-cell="${index}" data-value="${cell.status}" ${editable ? '' : 'disabled'}>${statusLabels[cell.status]}</button></td>`;
|
||||
}).join('')}</tr>`).join('')}</tbody></table></div>
|
||||
${editable ? '<button class="btn sm" type="button" id="timetable-fill-free">将其余待确认设为无课</button>' : ''}
|
||||
<div class="form-error" role="alert"></div><p class="muted" id="timetable-confirmation-state">${item.confirmed_at ? '已核对,确认时间:' + fmtDate(item.confirmed_at) : '对照背景课表,核对后再确认。'}</p>
|
||||
${editable ? '<div class="form-actions"><button class="btn" type="submit" data-confirm="false">保存草稿</button><button class="btn primary" type="submit" data-confirm="true">核对无误并确认</button></div>' : ''}
|
||||
</div></form>
|
||||
</div>
|
||||
<details class="timetable-recognition-notes"><summary>识别说明</summary><p class="muted">${item.structure.warnings.map(esc).join('<br />')}</p></details>
|
||||
<div class="form-actions"><button class="btn" type="button" id="timetable-download-image">下载原图</button><button class="btn" type="button" id="timetable-editor-close">关闭</button></div>`);
|
||||
$('#modal-root .modal').classList.add('timetable-editor');
|
||||
const form = $('#timetable-correction-form'), img = $('#timetable-source-image'), imageStatus = $('#timetable-image-status');
|
||||
$('#timetable-editor-close').addEventListener('click', closeModal);
|
||||
@@ -1279,28 +1283,56 @@
|
||||
fetch(item.image_url, { headers: { Authorization: `Bearer ${getToken()}` } }).then(async response => {
|
||||
if (!response.ok) throw new Error('原图暂不可用,请关闭后重新打开');
|
||||
const blob = await response.blob(); if (!img.isConnected) return;
|
||||
imageUrl = URL.createObjectURL(blob); img.src = imageUrl; imageStatus.textContent = '';
|
||||
imageUrl = URL.createObjectURL(blob); img.src = imageUrl; imageStatus.textContent = ''; imageStatus.classList.add('hidden');
|
||||
}).catch(error => { imageStatus.textContent = error.message; });
|
||||
const stage = $('#timetable-review-stage'), reviewButton = $('#timetable-review-toggle');
|
||||
reviewButton.addEventListener('click', () => {
|
||||
const open = form.hidden;
|
||||
form.hidden = !open; stage.classList.toggle('is-reviewing', open);
|
||||
reviewButton.setAttribute('aria-expanded', String(open));
|
||||
reviewButton.textContent = open ? (editable ? '收起校对' : '收起时段') : (editable ? '校对课表' : '查看时段');
|
||||
});
|
||||
$('#timetable-image-zoom').addEventListener('click', event => {
|
||||
const expanded = stage.classList.toggle('is-expanded');
|
||||
event.currentTarget.setAttribute('aria-pressed', String(expanded));
|
||||
event.currentTarget.textContent = expanded ? '缩小原图' : '放大原图';
|
||||
});
|
||||
const updateSummary = () => {
|
||||
const counts = {busy:0, free:0, unknown:0};
|
||||
form.querySelectorAll('[data-cell]').forEach(button => counts[button.dataset.value]++);
|
||||
$('#timetable-recognition-summary').textContent = `${counts.busy}个有课 · ${counts.free}个无课${counts.unknown ? ' · ' + counts.unknown + '个待确认' : ''}`;
|
||||
if (editable) $('#timetable-fill-free').classList.toggle('hidden', counts.unknown === 0);
|
||||
};
|
||||
updateSummary();
|
||||
if (!editable) return;
|
||||
form.querySelectorAll('[data-cell]').forEach(select => select.addEventListener('change', () => {
|
||||
select.closest('td').dataset.status = select.value;
|
||||
const setCellStatus = (button, status) => {
|
||||
button.dataset.value = status; button.textContent = statusLabels[status];
|
||||
button.closest('td').dataset.status = status;
|
||||
form.querySelector('.form-error').textContent = '';
|
||||
const cell = cells[Number(button.dataset.cell)], slot = slots.find(slot => slot.id === cell.slot);
|
||||
button.setAttribute('aria-label', `${days[cell.day-1]}${slot.label}:${statusLabels[status]}`);
|
||||
button.setAttribute('aria-pressed', String(status === 'busy'));
|
||||
form.querySelector('#timetable-confirmation-state').textContent = '有未保存修改,请重新保存并确认。';
|
||||
updateSummary();
|
||||
};
|
||||
form.querySelectorAll('[data-cell]').forEach(button => button.addEventListener('click', () => {
|
||||
setCellStatus(button, button.dataset.value === 'busy' ? 'free' : 'busy');
|
||||
}));
|
||||
$('#timetable-fill-free').addEventListener('click', () => {
|
||||
form.querySelectorAll('[data-cell]').forEach(select => { if (select.value === 'unknown') { select.value = 'free'; select.dispatchEvent(new Event('change')); } });
|
||||
form.querySelectorAll('[data-cell]').forEach(button => { if (button.dataset.value === 'unknown') setCellStatus(button, 'free'); });
|
||||
});
|
||||
let saving = false;
|
||||
form.addEventListener('submit', async event => {
|
||||
event.preventDefault(); if (saving) return;
|
||||
const confirm = event.submitter?.dataset.confirm === 'true';
|
||||
const edited = cells.map((cell,index) => ({ day: cell.day, slot: cell.slot, status: form.querySelector(`[data-cell="${index}"]`).value, courses: '' }));
|
||||
const edited = cells.map((cell,index) => ({ day: cell.day, slot: cell.slot, status: form.querySelector(`[data-cell="${index}"]`).dataset.value, courses: '' }));
|
||||
const errorBox = form.querySelector('.form-error'); errorBox.textContent = '';
|
||||
if (confirm && edited.some(cell => cell.status === 'unknown')) { errorBox.textContent = '仍有待确认时段,请核对后再确认'; return; }
|
||||
saving = true; form.querySelectorAll('[type=submit]').forEach(button => button.disabled = true);
|
||||
saving = true; form.querySelectorAll('button').forEach(button => button.disabled = true);
|
||||
try {
|
||||
await api('/timetables/me/' + item.week_type, { method: 'PATCH', body: { revision: item.revision, cells: edited, confirm } });
|
||||
closeModal(); toast(confirm ? '课表已核对确认' : '草稿已保存'); loadTimetables();
|
||||
} catch (error) { errorBox.textContent = error.message; saving = false; form.querySelectorAll('[type=submit]').forEach(button => button.disabled = false); }
|
||||
} catch (error) { errorBox.textContent = error.message; saving = false; form.querySelectorAll('button').forEach(button => button.disabled = false); }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user