Initial commit: SSS 50-week LAN check-in app.
Ship the Synology/Mac deployable player with curriculum mapping, stats, and resource library. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
commit
dd281e1bd0
27 files changed
+9416
No files matched your search
+1099
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
||||
<rect width="512" height="512" rx="128" fill="#f5a65b"/>
|
||||
<circle cx="190" cy="358" r="74" fill="#fffdf8"/>
|
||||
<circle cx="358" cy="318" r="66" fill="#fffdf8"/>
|
||||
<path d="M244 116v241h-38V146l206-52v223h-38V143z" fill="#fffdf8"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 303 B |
@@ -0,0 +1,203 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#f5a65b" />
|
||||
<meta name="description" content="SSS 50周儿歌独立媒体卡、小红花打卡与十四天成长记录" />
|
||||
<link rel="manifest" href="/static/manifest.webmanifest" />
|
||||
<link rel="icon" href="/static/icon.svg" type="image/svg+xml" />
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
<title>SSS 50 周打卡</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page-shell">
|
||||
<header class="topbar">
|
||||
<h1 id="week-title" class="week-top-title">第 1 周</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<p id="startup-status" class="startup-status" role="status" aria-live="polite">正在连接学习记录…</p>
|
||||
<section class="hero" aria-labelledby="week-title">
|
||||
<div class="hero-copy">
|
||||
<div class="study-line">
|
||||
<p id="week-kind" class="eyebrow">今日学习</p>
|
||||
<p id="study-date-label" class="study-date-label">今天 · 10月12日</p>
|
||||
</div>
|
||||
<p id="week-category" class="week-category">宠物 · 农场动物</p>
|
||||
</div>
|
||||
<div class="today-card">
|
||||
<button id="identity-button" class="identity-chip" type="button" aria-label="切换当前角色">
|
||||
<span id="identity-emoji" aria-hidden="true">●</span>
|
||||
<span id="identity-label">选择身份</span>
|
||||
</button>
|
||||
<div class="today-metrics">
|
||||
<span><strong id="today-checkins">0</strong><small id="day-flower-label">今日红花</small></span>
|
||||
<span><strong id="today-plays">0</strong><small id="day-play-label">今日播放</small></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="week-nav" aria-label="切换周次">
|
||||
<button id="previous-week" class="soft-button" type="button">上一周</button>
|
||||
<button id="current-week" class="soft-button accent" type="button">回到今天</button>
|
||||
<button id="next-week" class="soft-button" type="button">下一周</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="playlist-control" aria-label="本周音频循环播放">
|
||||
<button id="playlist-loop-button" class="playlist-loop-button" type="button" aria-pressed="false">
|
||||
<span aria-hidden="true">▶</span>
|
||||
<strong>一键播放</strong>
|
||||
</button>
|
||||
<p class="playlist-description">三首本周歌曲依次播放,锁屏后也会自动循环。</p>
|
||||
<p id="playlist-loop-status" hidden aria-live="polite"></p>
|
||||
<audio id="weekly-loop-player" class="weekly-loop-player" preload="none" loop playsinline webkit-playsinline aria-hidden="true"></audio>
|
||||
</section>
|
||||
|
||||
<section id="player" class="player-section" aria-labelledby="player-heading">
|
||||
<h2 id="player-heading" hidden>本周歌单</h2>
|
||||
|
||||
<div id="song-cards" class="song-cards" aria-label="本周歌曲"></div>
|
||||
|
||||
<div id="round-checkin" class="round-checkin" aria-label="整轮小红花">
|
||||
<div id="round-flowers" class="round-flower-strip"></div>
|
||||
<p id="round-hint" class="round-hint">三首歌都听完,才能领取一朵大红花哦</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="achievement-section" aria-labelledby="achievement-heading">
|
||||
<div class="achievement-heading">
|
||||
<div>
|
||||
<p class="eyebrow">成长足迹</p>
|
||||
<h2 id="achievement-heading">最近 14 天</h2>
|
||||
</div>
|
||||
<div class="achievement-summary">
|
||||
<span aria-hidden="true">🌸</span>
|
||||
<strong id="achievement-count">0</strong>
|
||||
<small>朵红花</small>
|
||||
</div>
|
||||
</div>
|
||||
<p class="achievement-copy">今天永远在右下角。点过去的日期,可以补学习、补红花。</p>
|
||||
<div class="progress-calendar" aria-label="最近十四天打卡情况">
|
||||
<div id="progress-weekdays" class="progress-weekdays" aria-hidden="true"></div>
|
||||
<div id="progress-grid" class="progress-grid"></div>
|
||||
</div>
|
||||
<div class="progress-legend" aria-hidden="true">
|
||||
<span><i class="legend-dot complete"></i>完成一轮</span>
|
||||
<span><i class="legend-dot progress"></i>学习过</span>
|
||||
<span><i class="legend-dot missed"></i>待补</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="plan-section" aria-labelledby="plan-heading">
|
||||
<div class="section-heading">
|
||||
<div>
|
||||
<p class="eyebrow">课程地图</p>
|
||||
<h2 id="plan-heading">50 周学习计划</h2>
|
||||
</div>
|
||||
<span id="plan-summary" class="summary-pill">0/50 周学过</span>
|
||||
</div>
|
||||
<div id="week-grid" class="week-grid"></div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div>
|
||||
<span>播放与打卡数据只保存在家庭服务器</span>
|
||||
<span id="asset-status">正在检查视频、音频和歌词…</span>
|
||||
</div>
|
||||
<button id="bottom-settings-button" class="footer-settings-button" type="button" aria-label="打开家长设置">
|
||||
<span aria-hidden="true">⚙</span> 设置
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<div id="identity-dialog" class="modal identity-dialog" role="dialog" aria-modal="true" aria-labelledby="identity-dialog-title" hidden>
|
||||
<div class="dialog-body">
|
||||
<p class="eyebrow">角色切换</p>
|
||||
<h2 id="identity-dialog-title">现在是谁在使用?</h2>
|
||||
<p class="dialog-copy">选择后会记住这台手机或平板,以后的播放和打卡会记录操作者。</p>
|
||||
<div id="identity-options" class="identity-options"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="settings-dialog" class="modal settings-dialog" role="dialog" aria-modal="true" aria-labelledby="settings-dialog-title" hidden>
|
||||
<form id="settings-form">
|
||||
<div class="dialog-heading">
|
||||
<div>
|
||||
<p class="eyebrow">家长设置</p>
|
||||
<h2 id="settings-dialog-title">学习与设备</h2>
|
||||
</div>
|
||||
<button id="close-settings" class="icon-button" type="button" value="cancel" aria-label="关闭">×</button>
|
||||
</div>
|
||||
|
||||
<label>
|
||||
开始学习日期(已固定)
|
||||
<input id="start-date" name="start_date" type="date" value="2026-10-12" disabled />
|
||||
<small class="field-help">课程固定从 2026 年 10 月 12 日开始,每 7 天进入下一周。</small>
|
||||
</label>
|
||||
<label>
|
||||
同一首歌领取间隔
|
||||
<select id="checkin-window" name="checkin_window_minutes">
|
||||
<option value="30">30 分钟内只记一次</option>
|
||||
<option value="60">1 小时内只记一次</option>
|
||||
<option value="90">90 分钟内只记一次</option>
|
||||
<option value="120">2 小时内只记一次</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="mode-setting">
|
||||
<input id="child-mode" name="child_mode" type="checkbox" />
|
||||
<span>
|
||||
<strong>儿童模式</strong>
|
||||
<small>只显示一键播放和三首歌的单独音频播放。</small>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<a class="stats-link" href="/stats">
|
||||
<span>
|
||||
<strong>查看红花与播放统计</strong>
|
||||
<small>每天、50 周、每首歌和家庭成员</small>
|
||||
</span>
|
||||
<span aria-hidden="true">›</span>
|
||||
</a>
|
||||
|
||||
<a class="stats-link resource-link" href="/resources">
|
||||
<span>
|
||||
<strong>打开全部资源库</strong>
|
||||
<small>搜索 100 首歌,播放视频音频、查看歌词</small>
|
||||
</span>
|
||||
<span aria-hidden="true">›</span>
|
||||
</a>
|
||||
|
||||
<div class="dialog-actions">
|
||||
<button class="primary-button" type="submit">保存设置</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="toast" role="status" aria-live="polite"></div>
|
||||
<div id="celebration" class="celebration" hidden aria-live="assertive">
|
||||
<div class="spark-ring" aria-hidden="true"></div>
|
||||
<div class="sparkles" aria-hidden="true">
|
||||
<i>✦</i><i>✧</i><i>★</i><i>✦</i><i>✧</i><i>★</i><i>✦</i><i>✧</i><i>★</i><i>✦</i><i>✧</i><i>★</i>
|
||||
</div>
|
||||
<div class="petal-burst" aria-hidden="true">
|
||||
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
|
||||
</div>
|
||||
<div class="celebration-card">
|
||||
<span class="reward-kicker">奖励到手</span>
|
||||
<span class="celebration-flower" aria-hidden="true">🌸</span>
|
||||
<strong id="celebration-title">获得一朵小红花!</strong>
|
||||
<p id="celebration-copy">认真听完啦,真棒!</p>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/app.js" defer></script>
|
||||
<script>
|
||||
window.setTimeout(function () {
|
||||
var status = document.getElementById("startup-status");
|
||||
if (status && !status.hidden) {
|
||||
status.textContent = "页面未能完成启动。请关闭此页面后重新打开;如果仍然出现,请告诉家长。";
|
||||
}
|
||||
}, 7000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "SSS 50 周打卡",
|
||||
"short_name": "SSS打卡",
|
||||
"description": "家庭局域网中的 SSS 儿歌独立播放、小红花打卡与统计工具",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#f8f3e8",
|
||||
"theme_color": "#f5a65b",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/static/icon.svg",
|
||||
"sizes": "any",
|
||||
"type": "image/svg+xml",
|
||||
"purpose": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,576 @@
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.resource-shell {
|
||||
width: calc(100% - 32px);
|
||||
max-width: 1240px;
|
||||
width: min(1240px, calc(100% - 32px));
|
||||
margin: 0 auto;
|
||||
padding-bottom: 54px;
|
||||
}
|
||||
|
||||
.resource-topbar {
|
||||
min-height: 168px;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.resource-topbar > div {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.resource-topbar h1 {
|
||||
margin: 0;
|
||||
font-size: 48px;
|
||||
font-size: clamp(38px, 6vw, 64px);
|
||||
}
|
||||
|
||||
.resource-topbar p:last-child {
|
||||
margin: 8px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
justify-self: start;
|
||||
padding: 10px 14px;
|
||||
border-radius: 13px;
|
||||
color: var(--ink);
|
||||
background: rgba(255, 253, 248, 0.78);
|
||||
text-decoration: none;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.resource-total {
|
||||
justify-self: end;
|
||||
padding: 9px 13px;
|
||||
border-radius: 999px;
|
||||
color: var(--sage-dark);
|
||||
background: var(--sage-soft);
|
||||
font-size: 12px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.resource-summary {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.resource-summary article {
|
||||
min-height: 104px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding: 18px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.9);
|
||||
border-radius: 22px;
|
||||
background: rgba(255, 253, 248, 0.84);
|
||||
box-shadow: 0 12px 30px rgba(78, 62, 38, 0.06);
|
||||
}
|
||||
|
||||
.resource-summary article:nth-child(2) { background: rgba(255, 241, 220, 0.86); }
|
||||
.resource-summary article:nth-child(3) { background: rgba(223, 238, 231, 0.84); }
|
||||
.resource-summary article:nth-child(4) { background: rgba(255, 230, 230, 0.72); }
|
||||
|
||||
.summary-icon {
|
||||
width: 47px;
|
||||
height: 47px;
|
||||
flex: 0 0 47px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 15px;
|
||||
color: white;
|
||||
background: var(--peach);
|
||||
font-size: 21px;
|
||||
}
|
||||
|
||||
.resource-summary small,
|
||||
.resource-summary strong {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.resource-summary small {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.resource-summary strong {
|
||||
margin-top: 6px;
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
.resource-summary em {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.resource-toolbar {
|
||||
position: sticky;
|
||||
top: 10px;
|
||||
z-index: 8;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(280px, 1fr) 160px 160px;
|
||||
gap: 10px;
|
||||
margin: 26px 0;
|
||||
padding: 11px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.9);
|
||||
border-radius: 20px;
|
||||
background: rgba(249, 245, 235, 0.92);
|
||||
box-shadow: 0 12px 34px rgba(78, 62, 38, 0.1);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.resource-search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding-left: 12px;
|
||||
border-radius: 13px;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.resource-toolbar input,
|
||||
.resource-toolbar select {
|
||||
width: 100%;
|
||||
min-height: 47px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 13px;
|
||||
color: var(--ink);
|
||||
background: white;
|
||||
}
|
||||
|
||||
.resource-search input {
|
||||
padding: 10px 12px 10px 0;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.resource-toolbar select {
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.resource-layout {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.catalog-panel {
|
||||
border: 1px solid rgba(255, 255, 255, 0.88);
|
||||
border-radius: 27px;
|
||||
background: rgba(255, 253, 248, 0.78);
|
||||
box-shadow: 0 14px 38px rgba(78, 62, 38, 0.07);
|
||||
}
|
||||
|
||||
.catalog-panel {
|
||||
padding: 22px;
|
||||
}
|
||||
|
||||
.catalog-heading {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.catalog-heading h2 {
|
||||
margin: 2px 0 0;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.result-count {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.resource-list {
|
||||
display: grid;
|
||||
gap: 9px;
|
||||
max-width: 940px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.resource-item {
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 20px;
|
||||
background: rgba(255, 255, 255, 0.68);
|
||||
transition: 180ms ease;
|
||||
}
|
||||
|
||||
.resource-item.expanded {
|
||||
border-color: rgba(245, 166, 91, 0.62);
|
||||
background: #fff8eb;
|
||||
box-shadow: 0 12px 30px rgba(217, 121, 53, 0.12);
|
||||
}
|
||||
|
||||
.resource-card {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
grid-template-columns: 62px minmax(0, 1fr) auto;
|
||||
align-items: center;
|
||||
gap: 13px;
|
||||
padding: 13px;
|
||||
border: 0;
|
||||
border-radius: 19px;
|
||||
color: var(--ink);
|
||||
background: rgba(255, 255, 255, 0.68);
|
||||
text-align: left;
|
||||
transition: 160ms ease;
|
||||
}
|
||||
|
||||
.resource-card:hover,
|
||||
.resource-card.selected {
|
||||
background: #fff8eb;
|
||||
box-shadow: none;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.resource-item.expanded .resource-card {
|
||||
border-radius: 19px 19px 0 0;
|
||||
border-bottom: 1px solid rgba(217, 121, 53, 0.14);
|
||||
}
|
||||
|
||||
.resource-number {
|
||||
min-height: 48px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
border-radius: 14px;
|
||||
color: #9a5828;
|
||||
background: #ffe9c9;
|
||||
font-size: 13px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.resource-card-copy,
|
||||
.resource-card-copy strong,
|
||||
.resource-card-copy small {
|
||||
display: block;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.resource-card-copy strong {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.resource-card-copy small {
|
||||
margin-top: 4px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.asset-badges {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.asset-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 4px 7px;
|
||||
border-radius: 999px;
|
||||
color: var(--muted);
|
||||
background: rgba(37, 50, 45, 0.05);
|
||||
font-size: 9px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.asset-badge i {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: #c9beb4;
|
||||
}
|
||||
|
||||
.asset-badge.ready {
|
||||
color: var(--sage-dark);
|
||||
background: var(--sage-soft);
|
||||
}
|
||||
|
||||
.asset-badge.ready i { background: var(--sage); }
|
||||
.asset-badge.missing { color: #a95b62; background: #ffe7e8; }
|
||||
.asset-badge.missing i { background: #dc717a; }
|
||||
|
||||
.resource-arrow {
|
||||
color: var(--muted);
|
||||
font-size: 24px;
|
||||
transition: transform 180ms ease;
|
||||
}
|
||||
|
||||
.resource-item.expanded .resource-arrow {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.resource-empty {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
padding: 58px 20px;
|
||||
color: var(--muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.resource-empty[hidden] { display: none; }
|
||||
.resource-empty > span { font-size: 38px; }
|
||||
.resource-empty strong { margin-top: 10px; color: var(--ink); }
|
||||
.resource-empty p { margin-bottom: 0; }
|
||||
|
||||
.resource-inline-viewer {
|
||||
margin: 12px;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgba(37, 50, 45, 0.08);
|
||||
border-radius: 22px;
|
||||
background: rgba(255, 253, 248, 0.96);
|
||||
animation: resource-unfold 210ms ease-out both;
|
||||
}
|
||||
|
||||
.resource-inline-tabs {
|
||||
border-bottom: 1px solid rgba(37, 50, 45, 0.06);
|
||||
}
|
||||
|
||||
.resource-inline-viewer .song-media-shell {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.resource-inline-viewer .center-play:disabled,
|
||||
.resource-inline-viewer .audio-toggle:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.resource-inline-note {
|
||||
margin: 0;
|
||||
padding: 12px 16px;
|
||||
color: var(--sage-dark);
|
||||
background: var(--sage-soft);
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@keyframes resource-unfold {
|
||||
from { opacity: 0; transform: translateY(-8px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
.resource-viewer {
|
||||
position: sticky;
|
||||
top: 102px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.viewer-heading {
|
||||
padding: 25px 25px 20px;
|
||||
}
|
||||
|
||||
.viewer-heading h2 {
|
||||
margin: 9px 0 6px;
|
||||
font-size: clamp(25px, 3vw, 37px);
|
||||
line-height: 1.08;
|
||||
}
|
||||
|
||||
.viewer-heading p {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.resource-tabs {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 6px;
|
||||
padding: 8px;
|
||||
border-top: 1px solid var(--border);
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: rgba(245, 241, 231, 0.84);
|
||||
}
|
||||
|
||||
.resource-tab {
|
||||
min-height: 43px;
|
||||
border-radius: 12px;
|
||||
color: var(--muted);
|
||||
background: transparent;
|
||||
font-size: 12px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.resource-tab.selected {
|
||||
color: var(--peach-dark);
|
||||
background: white;
|
||||
box-shadow: 0 5px 14px rgba(78, 62, 38, 0.08);
|
||||
}
|
||||
|
||||
.resource-panel {
|
||||
min-height: 360px;
|
||||
}
|
||||
|
||||
.info-panel {
|
||||
padding: 23px;
|
||||
}
|
||||
|
||||
.viewer-note {
|
||||
margin: 0 0 18px;
|
||||
padding: 13px 14px;
|
||||
border-radius: 15px;
|
||||
color: var(--sage-dark);
|
||||
background: var(--sage-soft);
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.file-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.file-list div {
|
||||
padding: 13px 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 15px;
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
.file-list dt {
|
||||
color: var(--muted);
|
||||
font-size: 10px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.file-list dd {
|
||||
margin: 5px 0 0;
|
||||
overflow-wrap: anywhere;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.media-preview,
|
||||
.lyrics-preview {
|
||||
background: #202621;
|
||||
}
|
||||
|
||||
.media-preview video {
|
||||
width: 100%;
|
||||
min-height: 360px;
|
||||
display: block;
|
||||
background: #111;
|
||||
}
|
||||
|
||||
.media-preview audio {
|
||||
width: calc(100% - 42px);
|
||||
margin: 142px 21px 0;
|
||||
}
|
||||
|
||||
.lazy-placeholder {
|
||||
min-height: 360px;
|
||||
display: grid;
|
||||
place-content: center;
|
||||
justify-items: center;
|
||||
padding: 34px;
|
||||
color: white;
|
||||
background: radial-gradient(circle at top right, rgba(245,166,91,.42), transparent 42%), #25322d;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.lazy-placeholder > span {
|
||||
width: 68px;
|
||||
height: 68px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
margin-bottom: 16px;
|
||||
border-radius: 23px;
|
||||
color: white;
|
||||
background: var(--peach);
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.lazy-placeholder p {
|
||||
max-width: 290px;
|
||||
margin: 8px 0 19px;
|
||||
color: rgba(255,255,255,.72);
|
||||
font-size: 12px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.lazy-placeholder .primary-button:disabled {
|
||||
opacity: .5;
|
||||
}
|
||||
|
||||
.audio-lazy {
|
||||
background: radial-gradient(circle at top right, rgba(118,168,150,.4), transparent 42%), #25322d;
|
||||
}
|
||||
|
||||
.lyrics-preview {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
min-height: 360px;
|
||||
padding: 12px;
|
||||
background: #f0ece3;
|
||||
}
|
||||
|
||||
.lyrics-preview img {
|
||||
max-width: 100%;
|
||||
max-height: 68vh;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.resource-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 18px;
|
||||
padding: 38px 4px 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.resource-summary { grid-template-columns: repeat(2, 1fr); }
|
||||
.resource-layout { grid-template-columns: 1fr; }
|
||||
.resource-viewer { position: static; order: -1; scroll-margin-top: 96px; }
|
||||
.resource-panel { min-height: 330px; }
|
||||
.lazy-placeholder, .media-preview video { min-height: 330px; }
|
||||
}
|
||||
|
||||
@media (max-width: 620px) {
|
||||
.resource-shell { width: calc(100% - 22px); max-width: 580px; width: min(calc(100% - 22px), 580px); }
|
||||
.resource-topbar { min-height: 150px; grid-template-columns: 1fr auto; }
|
||||
.resource-topbar > div { grid-column: 1 / -1; grid-row: 1; }
|
||||
.back-link { grid-column: 1; grid-row: 2; }
|
||||
.resource-total { grid-column: 2; grid-row: 2; }
|
||||
.resource-topbar h1 { font-size: 36px; }
|
||||
.resource-summary { gap: 8px; }
|
||||
.resource-summary article { min-height: 89px; gap: 10px; padding: 13px; border-radius: 18px; }
|
||||
.summary-icon { width: 39px; height: 39px; flex-basis: 39px; border-radius: 12px; font-size: 17px; }
|
||||
.resource-summary strong { font-size: 21px; }
|
||||
.resource-toolbar { top: 6px; grid-template-columns: repeat(2, 1fr); margin: 18px 0; }
|
||||
.resource-search { grid-column: 1 / -1; }
|
||||
.catalog-panel { padding: 13px; border-radius: 22px; }
|
||||
.resource-card { grid-template-columns: 52px minmax(0, 1fr) 22px; padding: 11px; }
|
||||
.resource-number { min-height: 45px; }
|
||||
.resource-arrow { display: block; text-align: center; }
|
||||
.asset-badge { font-size: 8px; }
|
||||
.resource-inline-viewer { margin: 7px; border-radius: 18px; }
|
||||
.resource-inline-note { padding: 10px 12px; font-size: 10px; }
|
||||
.resource-viewer { border-radius: 22px; }
|
||||
.viewer-heading { padding: 21px 18px 17px; }
|
||||
.resource-tabs { gap: 3px; padding: 6px; }
|
||||
.resource-tab { font-size: 11px; }
|
||||
.resource-panel, .lazy-placeholder, .media-preview video { min-height: 290px; }
|
||||
.info-panel { padding: 17px; }
|
||||
.media-preview audio { margin-top: 116px; }
|
||||
.resource-footer { flex-direction: column; }
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#f5a65b" />
|
||||
<meta name="description" content="SSS 50周全部视频、音频和歌词资源库" />
|
||||
<link rel="icon" href="/static/icon.svg" type="image/svg+xml" />
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
<link rel="stylesheet" href="/static/resources.css" />
|
||||
<title>SSS 全部资源库</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="resource-shell">
|
||||
<header class="resource-topbar">
|
||||
<a class="back-link" href="/" aria-label="返回播放器">‹ 返回播放</a>
|
||||
<div>
|
||||
<p class="eyebrow">家长工具</p>
|
||||
<h1>全部资源库</h1>
|
||||
<p>快速找到每一首歌的视频、音频和歌词</p>
|
||||
</div>
|
||||
<span id="resource-total" class="resource-total">正在读取…</span>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section id="resource-summary" class="resource-summary" aria-label="资源完整情况"></section>
|
||||
|
||||
<section class="resource-toolbar" aria-label="搜索和筛选资源">
|
||||
<label class="resource-search">
|
||||
<span aria-hidden="true">⌕</span>
|
||||
<input id="resource-search" type="search" placeholder="搜索歌名、编号、主题或文件名" autocomplete="off" />
|
||||
</label>
|
||||
<label>
|
||||
<span class="sr-only">按周筛选</span>
|
||||
<select id="week-filter"><option value="all">全部周次</option></select>
|
||||
</label>
|
||||
<label>
|
||||
<span class="sr-only">按资源状态筛选</span>
|
||||
<select id="availability-filter">
|
||||
<option value="all">全部资源</option>
|
||||
<option value="complete">三项齐全</option>
|
||||
<option value="missing">存在缺失</option>
|
||||
</select>
|
||||
</label>
|
||||
</section>
|
||||
|
||||
<div class="resource-layout">
|
||||
<section class="catalog-panel" aria-labelledby="catalog-heading">
|
||||
<div class="catalog-heading">
|
||||
<div>
|
||||
<p class="eyebrow">课程清单</p>
|
||||
<h2 id="catalog-heading">100 首歌</h2>
|
||||
</div>
|
||||
<span id="result-count" class="result-count">0 项</span>
|
||||
</div>
|
||||
<div id="resource-list" class="resource-list"></div>
|
||||
<div id="resource-empty" class="resource-empty" hidden>
|
||||
<span aria-hidden="true">⌕</span>
|
||||
<strong>没有找到匹配的歌曲</strong>
|
||||
<p>试试清空关键词,或选择其他周次。</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="resource-footer">
|
||||
<span>只在局域网内读取群晖资源</span>
|
||||
<span>视频、音频均按需加载</span>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<div id="resource-toast" class="toast" role="status" aria-live="polite"></div>
|
||||
<script src="/static/resources.js" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,368 @@
|
||||
const resourceState = {
|
||||
catalog: null,
|
||||
selectedId: null,
|
||||
mode: "video",
|
||||
};
|
||||
|
||||
const resourceElements = {
|
||||
total: document.querySelector("#resource-total"),
|
||||
summary: document.querySelector("#resource-summary"),
|
||||
search: document.querySelector("#resource-search"),
|
||||
weekFilter: document.querySelector("#week-filter"),
|
||||
availabilityFilter: document.querySelector("#availability-filter"),
|
||||
catalogHeading: document.querySelector("#catalog-heading"),
|
||||
resultCount: document.querySelector("#result-count"),
|
||||
list: document.querySelector("#resource-list"),
|
||||
empty: document.querySelector("#resource-empty"),
|
||||
toast: document.querySelector("#resource-toast"),
|
||||
};
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value == null ? "" : value)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function forEachNode(nodes, callback) {
|
||||
for (let index = 0; index < nodes.length; index += 1) {
|
||||
callback(nodes[index], index);
|
||||
}
|
||||
}
|
||||
|
||||
function currentSong() {
|
||||
return resourceState.catalog
|
||||
? resourceState.catalog.songs.find((song) => song.id === resourceState.selectedId) || null
|
||||
: null;
|
||||
}
|
||||
|
||||
function isComplete(song) {
|
||||
return song.available.video && song.available.audio && song.available.lyrics;
|
||||
}
|
||||
|
||||
function availabilityBadge(label, available) {
|
||||
return `<span class="asset-badge ${available ? "ready" : "missing"}"><i aria-hidden="true"></i>${label}${available ? "齐全" : "缺失"}</span>`;
|
||||
}
|
||||
|
||||
function renderSummary() {
|
||||
const { songs, available } = resourceState.catalog.summary;
|
||||
resourceElements.total.textContent = `${songs} 首歌`;
|
||||
resourceElements.summary.innerHTML = [
|
||||
["全部歌曲", songs, "首", "♫"],
|
||||
["视频文件", available.video, "/ 100", "▶"],
|
||||
["音频文件", available.audio, "/ 100", "♬"],
|
||||
["歌词图片", available.lyrics, "/ 100", "▤"],
|
||||
]
|
||||
.map(
|
||||
([label, value, unit, icon]) => `
|
||||
<article>
|
||||
<span class="summary-icon" aria-hidden="true">${icon}</span>
|
||||
<div><small>${label}</small><strong>${value} <em>${unit}</em></strong></div>
|
||||
</article>`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
function populateWeeks() {
|
||||
const weeks = [];
|
||||
resourceState.catalog.songs.forEach((song) => {
|
||||
if (weeks.indexOf(song.week) === -1) weeks.push(song.week);
|
||||
});
|
||||
resourceElements.weekFilter.insertAdjacentHTML(
|
||||
"beforeend",
|
||||
weeks.map((week) => `<option value="${week}">第 ${week} 周</option>`).join(""),
|
||||
);
|
||||
}
|
||||
|
||||
function filteredSongs() {
|
||||
const needle = resourceElements.search.value.trim().toLowerCase();
|
||||
const week = resourceElements.weekFilter.value;
|
||||
const availability = resourceElements.availabilityFilter.value;
|
||||
return resourceState.catalog.songs.filter((song) => {
|
||||
const haystack = [song.id, song.title, song.category, song.files.video, song.files.audio, song.files.lyrics]
|
||||
.join(" ")
|
||||
.toLowerCase();
|
||||
const matchesText = !needle || haystack.includes(needle);
|
||||
const matchesWeek = week === "all" || song.week === Number(week);
|
||||
const complete = isComplete(song);
|
||||
const matchesAvailability = availability === "all" || (availability === "complete" ? complete : !complete);
|
||||
return matchesText && matchesWeek && matchesAvailability;
|
||||
});
|
||||
}
|
||||
|
||||
function resourceDetailMarkup(song) {
|
||||
const videoDisabled = song.available.video ? "" : " disabled";
|
||||
const audioDisabled = song.available.audio ? "" : " disabled";
|
||||
return `
|
||||
<div class="resource-inline-viewer" data-resource-detail>
|
||||
<div class="mode-tabs resource-inline-tabs" role="tablist" aria-label="${escapeHtml(song.title)} 内容形式">
|
||||
<button class="mode-tab ${resourceState.mode === "video" ? "selected" : ""}" type="button" data-resource-mode="video" role="tab" aria-selected="${resourceState.mode === "video"}">
|
||||
<span aria-hidden="true">▶</span> 视频
|
||||
</button>
|
||||
<button class="mode-tab ${resourceState.mode === "audio" ? "selected" : ""}" type="button" data-resource-mode="audio" role="tab" aria-selected="${resourceState.mode === "audio"}">
|
||||
<span aria-hidden="true">♫</span> 音频
|
||||
</button>
|
||||
<button class="mode-tab ${resourceState.mode === "lyrics" ? "selected" : ""}" type="button" data-resource-mode="lyrics" role="tab" aria-selected="${resourceState.mode === "lyrics"}">
|
||||
<span aria-hidden="true">▤</span> 歌词
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="song-media-shell">
|
||||
<div class="song-media-panel song-video-panel" data-resource-panel="video" ${resourceState.mode === "video" ? "" : "hidden"}>
|
||||
<video controls playsinline webkit-playsinline preload="none" data-resource-video data-video-url="${escapeHtml(song.urls.video)}" aria-label="${escapeHtml(song.title)} 视频"></video>
|
||||
<button class="center-play" type="button" data-resource-video-toggle${videoDisabled}>${song.available.video ? "播放视频" : "视频缺失"}</button>
|
||||
</div>
|
||||
|
||||
<div class="song-media-panel song-audio-panel" data-resource-panel="audio" ${resourceState.mode === "audio" ? "" : "hidden"}>
|
||||
<img data-resource-audio-art data-src="${escapeHtml(song.urls.lyrics)}" alt="" />
|
||||
<button class="audio-toggle" type="button" data-resource-audio-toggle aria-label="播放 ${escapeHtml(song.title)} 音频"${audioDisabled}>
|
||||
<span class="audio-disc" aria-hidden="true">♫</span>
|
||||
<strong>${song.available.audio ? "播放音频" : "音频缺失"}</strong>
|
||||
<small>${escapeHtml(song.title)}</small>
|
||||
</button>
|
||||
<div class="audio-timeline">
|
||||
<span data-resource-audio-current>0:00</span>
|
||||
<input type="range" min="0" max="0" value="0" step="0.1" data-resource-audio-progress aria-label="${escapeHtml(song.title)} 音频进度" ${song.available.audio ? "" : "disabled"} />
|
||||
<span data-resource-audio-duration>--:--</span>
|
||||
</div>
|
||||
<audio preload="none" data-resource-audio data-audio-url="${escapeHtml(song.urls.audio)}"></audio>
|
||||
</div>
|
||||
|
||||
<div class="song-lyrics-panel" data-resource-panel="lyrics" ${resourceState.mode === "lyrics" ? "" : "hidden"}>
|
||||
<img data-resource-lyrics data-src="${escapeHtml(song.urls.lyrics)}" alt="${escapeHtml(song.title)} 歌词" />
|
||||
</div>
|
||||
</div>
|
||||
<p class="resource-inline-note">资源库试听不会产生打卡记录;要记录学习,请回到主页面完整播放。</p>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function resourceItemMarkup(song) {
|
||||
const expanded = song.id === resourceState.selectedId;
|
||||
return `
|
||||
<article class="resource-item ${expanded ? "expanded" : ""}" data-resource-item="${song.id}">
|
||||
<button type="button" class="resource-card ${expanded ? "selected" : ""}" data-song-id="${song.id}" aria-expanded="${expanded}">
|
||||
<span class="resource-number">${song.id}</span>
|
||||
<span class="resource-card-copy">
|
||||
<strong>${escapeHtml(song.title)}</strong>
|
||||
<small>第 ${song.week} 周 · ${escapeHtml(song.category || "综合主题")}</small>
|
||||
<span class="asset-badges">
|
||||
${availabilityBadge("视频", song.available.video)}
|
||||
${availabilityBadge("音频", song.available.audio)}
|
||||
${availabilityBadge("歌词", song.available.lyrics)}
|
||||
</span>
|
||||
</span>
|
||||
<span class="resource-arrow" aria-hidden="true">⌄</span>
|
||||
</button>
|
||||
${expanded ? resourceDetailMarkup(song) : ""}
|
||||
</article>`;
|
||||
}
|
||||
|
||||
function stopOpenMedia() {
|
||||
forEachNode(resourceElements.list.querySelectorAll("video, audio"), (media) => {
|
||||
media.pause();
|
||||
media.removeAttribute("src");
|
||||
media.load();
|
||||
});
|
||||
}
|
||||
|
||||
function renderList() {
|
||||
const songs = filteredSongs();
|
||||
if (resourceState.selectedId && !songs.some((song) => song.id === resourceState.selectedId)) {
|
||||
resourceState.selectedId = null;
|
||||
resourceState.mode = "video";
|
||||
}
|
||||
resourceElements.resultCount.textContent = `${songs.length} 项`;
|
||||
resourceElements.empty.hidden = songs.length > 0;
|
||||
resourceElements.list.innerHTML = songs.map(resourceItemMarkup).join("");
|
||||
bindList();
|
||||
}
|
||||
|
||||
function selectSong(songId) {
|
||||
stopOpenMedia();
|
||||
const shouldClose = resourceState.selectedId === songId;
|
||||
resourceState.selectedId = shouldClose ? null : songId;
|
||||
resourceState.mode = "video";
|
||||
renderList();
|
||||
if (!shouldClose) {
|
||||
const item = resourceElements.list.querySelector(`[data-resource-item="${songId}"]`);
|
||||
if (item && item.scrollIntoView) item.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
||||
}
|
||||
}
|
||||
|
||||
function openPanel() {
|
||||
return resourceElements.list.querySelector("[data-resource-detail]");
|
||||
}
|
||||
|
||||
function pauseOpenMedia(except = null) {
|
||||
const panel = openPanel();
|
||||
if (!panel) return;
|
||||
forEachNode(panel.querySelectorAll("video, audio"), (media) => {
|
||||
if (media !== except) media.pause();
|
||||
});
|
||||
}
|
||||
|
||||
function loadLazyImage(image) {
|
||||
if (image && !image.hasAttribute("src") && image.dataset.src) image.src = image.dataset.src;
|
||||
}
|
||||
|
||||
function changeMode(mode) {
|
||||
if (!currentSong()) return;
|
||||
resourceState.mode = mode;
|
||||
const detail = openPanel();
|
||||
forEachNode(detail.querySelectorAll("[data-resource-mode]"), (tab) => {
|
||||
const selected = tab.dataset.resourceMode === mode;
|
||||
tab.classList.toggle("selected", selected);
|
||||
tab.setAttribute("aria-selected", String(selected));
|
||||
});
|
||||
forEachNode(detail.querySelectorAll("[data-resource-panel]"), (panel) => {
|
||||
panel.hidden = panel.dataset.resourcePanel !== mode;
|
||||
});
|
||||
if (mode === "audio") loadLazyImage(detail.querySelector("[data-resource-audio-art]"));
|
||||
if (mode === "lyrics") loadLazyImage(detail.querySelector("[data-resource-lyrics]"));
|
||||
}
|
||||
|
||||
function updateVideoButton(detail) {
|
||||
const video = detail.querySelector("[data-resource-video]");
|
||||
const button = detail.querySelector("[data-resource-video-toggle]");
|
||||
if (!video || !button || button.disabled) return;
|
||||
button.hidden = !video.paused && !video.ended;
|
||||
button.textContent = video.currentTime > 0 && !video.ended ? "继续播放" : "播放视频";
|
||||
}
|
||||
|
||||
async function toggleVideo() {
|
||||
const song = currentSong();
|
||||
if (!song || !song.available.video) return;
|
||||
const detail = openPanel();
|
||||
const video = detail ? detail.querySelector("[data-resource-video]") : null;
|
||||
if (!video) return;
|
||||
if (!video.src) {
|
||||
video.src = video.dataset.videoUrl;
|
||||
video.load();
|
||||
}
|
||||
pauseOpenMedia(video);
|
||||
if (video.paused) {
|
||||
try {
|
||||
await video.play();
|
||||
} catch (error) {
|
||||
showToast("视频已加载,点播放器开始播放");
|
||||
}
|
||||
} else {
|
||||
video.pause();
|
||||
}
|
||||
updateVideoButton(detail);
|
||||
}
|
||||
|
||||
function formatTime(value) {
|
||||
if (!Number.isFinite(value) || value < 0) return "0:00";
|
||||
const minutes = Math.floor(value / 60);
|
||||
const seconds = Math.floor(value % 60);
|
||||
return `${minutes}:${String(seconds).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function updateAudioControls(detail) {
|
||||
const audio = detail.querySelector("[data-resource-audio]");
|
||||
const panel = detail.querySelector("[data-resource-panel='audio']");
|
||||
const button = detail.querySelector("[data-resource-audio-toggle]");
|
||||
const label = button.querySelector("strong");
|
||||
const progress = detail.querySelector("[data-resource-audio-progress]");
|
||||
const current = detail.querySelector("[data-resource-audio-current]");
|
||||
const duration = detail.querySelector("[data-resource-audio-duration]");
|
||||
const playing = !audio.paused && !audio.ended;
|
||||
panel.classList.toggle("playing", playing);
|
||||
label.textContent = playing ? "暂停音频" : audio.currentTime > 0 && !audio.ended ? "继续播放音频" : "播放音频";
|
||||
current.textContent = formatTime(audio.currentTime);
|
||||
duration.textContent = Number.isFinite(audio.duration) ? formatTime(audio.duration) : "--:--";
|
||||
progress.max = Number.isFinite(audio.duration) ? audio.duration : 0;
|
||||
progress.value = audio.currentTime || 0;
|
||||
}
|
||||
|
||||
async function toggleAudio() {
|
||||
const song = currentSong();
|
||||
if (!song || !song.available.audio) return;
|
||||
const detail = openPanel();
|
||||
const audio = detail ? detail.querySelector("[data-resource-audio]") : null;
|
||||
if (!audio) return;
|
||||
loadLazyImage(detail.querySelector("[data-resource-audio-art]"));
|
||||
if (!audio.src) {
|
||||
audio.src = audio.dataset.audioUrl;
|
||||
audio.load();
|
||||
}
|
||||
pauseOpenMedia(audio);
|
||||
if (audio.paused) {
|
||||
try {
|
||||
await audio.play();
|
||||
} catch (error) {
|
||||
showToast("音频已加载,点中间按钮开始播放");
|
||||
}
|
||||
} else {
|
||||
audio.pause();
|
||||
}
|
||||
updateAudioControls(detail);
|
||||
}
|
||||
|
||||
function bindList() {
|
||||
forEachNode(resourceElements.list.querySelectorAll("[data-song-id]"), (button) => {
|
||||
button.addEventListener("click", () => selectSong(button.dataset.songId));
|
||||
});
|
||||
const detail = openPanel();
|
||||
if (!detail) return;
|
||||
forEachNode(detail.querySelectorAll("[data-resource-mode]"), (tab) => {
|
||||
tab.addEventListener("click", () => changeMode(tab.dataset.resourceMode));
|
||||
});
|
||||
const video = detail.querySelector("[data-resource-video]");
|
||||
const videoButton = detail.querySelector("[data-resource-video-toggle]");
|
||||
videoButton.addEventListener("click", toggleVideo);
|
||||
video.addEventListener("play", () => updateVideoButton(detail));
|
||||
video.addEventListener("pause", () => updateVideoButton(detail));
|
||||
video.addEventListener("ended", () => updateVideoButton(detail));
|
||||
|
||||
const audioPanel = detail.querySelector("[data-resource-panel='audio']");
|
||||
const audio = detail.querySelector("[data-resource-audio]");
|
||||
const audioButton = detail.querySelector("[data-resource-audio-toggle]");
|
||||
audioButton.addEventListener("click", toggleAudio);
|
||||
audioPanel.addEventListener("click", (event) => {
|
||||
if (event.target.closest("[data-resource-audio-toggle], .audio-timeline")) return;
|
||||
toggleAudio();
|
||||
});
|
||||
["play", "pause", "timeupdate", "loadedmetadata", "ended"].forEach((eventName) => {
|
||||
audio.addEventListener(eventName, () => updateAudioControls(detail));
|
||||
});
|
||||
detail.querySelector("[data-resource-audio-progress]").addEventListener("input", (event) => {
|
||||
if (Number.isFinite(audio.duration)) audio.currentTime = Number(event.target.value);
|
||||
});
|
||||
if (resourceState.mode === "audio") loadLazyImage(detail.querySelector("[data-resource-audio-art]"));
|
||||
if (resourceState.mode === "lyrics") loadLazyImage(detail.querySelector("[data-resource-lyrics]"));
|
||||
}
|
||||
|
||||
function refreshList() {
|
||||
stopOpenMedia();
|
||||
renderList();
|
||||
}
|
||||
|
||||
let toastTimer;
|
||||
function showToast(message) {
|
||||
resourceElements.toast.textContent = message;
|
||||
resourceElements.toast.classList.add("visible");
|
||||
clearTimeout(toastTimer);
|
||||
toastTimer = window.setTimeout(() => resourceElements.toast.classList.remove("visible"), 2400);
|
||||
}
|
||||
|
||||
async function loadCatalog() {
|
||||
const response = await fetch("/api/resources");
|
||||
if (!response.ok) throw new Error("无法读取资源目录");
|
||||
resourceState.catalog = await response.json();
|
||||
renderSummary();
|
||||
populateWeeks();
|
||||
renderList();
|
||||
}
|
||||
|
||||
resourceElements.search.addEventListener("input", refreshList);
|
||||
resourceElements.weekFilter.addEventListener("change", refreshList);
|
||||
resourceElements.availabilityFilter.addEventListener("change", refreshList);
|
||||
|
||||
loadCatalog().catch((error) => {
|
||||
resourceElements.total.textContent = error.message;
|
||||
showToast(error.message);
|
||||
});
|
||||
@@ -0,0 +1,522 @@
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.stats-shell {
|
||||
width: calc(100% - 32px);
|
||||
max-width: 1180px;
|
||||
width: min(1180px, calc(100% - 32px));
|
||||
margin: 0 auto;
|
||||
padding-bottom: 60px;
|
||||
}
|
||||
|
||||
.stats-topbar {
|
||||
min-height: 160px;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.stats-topbar h1 {
|
||||
margin: 0;
|
||||
font-size: 50px;
|
||||
font-size: clamp(38px, 7vw, 66px);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stats-topbar .eyebrow {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
justify-self: start;
|
||||
padding: 10px 14px;
|
||||
border-radius: 13px;
|
||||
color: var(--ink);
|
||||
background: rgba(255, 253, 248, 0.78);
|
||||
text-decoration: none;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.updated-at {
|
||||
justify-self: end;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.summary-cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(6, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.summary-card {
|
||||
min-height: 130px;
|
||||
padding: 19px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.9);
|
||||
border-radius: 22px;
|
||||
background: rgba(255, 253, 248, 0.88);
|
||||
box-shadow: 0 12px 32px rgba(78, 62, 38, 0.07);
|
||||
}
|
||||
|
||||
.summary-card:nth-child(1),
|
||||
.summary-card:nth-child(4) {
|
||||
background: rgba(223, 238, 231, 0.88);
|
||||
}
|
||||
|
||||
.summary-card:nth-child(2),
|
||||
.summary-card:nth-child(5) {
|
||||
background: rgba(255, 241, 220, 0.9);
|
||||
}
|
||||
|
||||
.summary-card strong,
|
||||
.summary-card span {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.summary-card strong {
|
||||
margin-top: 22px;
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.summary-card span {
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.stats-section {
|
||||
padding-top: 56px;
|
||||
}
|
||||
|
||||
.stats-heading {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
justify-content: space-between;
|
||||
gap: 18px;
|
||||
margin-bottom: 19px;
|
||||
}
|
||||
|
||||
.legend {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.legend i {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 4px;
|
||||
background: var(--sage);
|
||||
}
|
||||
|
||||
.calendar-card {
|
||||
padding: 18px;
|
||||
border-radius: 24px;
|
||||
background: rgba(255, 253, 248, 0.84);
|
||||
box-shadow: 0 12px 34px rgba(78, 62, 38, 0.07);
|
||||
}
|
||||
|
||||
.weekday-row,
|
||||
.daily-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.weekday-row {
|
||||
margin-bottom: 8px;
|
||||
color: var(--muted);
|
||||
text-align: center;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.day-cell {
|
||||
min-height: 72px;
|
||||
padding: 9px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 15px;
|
||||
background: rgba(37, 50, 45, 0.025);
|
||||
}
|
||||
|
||||
.day-cell.active {
|
||||
border-color: rgba(118, 168, 150, 0.35);
|
||||
background: var(--sage-soft);
|
||||
}
|
||||
|
||||
.day-cell strong,
|
||||
.day-cell span {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.day-cell strong {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.day-cell span {
|
||||
margin-top: 9px;
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.daily-list {
|
||||
display: grid;
|
||||
gap: 9px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.daily-row {
|
||||
display: grid;
|
||||
grid-template-columns: 100px repeat(4, 1fr);
|
||||
gap: 12px;
|
||||
padding: 13px 16px;
|
||||
border-radius: 16px;
|
||||
background: rgba(255, 253, 248, 0.72);
|
||||
}
|
||||
|
||||
.daily-row strong {
|
||||
color: var(--peach-dark);
|
||||
}
|
||||
|
||||
.daily-row span {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.stats-week-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.stats-week-card {
|
||||
padding: 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 18px;
|
||||
background: rgba(255, 253, 248, 0.76);
|
||||
}
|
||||
|
||||
.stats-week-card.review {
|
||||
background: rgba(223, 238, 231, 0.66);
|
||||
}
|
||||
|
||||
.stats-week-card.active {
|
||||
border-color: rgba(245, 166, 91, 0.55);
|
||||
box-shadow: 0 7px 19px rgba(217, 121, 53, 0.09);
|
||||
}
|
||||
|
||||
.stats-week-card header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.stats-week-card header strong {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.stats-week-card header span {
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.week-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 7px;
|
||||
margin-top: 12px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.two-column {
|
||||
display: grid;
|
||||
grid-template-columns: 0.8fr 1.2fr;
|
||||
gap: 28px;
|
||||
}
|
||||
|
||||
.actor-stats,
|
||||
.session-list {
|
||||
display: grid;
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
.actor-card,
|
||||
.session-card {
|
||||
padding: 14px 16px;
|
||||
border-radius: 17px;
|
||||
background: rgba(255, 253, 248, 0.78);
|
||||
}
|
||||
|
||||
.actor-card header,
|
||||
.session-card header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.actor-card p,
|
||||
.session-card p {
|
||||
margin: 8px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.song-search input {
|
||||
width: min(300px, 48vw);
|
||||
min-height: 44px;
|
||||
padding: 10px 13px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 14px;
|
||||
color: var(--ink);
|
||||
background: rgba(255, 253, 248, 0.9);
|
||||
}
|
||||
|
||||
.song-table-wrap {
|
||||
overflow-x: auto;
|
||||
border-radius: 22px;
|
||||
background: rgba(255, 253, 248, 0.84);
|
||||
box-shadow: 0 12px 34px rgba(78, 62, 38, 0.07);
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
min-width: 900px;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
padding: 13px 15px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
th {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
color: var(--muted);
|
||||
background: #f3eee3;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
td {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
td strong,
|
||||
td small {
|
||||
display: block;
|
||||
}
|
||||
|
||||
td small {
|
||||
margin-top: 4px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.stats-empty {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
inset: 0;
|
||||
z-index: 10;
|
||||
display: grid;
|
||||
place-content: center;
|
||||
justify-items: center;
|
||||
padding: 28px;
|
||||
background: var(--cream);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stats-empty[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.stats-empty > span {
|
||||
width: 78px;
|
||||
height: 78px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
margin-bottom: 18px;
|
||||
border-radius: 26px;
|
||||
color: white;
|
||||
background: var(--peach);
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
.stats-empty p {
|
||||
max-width: 420px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.stats-empty .primary-button {
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
margin-top: 8px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.summary-cards {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
.stats-week-grid {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
|
||||
.two-column {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 620px) {
|
||||
.stats-shell {
|
||||
width: min(calc(100% - 22px), 580px);
|
||||
}
|
||||
|
||||
.stats-topbar {
|
||||
min-height: 128px;
|
||||
grid-template-columns: 1fr auto;
|
||||
}
|
||||
|
||||
.stats-topbar > div {
|
||||
grid-column: 1 / -1;
|
||||
grid-row: 1;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
grid-column: 1;
|
||||
grid-row: 2;
|
||||
}
|
||||
|
||||
.updated-at {
|
||||
grid-column: 2;
|
||||
grid-row: 2;
|
||||
}
|
||||
|
||||
.summary-cards {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.summary-card {
|
||||
min-height: 110px;
|
||||
}
|
||||
|
||||
.summary-card strong {
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.stats-section {
|
||||
padding-top: 42px;
|
||||
}
|
||||
|
||||
.calendar-card {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.weekday-row,
|
||||
.daily-grid {
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.day-cell {
|
||||
min-height: 58px;
|
||||
padding: 6px;
|
||||
border-radius: 11px;
|
||||
}
|
||||
|
||||
.day-cell span {
|
||||
margin-top: 5px;
|
||||
font-size: 9px;
|
||||
}
|
||||
|
||||
.daily-row {
|
||||
grid-template-columns: 82px repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.daily-row span:nth-last-child(-n + 2) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.stats-week-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.song-heading-row {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.song-search input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.song-table-wrap {
|
||||
overflow: visible;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
table,
|
||||
tbody {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
tbody {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
tbody tr {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 7px 12px;
|
||||
padding: 15px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 17px;
|
||||
background: rgba(255, 253, 248, 0.82);
|
||||
}
|
||||
|
||||
tbody td {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
tbody td:first-child {
|
||||
display: block;
|
||||
grid-column: 1 / -1;
|
||||
padding-bottom: 7px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
tbody td[data-label]::before {
|
||||
content: attr(data-label);
|
||||
color: var(--muted);
|
||||
font-size: 10px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#f5a65b" />
|
||||
<link rel="icon" href="/static/icon.svg" type="image/svg+xml" />
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
<link rel="stylesheet" href="/static/stats.css" />
|
||||
<title>SSS 红花与播放统计</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="stats-shell">
|
||||
<header class="stats-topbar">
|
||||
<a class="back-link" href="/" aria-label="返回播放器">‹ 返回播放</a>
|
||||
<div>
|
||||
<p class="eyebrow">家长查看</p>
|
||||
<h1>红花统计</h1>
|
||||
</div>
|
||||
<span id="updated-at" class="updated-at">正在更新…</span>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section id="summary-cards" class="summary-cards" aria-label="总体统计"></section>
|
||||
|
||||
<section class="stats-section" aria-labelledby="daily-heading">
|
||||
<div class="stats-heading">
|
||||
<div>
|
||||
<p class="eyebrow">最近六周</p>
|
||||
<h2 id="daily-heading">每天红花情况</h2>
|
||||
</div>
|
||||
<span class="legend"><i></i> 有红花</span>
|
||||
</div>
|
||||
<div class="calendar-card">
|
||||
<div class="weekday-row" aria-hidden="true">
|
||||
<span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span>六</span><span>日</span>
|
||||
</div>
|
||||
<div id="daily-grid" class="daily-grid"></div>
|
||||
</div>
|
||||
<div id="daily-list" class="daily-list"></div>
|
||||
</section>
|
||||
|
||||
<section class="stats-section" aria-labelledby="week-heading">
|
||||
<div class="stats-heading">
|
||||
<div>
|
||||
<p class="eyebrow">完整计划</p>
|
||||
<h2 id="week-heading">50 周学习情况</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div id="stats-week-grid" class="stats-week-grid"></div>
|
||||
</section>
|
||||
|
||||
<section class="stats-section two-column" aria-label="家庭成员与打卡时段">
|
||||
<div>
|
||||
<div class="stats-heading">
|
||||
<div>
|
||||
<p class="eyebrow">操作记录</p>
|
||||
<h2>家庭成员</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div id="actor-stats" class="actor-stats"></div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="stats-heading">
|
||||
<div>
|
||||
<p class="eyebrow">最近记录</p>
|
||||
<h2>最近小红花</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div id="session-list" class="session-list"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="stats-section" aria-labelledby="song-heading">
|
||||
<div class="stats-heading song-heading-row">
|
||||
<div>
|
||||
<p class="eyebrow">逐首查看</p>
|
||||
<h2 id="song-heading">每首歌的播放与红花</h2>
|
||||
</div>
|
||||
<label class="song-search">
|
||||
<span class="sr-only">搜索歌曲</span>
|
||||
<input id="song-search" type="search" placeholder="搜索歌名或编号" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="song-table-wrap">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>歌曲</th>
|
||||
<th>视频完成/开始</th>
|
||||
<th>音频完成/开始</th>
|
||||
<th>小红花</th>
|
||||
<th>操作者</th>
|
||||
<th>最近播放</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="song-table-body"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<div id="stats-empty" class="stats-empty" hidden>
|
||||
<span aria-hidden="true">♫</span>
|
||||
<h2>还没有红花记录</h2>
|
||||
<p>完整播放第一首歌并领取小红花后,这里就会出现成长统计。</p>
|
||||
<a class="primary-button" href="/">返回播放器</a>
|
||||
</div>
|
||||
|
||||
<script src="/static/stats.js" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
const elements = {
|
||||
updatedAt: document.querySelector("#updated-at"),
|
||||
summaryCards: document.querySelector("#summary-cards"),
|
||||
dailyGrid: document.querySelector("#daily-grid"),
|
||||
dailyList: document.querySelector("#daily-list"),
|
||||
weekGrid: document.querySelector("#stats-week-grid"),
|
||||
actorStats: document.querySelector("#actor-stats"),
|
||||
sessionList: document.querySelector("#session-list"),
|
||||
songSearch: document.querySelector("#song-search"),
|
||||
songTableBody: document.querySelector("#song-table-body"),
|
||||
empty: document.querySelector("#stats-empty"),
|
||||
};
|
||||
|
||||
let statistics = null;
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value == null ? "" : value)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function formatDateTime(value) {
|
||||
if (!value) return "—";
|
||||
return new Intl.DateTimeFormat("zh-CN", {
|
||||
month: "numeric",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
function formatDay(value) {
|
||||
const date = new Date(`${value}T12:00:00`);
|
||||
return `${date.getMonth() + 1}/${date.getDate()}`;
|
||||
}
|
||||
|
||||
async function loadStatistics() {
|
||||
const response = await fetch("/api/statistics");
|
||||
if (!response.ok) throw new Error("无法读取统计数据");
|
||||
statistics = await response.json();
|
||||
render();
|
||||
}
|
||||
|
||||
function render() {
|
||||
const { summary } = statistics;
|
||||
elements.updatedAt.textContent = `更新于 ${formatDateTime(statistics.generated_at)}`;
|
||||
elements.empty.hidden = summary.video_plays + summary.audio_plays > 0;
|
||||
renderSummary();
|
||||
renderDaily();
|
||||
renderWeeks();
|
||||
renderActors();
|
||||
renderSessions();
|
||||
renderSongs(elements.songSearch.value);
|
||||
}
|
||||
|
||||
function renderSummary() {
|
||||
const summary = statistics.summary;
|
||||
const cards = [
|
||||
["获得小红花", summary.checkins, "朵"],
|
||||
["完成整轮", summary.round_checkins, "轮"],
|
||||
["学习天数", summary.active_days, "天"],
|
||||
["连续学习", summary.streak, "天"],
|
||||
["视频完整播放", summary.video_plays, "次"],
|
||||
["音频完整播放", summary.audio_plays, "次"],
|
||||
];
|
||||
elements.summaryCards.innerHTML = cards
|
||||
.map(
|
||||
([label, value, unit]) => `
|
||||
<article class="summary-card">
|
||||
<span>${escapeHtml(label)}</span>
|
||||
<strong>${escapeHtml(value)} <small>${escapeHtml(unit)}</small></strong>
|
||||
</article>`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
function renderDaily() {
|
||||
elements.dailyGrid.innerHTML = statistics.daily
|
||||
.map((day) => {
|
||||
const active = day.checkins > 0;
|
||||
const details = active
|
||||
? `${day.checkins} 朵红花 · ${day.video_plays + day.audio_plays} 次播放`
|
||||
: "没有红花";
|
||||
return `
|
||||
<div class="day-cell ${active ? "active" : ""}" title="${escapeHtml(day.date)} ${details}">
|
||||
<strong>${formatDay(day.date)}</strong>
|
||||
<span>${active ? `${day.checkins} 朵` : "—"}</span>
|
||||
</div>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
const activeDays = statistics.daily.slice().reverse().filter((day) => day.checkins || day.video_plays || day.audio_plays);
|
||||
elements.dailyList.innerHTML = activeDays.length
|
||||
? activeDays
|
||||
.slice(0, 12)
|
||||
.map(
|
||||
(day) => `
|
||||
<div class="daily-row">
|
||||
<strong>${formatDay(day.date)}</strong>
|
||||
<span>${day.checkins} 朵红花</span>
|
||||
<span>${day.video_plays} 次视频</span>
|
||||
<span>${day.audio_plays} 次音频</span>
|
||||
<span>${escapeHtml(day.actors.join("、") || "—")}</span>
|
||||
</div>`,
|
||||
)
|
||||
.join("")
|
||||
: '<div class="daily-row"><strong>暂无</strong><span>完整播放后自动生成</span></div>';
|
||||
}
|
||||
|
||||
function renderWeeks() {
|
||||
elements.weekGrid.innerHTML = statistics.weeks
|
||||
.map((week) => {
|
||||
const active = week.video_plays + week.audio_plays > 0;
|
||||
return `
|
||||
<article class="stats-week-card ${week.kind} ${active ? "active" : ""}">
|
||||
<header>
|
||||
<strong>第 ${week.number} 周</strong>
|
||||
<span>${week.kind === "review" ? "复习" : escapeHtml(week.category || "课程")}</span>
|
||||
</header>
|
||||
<div class="week-metrics">
|
||||
<span>${week.checkins} 红花</span>
|
||||
<span>${week.active_days} 天</span>
|
||||
<span>${week.video_plays} 视频</span>
|
||||
<span>${week.audio_plays} 音频</span>
|
||||
</div>
|
||||
</article>`;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
|
||||
function renderActors() {
|
||||
elements.actorStats.innerHTML = statistics.actors.length
|
||||
? statistics.actors
|
||||
.map(
|
||||
(actor) => `
|
||||
<article class="actor-card">
|
||||
<header><strong>${escapeHtml(actor.actor)}</strong><span>${actor.checkins_started} 朵红花</span></header>
|
||||
<p>${actor.video_plays} 次视频 · ${actor.audio_plays} 次音频</p>
|
||||
</article>`,
|
||||
)
|
||||
.join("")
|
||||
: '<article class="actor-card"><strong>暂无操作记录</strong></article>';
|
||||
}
|
||||
|
||||
function renderSessions() {
|
||||
elements.sessionList.innerHTML = statistics.recent_sessions.length
|
||||
? statistics.recent_sessions
|
||||
.slice(0, 12)
|
||||
.map(
|
||||
(session) => `
|
||||
<article class="session-card">
|
||||
<header><strong>${formatDateTime(session.started_at)}</strong><span>${escapeHtml(session.actor)}获得</span></header>
|
||||
<p>${session.kind === "round" ? "完成整轮小红花" : `${escapeHtml(session.songs.join("、"))} 歌曲小红花`}</p>
|
||||
</article>`,
|
||||
)
|
||||
.join("")
|
||||
: '<article class="session-card"><strong>暂无小红花</strong></article>';
|
||||
}
|
||||
|
||||
function renderSongs(query = "") {
|
||||
const needle = query.trim().toLowerCase();
|
||||
const songs = statistics.songs.filter(
|
||||
(song) => !needle || song.id.includes(needle) || song.title.toLowerCase().includes(needle),
|
||||
);
|
||||
elements.songTableBody.innerHTML = songs
|
||||
.map(
|
||||
(song) => `
|
||||
<tr>
|
||||
<td><strong>${escapeHtml(song.title)}</strong><small>${escapeHtml(song.id)} · 第 ${song.week} 周</small></td>
|
||||
<td data-label="视频 完成/开始">${song.video_plays} / ${song.video_starts}</td>
|
||||
<td data-label="音频 完成/开始">${song.audio_plays} / ${song.audio_starts}</td>
|
||||
<td data-label="小红花">${song.checkins}</td>
|
||||
<td data-label="操作者">${escapeHtml(song.actors.join("、") || "—")}</td>
|
||||
<td data-label="最近播放">${formatDateTime(song.last_played_at)}</td>
|
||||
</tr>`,
|
||||
)
|
||||
.join("");
|
||||
}
|
||||
|
||||
elements.songSearch.addEventListener("input", () => renderSongs(elements.songSearch.value));
|
||||
loadStatistics().catch((error) => {
|
||||
elements.updatedAt.textContent = error.message;
|
||||
});
|
||||
+2169
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user