新增赋能中心一楼设备教程:上传、搜索与在线播放

This commit is contained in:
2026-11-23 11:13:58 +08:00
parent ad6ab63c8e
commit 533c401175
7 changed files with 446 additions and 8 deletions
+11
View File
@@ -718,4 +718,15 @@ button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px s
.center-history { margin-top:28px; }
.center-history summary { cursor:pointer; padding:12px 0; }
.center-history .acard { margin-top:12px; }
/* ---------- 设备使用教程 ---------- */
.tutorial-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(280px,1fr)); gap:16px; align-items:start; }
.tutorial-card { display:flex; flex-direction:column; gap:10px; padding:14px; background:var(--card); border:1px solid var(--line); border-radius:var(--radius); box-shadow:var(--shadow); }
.tutorial-head { display:flex; align-items:center; gap:8px; flex-wrap:wrap; min-width:0; }
.tutorial-head b { font-size:15px; font-weight:600; overflow-wrap:anywhere; }
.tutorial-head .tag { max-width:100%; overflow-wrap:anywhere; white-space:normal; }
.tutorial-video { display:block; width:100%; aspect-ratio:16/9; background:#101613; border-radius:10px; }
.tutorial-note { margin:0; font-size:13px; line-height:1.65; white-space:pre-wrap; overflow-wrap:anywhere; }
.tutorial-meta { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; margin-top:auto; }
.tutorial-meta .muted { min-width:0; overflow-wrap:anywhere; }
@media (max-width:760px) { .tutorial-grid { grid-template-columns:1fr; } }
@media (min-width:761px) and (max-width:1000px) { .topbar-inner { flex-wrap:wrap; } #nav { order:3; flex-basis:100%; } }
+12 -4
View File
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WorkLog · 活动记录</title>
<meta name="theme-color" content="#f5f7f5" />
<link rel="stylesheet" href="/assets/styles.css?v=28" />
<link rel="stylesheet" href="/assets/styles.css?v=29" />
</head>
<body>
<div id="app">
@@ -132,7 +132,7 @@
</div>
<section class="center-shortcuts" aria-label="赋能中心一楼快捷入口">
<div><strong>赋能中心一楼</strong><p>上传活动照片,完成每日清点,申请物品借用</p></div>
<div class="center-shortcut-actions"><a class="btn primary" href="#center-records">一楼活动记录</a><a class="btn" href="#center-duty">一楼值班</a><a class="btn" href="#center-assets">物品清点与借出</a><a class="btn" href="#timetables">课表收取</a></div>
<div class="center-shortcut-actions"><a class="btn primary" href="#center-records">一楼活动记录</a><a class="btn" href="#center-tutorials">设备教程</a><a class="btn" href="#center-duty">一楼值班</a><a class="btn" href="#center-assets">物品清点与借出</a><a class="btn" href="#timetables">课表收取</a></div>
</section>
<div class="filters">
<input id="feed-q" aria-label="搜索活动或地点" placeholder="搜索活动 / 地点" type="search" />
@@ -175,11 +175,19 @@
<p class="muted" id="center-export-status" role="status"></p>
<p class="muted">程序读取:GET /api/center/data;字段说明:GET /api/center/schema。均需使用本人登录令牌。</p>
</details>
<div class="tabs center-tabs"><button class="tab active" data-center-tab="records">活动记录</button><button class="tab" data-center-tab="duty">一楼值班</button><button class="tab" data-center-tab="assets">物品清点与借出</button><button class="tab" data-center-tab="hall">展厅使用登记</button></div>
<div class="tabs center-tabs"><button class="tab active" data-center-tab="records">活动记录</button><button class="tab" data-center-tab="tutorials">设备教程</button><button class="tab" data-center-tab="duty">一楼值班</button><button class="tab" data-center-tab="assets">物品清点与借出</button><button class="tab" data-center-tab="hall">展厅使用登记</button></div>
<section id="center-records">
<div class="filters center-toolbar"><input id="center-q" type="search" aria-label="搜索活动主题" placeholder="搜索活动主题" /><input id="center-from" type="date" aria-label="活动起始日期" /><input id="center-to" type="date" aria-label="活动截止日期" /><button id="center-new" class="btn primary">+ 记录一楼活动</button></div>
<div id="center-record-list" class="card-list"></div>
</section>
<section id="center-tutorials" class="hidden">
<div class="filters center-toolbar"><input id="tutorial-q" type="search" aria-label="搜索教室号、器材名或备注" placeholder="搜索教室号 / 器材名 / 备注" /><button id="tutorial-new" class="btn primary" type="button">+ 上传教程</button></div>
<p class="muted">教程视频仅登录成员可在线播放;原始视频只有上传者可以下载保存,其他人可在线观看。</p>
<div id="tutorial-list" class="tutorial-grid"></div>
<div id="tutorial-empty" class="empty hidden">还没有教程,点「+ 上传教程」添加第一份。</div>
<div class="form-actions"><button id="tutorial-more" class="btn hidden" type="button">加载更多</button></div>
<p class="muted" id="tutorial-status" role="status"></p>
</section>
<section id="center-duty" class="hidden">
<div class="center-duty-head">
<div>
@@ -358,7 +366,7 @@
<div id="toast" class="toast hidden" role="status" aria-live="polite"></div>
<script src="/js/app.js?v=48"></script>
<script src="/js/app.js?v=49"></script>
</div>
</body>
</html>
+178 -2
View File
@@ -1535,10 +1535,11 @@
let centerRecords = [];
function openCenterFromHash() {
if (state.me && location.hash === '#timetables') { show('timetables'); return true; }
if (!state.me || !['#center', '#center-records', '#center-duty', '#center-assets', '#center-hall'].includes(location.hash)) return false;
centerTab = location.hash === '#center-duty' ? 'duty' : location.hash === '#center-assets' ? 'assets' : location.hash === '#center-hall' ? 'hall' : 'records';
if (!state.me || !['#center', '#center-records', '#center-tutorials', '#center-duty', '#center-assets', '#center-hall'].includes(location.hash)) return false;
centerTab = location.hash === '#center-tutorials' ? 'tutorials' : location.hash === '#center-duty' ? 'duty' : location.hash === '#center-assets' ? 'assets' : location.hash === '#center-hall' ? 'hall' : 'records';
$$('[data-center-tab]').forEach(button => button.classList.toggle('active', button.dataset.centerTab === centerTab));
$('#center-records').classList.toggle('hidden', centerTab !== 'records');
$('#center-tutorials').classList.toggle('hidden', centerTab !== 'tutorials');
$('#center-duty').classList.toggle('hidden', centerTab !== 'duty');
$('#center-assets').classList.toggle('hidden', centerTab !== 'assets');
$('#center-hall').classList.toggle('hidden', centerTab !== 'hall');
@@ -1560,6 +1561,8 @@
const data = await api(`/activities?${p}`); centerRecords = data.items;
$('#center-record-list').innerHTML = data.items.map(a => activityCard(a)).join('') || '<div class="empty">暂无匹配的一楼活动,记录工作时请上传照片。</div>';
bindCardEvents($('#center-record-list'));
} else if (centerTab === 'tutorials') {
await loadTutorials();
} else if (centerTab === 'duty') {
await loadCenterDuty();
} else if (centerTab === 'hall') {
@@ -1612,6 +1615,7 @@
history.replaceState(null, '', '#center-' + centerTab);
$$('[data-center-tab]').forEach(b => b.classList.toggle('active', b === button));
$('#center-records').classList.toggle('hidden', centerTab !== 'records');
$('#center-tutorials').classList.toggle('hidden', centerTab !== 'tutorials');
$('#center-duty').classList.toggle('hidden', centerTab !== 'duty');
$('#center-assets').classList.toggle('hidden', centerTab !== 'assets');
$('#center-hall').classList.toggle('hidden', centerTab !== 'hall');
@@ -1634,6 +1638,178 @@
<label>${isDuty ? '值班人及联系方式' : '使用单位联系人及联系方式'}<input name="duty" maxlength="200" value="${esc(current && current !== '—' ? current : '')}" placeholder="例如:张三 13800000000" /></label>`,
async f => { await api('/center/hall-log/duty', { method: 'POST', body: { row, column, value: f.duty.value.trim() } }); toast('已保存并同步到金山文档'); });
});
// ---- 设备使用教程
const TUTORIAL_PAGE = 60;
const tutorialState = { items: [], q: '', hasMore: false, seq: 0 };
let tutorialDebounce = null, tutorialProgressHandler = null;
const fmtBytes = (bytes) => {
if (!bytes) return '';
if (bytes >= 1024 ** 3) return (bytes / 1024 ** 3).toFixed(1) + ' GB';
if (bytes >= 1024 ** 2) return Math.round(bytes / 1024 ** 2) + ' MB';
return Math.max(1, Math.round(bytes / 1024)) + ' KB';
};
function tutorialCard(item, index) {
const canDownload = item.uploader_id === state.me?.id;
const src = `/api/center/tutorials/${encodeURIComponent(item.id)}`;
return `<article class="tutorial-card" data-tutorial="${esc(item.id)}">
<div class="tutorial-head"><b>${esc(item.room)}</b><span class="tag cat">${esc(item.equipment)}</span></div>
<video class="tutorial-video" controls preload="none" playsinline data-index="${index}" data-loaded="0"><source data-index="${index}" /></video>
${item.note ? `<p class="tutorial-note">${esc(item.note)}</p>` : '<p class="tutorial-note muted">暂无备注</p>'}
<div class="tutorial-meta"><span class="muted">${esc(item.uploader)} · ${fmtDate(item.created_at)}${item.video_bytes ? ` · ${fmtBytes(item.video_bytes)}` : ''}</span>${canDownload ? `<button class="btn sm" type="button" data-tutorial-download="${esc(item.id)}">下载原视频</button>` : ''}</div>
</article>`;
}
function paintTutorials() {
const list = $('#tutorial-list');
list.innerHTML = tutorialState.items.map(tutorialCard).join('');
$('#tutorial-empty').classList.toggle('hidden', !!tutorialState.items.length || !!tutorialState.q);
$('#tutorial-more').classList.toggle('hidden', !tutorialState.hasMore);
$('#tutorial-empty').textContent = tutorialState.q ? '没有匹配的教程,换个教室号或器材名试试。' : '还没有教程,点「+ 上传教程」添加第一份。';
}
function playTutorial(index) {
const card = $('#tutorial-list article:nth-child(' + (index + 1) + ')');
const video = card?.querySelector('video');
const item = tutorialState.items[index];
if (!video || !item) return;
const source = video.querySelector('source');
if (video.dataset.loaded === '0') {
const ext = (item.video_file || '').split('.').pop();
source.type = { mp4: 'video/mp4', mov: 'video/quicktime', webm: 'video/webm' }[ext] || 'video/mp4';
source.src = `/api/center/tutorials/${encodeURIComponent(item.id)}`;
video.dataset.loaded = '1';
video.load();
}
video.play().catch(() => {});
}
async function loadTutorials({ fresh = false } = {}) {
const seq = ++tutorialState.seq;
tutorialState.freshMode = fresh;
const p = new URLSearchParams({ limit: TUTORIAL_PAGE });
if (tutorialState.q) p.set('q', tutorialState.q);
const append = !fresh && $('#tutorial-more').dataset.mode === 'append';
$('#tutorial-more').dataset.mode = '';
if (append && tutorialState.items.length) p.set('offset', String(tutorialState.items.length));
$('#tutorial-status').textContent = tutorialState.items.length ? '正在加载更多…' : '正在读取教程…';
try {
const data = await api(`/center/tutorials?${p}`);
if (seq !== tutorialState.seq) return;
tutorialState.items = append ? tutorialState.items.concat(data.items) : data.items;
tutorialState.hasMore = data.has_more;
paintTutorials();
$('#tutorial-status').textContent = tutorialState.q
? `搜索「${tutorialState.q}」共 ${tutorialState.items.length} 条${data.has_more ? '(可加载更多)' : ''}`
: `共 ${tutorialState.items.length} 条教程${data.has_more ? ',还有更多' : ''}`;
} catch (error) {
$('#tutorial-status').textContent = '';
toast(error.message, true);
} finally {
if (seq === tutorialState.seq) tutorialState.freshMode = false;
}
}
function searchTutorials() {
clearTimeout(tutorialDebounce);
tutorialDebounce = setTimeout(() => {
tutorialState.q = $('#tutorial-q').value.trim();
tutorialState.items = [];
loadTutorials({ fresh: true });
}, 250);
}
function openTutorialForm() {
modal(`<h3>上传设备使用教程</h3>
<form id="tutorial-form" novalidate>
<label>教室号 *<input name="room" required maxlength="40" placeholder="例如:赋能中心一楼 A101" /></label>
<label>器材名 *<input name="equipment" required maxlength="100" placeholder="例如:激光切割机、投影仪" /></label>
<label>教程视频 * <span class="hint-inline">(MP4 / MOV / WebM,单个不超过 1GB)</span><input name="video" type="file" accept="video/mp4,video/quicktime,video/webm,.mp4,.mov,.webm" required /></label>
<label>备注 <span class="hint-inline">(选填)</span><textarea name="note" rows="3" maxlength="2000" placeholder="开机步骤、注意事项、常见问题…"></textarea></label>
<div class="upload-progress hidden" id="tutorial-progress"><p id="tutorial-progress-label" role="status" aria-live="polite"></p><progress id="tutorial-meter" max="100" value="0" aria-labelledby="tutorial-progress-label"></progress></div>
<div class="form-error" id="tutorial-error" role="alert"></div>
<div class="form-actions"><button type="button" class="btn" id="tutorial-cancel">取消</button><button type="submit" class="btn primary">上传并保存</button><button type="button" class="btn hidden" id="tutorial-abort">取消上传</button></div>
</form>`);
const form = $('#tutorial-form'), errorBox = $('#tutorial-error');
const box = $('#tutorial-progress'), label = $('#tutorial-progress-label'), meter = $('#tutorial-meter');
const button = form.querySelector('[type=submit]'), abortButton = $('#tutorial-abort');
let submitted = false;
$('#tutorial-cancel').addEventListener('click', () => { if (!submitted || !materialUpload) closeModal(); else abortButton.click(); });
abortButton.addEventListener('click', () => materialUpload?.abort());
form.video.addEventListener('change', () => {
const size = form.video.files[0]?.size || 0;
errorBox.textContent = size > 1024 ** 3 ? '视频超过 1GB,请先压缩再上传' : '';
});
const showProgress = (loaded, total) => {
box.classList.remove('hidden');
const pct = total ? Math.min(100, Math.round((loaded / total) * 100)) : 0;
meter.value = pct;
label.textContent = pct >= 100 ? `视频已上传,正在保存…(${fmtBytes(loaded)})` : `正在上传视频 ${pct}%(${fmtBytes(loaded)} / ${fmtBytes(total)})`;
};
tutorialProgressHandler = showProgress;
form.addEventListener('submit', async event => {
event.preventDefault();
if (button.disabled) return;
errorBox.textContent = '';
if (!form.reportValidity()) return;
const room = form.room.value.trim(), equipment = form.equipment.value.trim();
const file = form.video.files[0], note = form.note.value.trim();
if (!file) { errorBox.textContent = '请选择教程视频'; return; }
if (file.size > 1024 ** 3) { errorBox.textContent = '视频超过 1GB,请先压缩再上传'; return; }
submitted = true;
button.disabled = true; form.room.disabled = form.equipment.disabled = form.video.disabled = form.note.disabled = true;
abortButton.classList.remove('hidden');
button.textContent = '正在上传…';
const params = new URLSearchParams({ room, equipment, note });
const ext = (file.name.split('.').pop() || '').toLowerCase();
const type = file.type || ({ mp4: 'video/mp4', mov: 'video/quicktime', m4v: 'video/mp4', webm: 'video/webm' })[ext] || 'application/octet-stream';
try {
await uploadFile(`/api/center/tutorials?${params}`, 'POST', file, showProgress, type);
closeModal();
toast('教程已上传');
if (centerTab !== 'tutorials') { centerTab = 'tutorials'; history.replaceState(null, '', '#center-tutorials'); }
$$('[data-center-tab]').forEach(b => b.classList.toggle('active', b.dataset.centerTab === 'tutorials'));
$('#center-records').classList.add('hidden'); $('#center-tutorials').classList.remove('hidden');
$('#center-duty').classList.add('hidden'); $('#center-assets').classList.add('hidden'); $('#center-hall').classList.add('hidden');
tutorialState.items = []; tutorialState.q = ''; $('#tutorial-q').value = '';
await loadTutorials({ fresh: true });
} catch (error) {
submitted = false;
errorBox.textContent = error.message;
label.textContent = '上传未完成,可以直接重试。';
abortButton.classList.add('hidden');
button.disabled = false; button.textContent = '重新上传';
form.room.disabled = form.equipment.disabled = form.video.disabled = form.note.disabled = false;
if (!form.isConnected) { tutorialProgressHandler = null; return; }
}
tutorialProgressHandler = null;
});
}
$('#tutorial-new').addEventListener('click', openTutorialForm);
$('#tutorial-q').addEventListener('input', searchTutorials);
$('#tutorial-more').addEventListener('click', async () => {
if (tutorialState.freshMode) return;
$('#tutorial-more').dataset.mode = 'append';
await loadTutorials();
});
$('#tutorial-list').addEventListener('pointerenter', event => {
const video = event.target.closest('.tutorial-video');
if (video && !tutorialState.freshMode) playTutorial(Number(video.dataset.index));
}, true);
$('#tutorial-list').addEventListener('focusin', event => {
});
$('#tutorial-list').addEventListener('click', async event => {
const button = event.target.closest('[data-tutorial-download]');
if (button) {
const item = tutorialState.items.find(t => t.id === button.dataset.tutorialDownload);
button.disabled = true;
try {
const ext = (item?.video_file || '').split('.').pop() || 'mp4';
await downloadCenterFile(`/api/center/tutorials/${encodeURIComponent(button.dataset.tutorialDownload)}?preview=1`,
`${item?.room || '教程'}-${item?.equipment || ''}.${ext}`.replace(/[\\/:*?"<>|]/g, '_'));
} catch (error) { toast(error.message, true); }
finally { button.disabled = false; }
return;
}
const video = event.target.closest('.tutorial-video');
if (video) playTutorial(Number(video.dataset.index));
});
function openLoanForm() {
centerForm('登记借出',
`<p class="muted">这里只保存借出记录,不占用库存,也不要求物品已加入库存清单。借出理由全员可见,联系方式仅本人可见。</p>