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
@@ -0,0 +1,8 @@
|
|||||||
|
.DS_Store
|
||||||
|
.git
|
||||||
|
.local-data
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
source
|
||||||
|
tests
|
||||||
|
docs
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Confirm these two server-side paths in Synology DSM before deployment.
|
||||||
|
SSS_ASSET_PATH=/volume1/study/Assets/SSS50
|
||||||
|
SSS_DATA_PATH=/volume1/docker/sss-checkin/data
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.DS_Store
|
||||||
|
.local-data/
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.env
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
FROM python:3.12-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# The one-key weekly audio loop is composed lazily when first requested.
|
||||||
|
# Keep ffmpeg in the NAS image so this also works after moving off the Mac.
|
||||||
|
RUN apk add --no-cache ffmpeg
|
||||||
|
|
||||||
|
COPY app.py curriculum.json ./
|
||||||
|
COPY public ./public
|
||||||
|
|
||||||
|
ENV HOST=0.0.0.0 \
|
||||||
|
PORT=8000 \
|
||||||
|
ASSET_ROOT=/assets \
|
||||||
|
DATA_DIR=/data \
|
||||||
|
PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
VOLUME ["/data"]
|
||||||
|
|
||||||
|
CMD ["python", "app.py"]
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
# SSS 50周局域网自动打卡工具
|
||||||
|
|
||||||
|
面向家庭手机浏览器的局域网应用。应用直接读取 NAS 上同一套课程的视频、音频和歌词图片;歌曲完整播放后记录播放并解锁小红花,让宝宝保留亲手打卡的快乐。
|
||||||
|
|
||||||
|
## 当前功能
|
||||||
|
|
||||||
|
- 50 周课程、100 首歌曲,视频、音频、歌词按课程编号自动匹配。
|
||||||
|
- 本周每首歌都有一张独立媒体卡,视频、音频、歌词在各自卡片内切换,不再通过统一播放器切歌。
|
||||||
|
- 同一张歌曲卡片切换视频、音频或歌词标签时不会暂停正在播放的媒体,因此可以一边听音频或视频,一边打开歌词查看;只有主动播放另一种媒体或另一首歌时才切换声源。
|
||||||
|
- 视频与音频画面固定为相同的 16:9 尺寸;音频点击画面中央即可播放或暂停,进度条收在画面底部,切换时页面不跳动。
|
||||||
|
- 成长足迹下方提供“播放本周音频”控制:从第一首开始依次播放整周歌单,播完最后一首后从头循环;直接播放某张歌曲卡片时,则自动单曲循环当前视频或音频。
|
||||||
|
- 歌词在主页面原位展示,不会把宝宝带到新页面。
|
||||||
|
- 单宝宝模式,没有孩子档案切换。
|
||||||
|
- 每台设备首次选择“宝宝、爸爸、妈妈、爷爷、奶奶、外公、外婆”,以后自动记住;右上角只显示当前角色,点击即可切换。
|
||||||
|
- 开课日期固定为 2026 年 10 月 12 日,每 7 天自动进入下一周;每次打开默认显示今天对应的课程周。
|
||||||
|
- 上一周、下一周和 50 周课程地图可以独立浏览全部周次:过去周可以补学习,未来周可以提前试听,但预习播放不会提前解锁任何歌曲或整轮红花。
|
||||||
|
- 每次完整播放计一次播放并解锁一次领取资格;每首歌每天最多领取 3 朵小红花,按“上午领取、下午领取、晚上领取”大尺寸展示,同一首歌默认间隔 60 分钟。
|
||||||
|
- 每完成一轮本周歌单,就会解锁 1 朵整轮大红花;每天最多 3 轮,宝宝可亲手领取,页面直接提示需听完全部歌曲。歌曲或整轮奖励若已满足条件却没有领取,会在下次进入时自动补记并播放奖励动画。
|
||||||
|
- 自动补领会检查所有学习日期:即使补学后跨天重新打开,已经完成的努力也不会漏掉。
|
||||||
|
- 首页展示连续 14 天成长日历,固定为 2 行 × 7 天;今天永远位于第二行最后一格,星期标题随日期动态变化。过去日期可直接进入补学习、补红花。
|
||||||
|
- 歌曲红花和整轮红花均提供大尺寸点击区域;尚未满足条件、仍在冷却或已经领取时,点击会直接说明原因。
|
||||||
|
- 多台设备可以同时使用:每台设备记录自己的身份,领取请求由 SQLite 事务串行处理;歌曲及整轮的一小时领取间隔按家庭共享,避免两个设备重复领取。
|
||||||
|
- 播放和红花都保留实际时间、学习日期、设备身份、歌曲、课程周和媒体类型。
|
||||||
|
- 设置中可进入统计页,查看最近 42 天、完整 50 周、每首歌、每位操作者和最近红花。
|
||||||
|
- 家长设置入口位于页面最底部,避免宝宝误触;开始学习日期仅灰色展示,不允许修改。
|
||||||
|
- 设置中可进入全部资源库,搜索或按周筛选 100 首歌;点击歌曲卡片后在卡片下方展开视频、音频和歌词,切换歌曲时上一张会自动收起。主页与资源库的视频都只有点击播放后才从 NAS 读取。
|
||||||
|
- SQLite 保存记录;NAS 资源目录以只读方式挂载。
|
||||||
|
|
||||||
|
## 在 Mac 上运行
|
||||||
|
|
||||||
|
当前 Mac 使用已登录用户的后台会话常驻运行,以保留对 NAS SMB 挂载 `/Volumes/study` 的读取权限。服务异常退出后会在两秒后自动重新启动;正常情况下不需要保持 Codex 或终端窗口打开。
|
||||||
|
|
||||||
|
|
||||||
|
常用检查命令:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./scripts/local_server.sh status
|
||||||
|
./scripts/local_server.sh logs
|
||||||
|
```
|
||||||
|
|
||||||
|
启动或停止服务:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /Users/optimx/CODE/nas/project_sss
|
||||||
|
./scripts/local_server.sh start
|
||||||
|
./scripts/local_server.sh stop
|
||||||
|
```
|
||||||
|
|
||||||
|
打开 <http://127.0.0.1:8787>。同一局域网的手机使用这台 Mac 的局域网 IP,例如 `http://192.168.50.x:8787`。
|
||||||
|
|
||||||
|
## 在群晖上部署
|
||||||
|
|
||||||
|
详细步骤见 [群晖部署说明](docs/群晖部署说明.md)。群晖容器必须使用群晖本机路径,不能直接使用 Mac 的 `/Volumes/...` 路径。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
docker compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
默认访问地址为 `http://群晖IP:8787`。
|
||||||
|
|
||||||
|
## 测试
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 -m unittest discover -s tests -v
|
||||||
|
```
|
||||||
|
|
||||||
|
## 目录
|
||||||
|
|
||||||
|
- `app.py`:HTTP 服务、自动打卡、统计、SQLite 和媒体 Range 流式传输。
|
||||||
|
- `curriculum.json`:从课程表与统一资源目录生成的映射。
|
||||||
|
- `public/`:宝宝友好的主页面,以及家长统计页和全部资源库。
|
||||||
|
- `source/`:课程 Excel 的项目内副本。
|
||||||
|
- `scripts/build_curriculum.py`:重新扫描视频、音频、歌词并生成课程数据。
|
||||||
|
- `docs/`:产品规则和群晖部署说明。
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
sss-checkin:
|
||||||
|
build: .
|
||||||
|
container_name: sss-checkin
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8787:8000"
|
||||||
|
environment:
|
||||||
|
TZ: Asia/Shanghai
|
||||||
|
ASSET_ROOT: /assets
|
||||||
|
DATA_DIR: /data
|
||||||
|
volumes:
|
||||||
|
- "${SSS_ASSET_PATH:-/volume1/study/Assets/SSS50}:/assets:ro"
|
||||||
|
- "${SSS_DATA_PATH:-/volume1/docker/sss-checkin/data}:/data"
|
||||||
+1177
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
|||||||
|
-- Run this once in Synology phpMyAdmin as a MariaDB administrator.
|
||||||
|
-- This creates only the isolated database. The application account is created
|
||||||
|
-- separately after the SSS service's final network location is decided.
|
||||||
|
|
||||||
|
CREATE DATABASE IF NOT EXISTS `sss_checkin`
|
||||||
|
CHARACTER SET utf8mb4
|
||||||
|
COLLATE utf8mb4_unicode_ci;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# SSS MariaDB bootstrap
|
||||||
|
|
||||||
|
Run `01-create-sss-database.sql` in Synology phpMyAdmin using a MariaDB
|
||||||
|
administrator. It creates the dedicated `sss_checkin` database with UTF-8
|
||||||
|
support suitable for the Chinese interface and role names.
|
||||||
|
|
||||||
|
Do not create an application account with host `%`. The account and grants
|
||||||
|
must be created after the SSS application has been migrated from SQLite and
|
||||||
|
its final location is known. The intended final layout is the SSS service and
|
||||||
|
MariaDB both on the NAS, so the account can be restricted to that application
|
||||||
|
network rather than opened to every LAN device.
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
# SSS 50周打卡工具产品设计
|
||||||
|
|
||||||
|
## 核心体验
|
||||||
|
|
||||||
|
宝宝在主页面完成所有日常操作:看视频、听音频、看歌词和领取红花。每首歌有自己的媒体卡,不需要先选歌;只有家长从设置中主动进入统计页或资源库时才离开主页面。
|
||||||
|
|
||||||
|
系统只维护一个宝宝的学习进度,不再提供多孩子档案。
|
||||||
|
|
||||||
|
## 身份与设备
|
||||||
|
|
||||||
|
- 首次访问必须选择当前设备对应的身份:宝宝、爸爸、妈妈、爷爷、奶奶、外公、外婆。
|
||||||
|
- 浏览器生成并保存设备标识,服务器保存“设备标识 → 身份”的映射。
|
||||||
|
- 以后从同一浏览器访问时自动恢复身份。
|
||||||
|
- 点击右上角当前角色会打开角色切换,修改后更新设备映射;已有历史播放仍保留播放发生时的身份,不随映射变化。
|
||||||
|
- 清除浏览器网站数据或更换浏览器后,会被视为新设备,需要重新选择身份。
|
||||||
|
|
||||||
|
## 播放与小红花打卡
|
||||||
|
|
||||||
|
- 每首歌独立展示“视频 / 音频 / 歌词”三个标签,从上到下依次排列,不再使用一个公共播放器切歌。
|
||||||
|
- 视频和音频共用相同的 16:9 媒体框尺寸;切换两种模式时,页面高度和后续内容位置保持不变。
|
||||||
|
- 音频点击画面中央即可播放或暂停,自定义进度条位于画面底部,不再额外占用一行,也不提供上一首、下一首按钮。
|
||||||
|
- 点击某一张歌曲卡片的视频或音频后,该媒体自动单曲循环;成长足迹下方另设整周音频播放控制,从第一首开始依次播放,最后一首结束后回到第一首循环。
|
||||||
|
- 歌词是每首歌对应的一张图片,可在媒体卡内原位查看;歌词允许按图片内容改变高度并滚动。
|
||||||
|
- 媒体标签只改变当前看见的面板,不暂停同一首正在播放的视频或音频;因此打开歌词时声音继续。只有主动播放另一种媒体或另一首歌时,才暂停原声源。
|
||||||
|
- 播放开始时建立记录,只有播放器触发完整播放结束后才计为一次完成播放,并解锁该歌曲的一次红花领取资格。
|
||||||
|
- 每首歌在每个学习日最多有 3 朵红花;一遍完整播放只能兑换其中一朵。
|
||||||
|
- 同一首歌相邻两次领取默认至少间隔 60 分钟,设置中可选 30、60、90 或 120 分钟;不同歌曲互不占用彼此的间隔。
|
||||||
|
- 孩子可以亲手点击每张歌曲卡片下方正在跳动的大尺寸红花领取奖励,并看到居中的红花、光圈、闪光和花瓣动画。
|
||||||
|
- 红花未解锁、冷却尚未结束、前一朵未领取或已经领取时,按钮仍可点击并明确说明原因。
|
||||||
|
- 若已有资格但离开页面时没有点击,下次进入时系统会检查全部历史学习日并自动补记,同时播放“努力没有漏掉”的补领仪式;补学后跨天也不会遗漏。
|
||||||
|
- 主页面和资源库的视频都使用按需读取:打开页面或切换标签不会设置视频地址,只有点击播放才向 NAS 请求视频数据。主页音频也只在点击播放后读取。
|
||||||
|
- 当前歌单全部歌曲至少完整播放一遍后,解锁第一朵整轮红花;全部歌曲分别完成第二遍、第三遍后继续解锁第二、第三朵。孩子在歌单下方亲手领取,每个学习日最多 3 朵。
|
||||||
|
- 整轮红花沿用领取间隔。多台设备并发领取时,由数据库事务和唯一约束串行裁决;冷却按整个家庭共享,后到的请求会收到已经领取或仍在冷却的提示。
|
||||||
|
- 每个完成播放保存:歌曲、课程周、学习日期、视频或音频、开始时间、完成时间、时长、设备和身份。
|
||||||
|
|
||||||
|
## 课程规则
|
||||||
|
|
||||||
|
- 保留原始课程表的 50 周结构,共 100 首唯一歌曲。
|
||||||
|
- 开课日期固定为 2026 年 10 月 12 日;当天至第 7 天为第 1 周,之后每 7 天自动进入下一周,超过计划长度时停留在第 50 周。
|
||||||
|
- 每次打开主页默认显示今天对应的课程周,不依赖手工推进。
|
||||||
|
- 周次浏览与成长日历解耦:上一周、下一周和 50 周地图都能进入任意周。过去周进入补学习;未来周显示为提前试听,允许播放但不产生红花领取资格,预习记录也不会在未来自动转成打卡。
|
||||||
|
- 学习周直接列出本周歌曲。
|
||||||
|
- 复习周列出其指定范围内的学习周歌曲,例如第 5 周展示第 1–4 周共 12 首歌。
|
||||||
|
- 成长日历展示截至今天的连续 14 天,固定为 2 行 × 7 天;今天始终位于第二行第 7 列,星期标题根据今天动态平移。整轮完成、部分学习、遗漏待补和开课前日期有明显不同的视觉状态。
|
||||||
|
- 点击开课日之后、今天之前的日期会进入补学习模式;播放和红花记在所选学习日期,同时保留真实操作时间。
|
||||||
|
- 50 周网格中只能进入已经开始的周,点击后选择该周的第一天作为补学日期。
|
||||||
|
|
||||||
|
## 页面结构
|
||||||
|
|
||||||
|
### 主页面
|
||||||
|
|
||||||
|
- 顶部:标题为“SSS 50 周打卡”,右侧只显示当前设备角色;点击角色只进入角色切换,不打开设置。
|
||||||
|
- 周概览:当前周、今日红花数、今日完成播放次数、前后周切换。
|
||||||
|
- 十四天成长:2 行 × 7 天的红花与学习进度,遗漏日期可直接点入补学。
|
||||||
|
- 播放模式:成长足迹下方的一键控制负责整周音频顺序循环,并显示当前歌曲与暂停状态。
|
||||||
|
- 歌曲媒体卡:本周每首歌一张卡片,显示歌名、视频/音频/歌词标签、固定尺寸媒体框和卡片下方 3 个大红花;红花占据卡片中部约一半宽度,下方分别标注上午领取、下午领取、晚上领取,可领取时轻微跳动。
|
||||||
|
- 整轮奖励:歌单下方摆放占据约 85% 宽度的 3 朵大花,并提示需要把当前歌单全部听完才能领取;完成对应轮次后点亮,由宝宝亲手领取。
|
||||||
|
- 50 周地图:快速查看和切换课程周。
|
||||||
|
- 页面底部:单独放置齿轮设置入口;开课日期灰色只读,避免宝宝或家长误改。
|
||||||
|
|
||||||
|
### 统计页面
|
||||||
|
|
||||||
|
- 最近 42 天日历和逐日播放、红花、时长、操作者。
|
||||||
|
- 50 周完成播放、红花、活跃天和覆盖歌曲统计。
|
||||||
|
- 每首歌的视频/音频开始次数、完成次数、红花数、操作者和最后播放时间。
|
||||||
|
- 每位操作者的完成播放与领取红花次数。
|
||||||
|
- 最近歌曲红花和整轮红花的时间、歌曲及操作者。
|
||||||
|
|
||||||
|
### 全部资源库
|
||||||
|
|
||||||
|
- 从家长设置进入,集中列出 100 首唯一歌曲的编号、原始周次、主题和三类资源完整状态。
|
||||||
|
- 支持按歌名、编号、主题和文件名搜索,并可按周次或资源是否齐全筛选。
|
||||||
|
- 初始只展示歌曲卡片;点击一首歌后,直接在该卡片下方展开“视频 / 音频 / 歌词”面板,点击另一首时自动收起上一首,页面不再保留固定在顶部的公共播放器。
|
||||||
|
- 展开面板沿用首页的 16:9 播放样式,只展示视频、音频和歌词,不再显示独立资料页或真实文件名。
|
||||||
|
- 视频和音频均不在列表或展开时预读;只有家长点击播放后才读取单个文件。歌词也只在打开歌词标签时加载。
|
||||||
|
- 资源库用于家长查找和试听,不产生课程播放或红花记录,避免预览资源误触发宝宝打卡。
|
||||||
|
|
||||||
|
## 数据与安全边界
|
||||||
|
|
||||||
|
- 资源入口固定为一个根目录,其下为 `视频/`、`音频/`、`歌词/`。
|
||||||
|
- 应用按稳定的 `周次-序号` 匹配三种资源,不修改或复制原文件。
|
||||||
|
- 资源目录只读挂载;应用只写自己的 SQLite 数据库。
|
||||||
|
- 仅为家庭局域网设计,不提供公网认证,不应直接暴露到互联网。
|
||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
# 群晖部署说明
|
||||||
|
|
||||||
|
## 前提
|
||||||
|
|
||||||
|
- 群晖已安装 Container Manager,或系统可运行 Docker Compose。
|
||||||
|
- 资源根目录下存在 `视频`、`音频`、`歌词` 三个子目录,每类各 100 个课程文件。
|
||||||
|
- 群晖使用固定局域网地址或路由器 DHCP 地址保留。
|
||||||
|
|
||||||
|
## 1. 确认群晖本机路径
|
||||||
|
|
||||||
|
开发机看到的资源路径是:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/Volumes/study/Assets/SSS50
|
||||||
|
```
|
||||||
|
|
||||||
|
容器不能使用这个 Mac 路径。若 `study` 是群晖共享文件夹,群晖上的路径通常为:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/volume1/study/Assets/SSS50
|
||||||
|
```
|
||||||
|
|
||||||
|
请在 DSM 中确认它实际位于哪个存储空间;如果不是 `volume1`,必须修改为真实路径。
|
||||||
|
|
||||||
|
## 2. 放置项目并配置
|
||||||
|
|
||||||
|
把整个 `project_sss` 目录复制到群晖,例如:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/volume1/docker/sss-checkin/app
|
||||||
|
```
|
||||||
|
|
||||||
|
进入该目录,创建本机配置:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
检查 `.env`:
|
||||||
|
|
||||||
|
```dotenv
|
||||||
|
SSS_ASSET_PATH=/volume1/study/Assets/SSS50
|
||||||
|
SSS_DATA_PATH=/volume1/docker/sss-checkin/data
|
||||||
|
```
|
||||||
|
|
||||||
|
`SSS_ASSET_PATH` 是三类课程资源的共同根目录;`SSS_DATA_PATH` 用于持久保存开课日期、设备身份、播放和小红花记录。
|
||||||
|
|
||||||
|
## 3. 启动与验证
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d --build
|
||||||
|
curl http://127.0.0.1:8787/api/health
|
||||||
|
```
|
||||||
|
|
||||||
|
镜像会自动安装 ffmpeg,用于在第一次点击“一键播放”时按需生成本周的循环音频合辑;合辑缓存只会写入 `SSS_DATA_PATH/weekly-mixes`,不会改动课程原始音频。
|
||||||
|
|
||||||
|
健康接口应返回 `status: ok`,并显示 video、audio、lyrics 都为 100。随后让手机连接家庭 Wi-Fi,打开:
|
||||||
|
|
||||||
|
```text
|
||||||
|
http://群晖IP:8787
|
||||||
|
```
|
||||||
|
|
||||||
|
第一次打开时选择这台设备的身份,然后在设置中确认开课日期。不同手机或不同浏览器会各自选择并记住自己的身份,课程周次则由全家共用的开课日期自动计算。
|
||||||
|
|
||||||
|
家长可从设置进入“全部资源库”,搜索全部 100 首歌曲并检查三类资源。资源库和主播放器的视频均为点击后才读取,不会在页面打开时预先缓存视频。
|
||||||
|
|
||||||
|
## 4. 权限
|
||||||
|
|
||||||
|
- 容器只需读取 `SSS_ASSET_PATH`,Compose 已按只读方式挂载到 `/assets`。
|
||||||
|
- `SSS_DATA_PATH` 必须可读写,SQLite 数据库位于其中的 `sss.db`。
|
||||||
|
- 若健康接口显示 `degraded`,优先检查目录拼写、共享文件夹权限以及三类资源数量。
|
||||||
|
|
||||||
|
## 5. 更新资源映射
|
||||||
|
|
||||||
|
课程文件名发生变化后,应在开发机重新生成 `curriculum.json` 并连同项目一起部署:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 scripts/build_curriculum.py \
|
||||||
|
'source/SSS 儿歌 50周打卡表.xlsx' \
|
||||||
|
'/Volumes/study/Assets/SSS50' \
|
||||||
|
curriculum.json
|
||||||
|
```
|
||||||
|
|
||||||
|
脚本会要求 Excel 中的每首歌都同时存在视频、音频和歌词;缺少任意一种资源时会停止并报告课程编号。
|
||||||
|
|
||||||
|
## 6. 备份
|
||||||
|
|
||||||
|
可以短暂停止容器后复制数据库:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose stop
|
||||||
|
cp /volume1/docker/sss-checkin/data/sss.db /目标备份目录/sss-日期.db
|
||||||
|
docker compose start
|
||||||
|
```
|
||||||
|
|
||||||
|
建议用群晖任务计划每天备份并保留最近若干份。开课日期、身份映射、播放历史和红花记录都在同一个数据库中。
|
||||||
|
|
||||||
|
## 7. 局域网安全
|
||||||
|
|
||||||
|
- 不要把 8787 端口直接映射到公网。
|
||||||
|
- 应用没有面向公网的账号密码体系,只应在可信家庭局域网使用。
|
||||||
|
- 若以后确实需要外网访问,优先通过 VPN 或 Tailscale 进入家庭网络。
|
||||||
+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
@@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Build curriculum.json from the workbook and unified SSS asset root."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from openpyxl import load_workbook
|
||||||
|
|
||||||
|
|
||||||
|
SONG_PATTERN = re.compile(r"^(\d+)-(\d+)\s+(.+)$")
|
||||||
|
REVIEW_PATTERN = re.compile(r"复习(\d+)-(\d+)周")
|
||||||
|
ASSET_SPECS = {
|
||||||
|
"video_file": ("视频", ".mp4"),
|
||||||
|
"audio_file": ("音频", ".mp3"),
|
||||||
|
"lyrics_file": ("歌词", ".jpg"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def files_by_song_id(folder: Path, extension: str) -> dict[str, str]:
|
||||||
|
result = {}
|
||||||
|
for path in sorted(folder.glob(f"*{extension}")):
|
||||||
|
match = re.match(r"^(\d+-\d+)\s+", path.stem)
|
||||||
|
if match:
|
||||||
|
result[match.group(1)] = path.name
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def build_curriculum(workbook_path: Path, asset_root: Path) -> dict:
|
||||||
|
workbook = load_workbook(workbook_path, data_only=True, read_only=True)
|
||||||
|
worksheet = workbook["50周打卡"]
|
||||||
|
assets = {
|
||||||
|
field: files_by_song_id(asset_root / folder, extension)
|
||||||
|
for field, (folder, extension) in ASSET_SPECS.items()
|
||||||
|
}
|
||||||
|
|
||||||
|
weeks: dict[int, dict] = {}
|
||||||
|
current_week = None
|
||||||
|
for week_value, category_value, song_value in worksheet.iter_rows(
|
||||||
|
min_row=3, max_col=3, values_only=True
|
||||||
|
):
|
||||||
|
if isinstance(week_value, int):
|
||||||
|
current_week = week_value
|
||||||
|
category = str(category_value or "").strip()
|
||||||
|
review_match = REVIEW_PATTERN.search(category)
|
||||||
|
weeks[current_week] = {
|
||||||
|
"number": current_week,
|
||||||
|
"kind": "review" if review_match else "lesson",
|
||||||
|
"category": category,
|
||||||
|
"songs": [],
|
||||||
|
}
|
||||||
|
if review_match:
|
||||||
|
weeks[current_week]["review_from"] = int(review_match.group(1))
|
||||||
|
weeks[current_week]["review_to"] = int(review_match.group(2))
|
||||||
|
|
||||||
|
if current_week is None or not isinstance(song_value, str):
|
||||||
|
continue
|
||||||
|
match = SONG_PATTERN.match(song_value.strip())
|
||||||
|
if not match:
|
||||||
|
continue
|
||||||
|
song_id = f"{match.group(1)}-{match.group(2)}"
|
||||||
|
song = {
|
||||||
|
"id": song_id,
|
||||||
|
"slot": int(match.group(2)),
|
||||||
|
"title": match.group(3),
|
||||||
|
}
|
||||||
|
for field, mapping in assets.items():
|
||||||
|
if song_id not in mapping:
|
||||||
|
raise RuntimeError(f"Missing {field} for {song_id}")
|
||||||
|
song[field] = mapping[song_id]
|
||||||
|
weeks[current_week]["songs"].append(song)
|
||||||
|
|
||||||
|
if sorted(weeks) != list(range(1, 51)):
|
||||||
|
raise RuntimeError("Workbook must contain weeks 1 through 50")
|
||||||
|
|
||||||
|
songs = [song for week in weeks.values() for song in week["songs"]]
|
||||||
|
song_ids = {song["id"] for song in songs}
|
||||||
|
for field, mapping in assets.items():
|
||||||
|
unused = sorted(set(mapping) - song_ids)
|
||||||
|
if unused:
|
||||||
|
raise RuntimeError(f"Unused {field}: {unused}")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"meta": {
|
||||||
|
"title": "SSS 50周学习计划",
|
||||||
|
"source_workbook": workbook_path.name,
|
||||||
|
"asset_root_name": asset_root.name,
|
||||||
|
"song_count": len(songs),
|
||||||
|
"week_count": 50,
|
||||||
|
},
|
||||||
|
"weeks": [weeks[number] for number in sorted(weeks)],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("workbook", type=Path)
|
||||||
|
parser.add_argument("asset_root", type=Path)
|
||||||
|
parser.add_argument("output", type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
result = build_curriculum(args.workbook, args.asset_root)
|
||||||
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
args.output.write_text(
|
||||||
|
json.dumps(result, ensure_ascii=False, indent=2) + "\n", encoding="utf-8"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
f"Wrote {result['meta']['week_count']} weeks and "
|
||||||
|
f"{result['meta']['song_count']} songs to {args.output}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Executable
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
# Keep the local LAN server in a detached user session. It intentionally runs
|
||||||
|
# in the logged-in user's context so it can read the authenticated SMB mount at
|
||||||
|
# /Volumes/study.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
session_name='sss50'
|
||||||
|
project_dir='/Users/optimx/CODE/nas/project_sss'
|
||||||
|
log_file='/Users/optimx/CODE/nas/project_sss/.local-data/server-tmux.log'
|
||||||
|
server_command="cd '${project_dir}' && while true; do env ASSET_ROOT='/Volumes/study/Assets/SSS50' DATA_DIR='${project_dir}/.local-data' PORT=8787 PYTHONUNBUFFERED=1 /usr/bin/python3 app.py >> '${log_file}' 2>&1; sleep 2; done"
|
||||||
|
|
||||||
|
case "${1:-start}" in
|
||||||
|
start)
|
||||||
|
if tmux has-session -t "${session_name}" 2>/dev/null; then
|
||||||
|
echo "SSS server is already running in tmux session: ${session_name}"
|
||||||
|
else
|
||||||
|
tmux new-session -d -s "${session_name}" "${server_command}"
|
||||||
|
echo "SSS server started: http://127.0.0.1:8787"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
tmux has-session -t "${session_name}"
|
||||||
|
curl -fsS http://127.0.0.1:8787/api/health
|
||||||
|
;;
|
||||||
|
logs)
|
||||||
|
tail -n "${2:-80}" "${log_file}"
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
tmux kill-session -t "${session_name}"
|
||||||
|
echo "SSS server stopped"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|status|logs|stop}" >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Binary file not shown.
@@ -0,0 +1,539 @@
|
|||||||
|
import sqlite3
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
from contextlib import closing
|
||||||
|
from datetime import date, datetime, timedelta, timezone
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import app
|
||||||
|
|
||||||
|
|
||||||
|
BASE_TIME = datetime(2026, 10, 12, 2, 0, tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
class SSSAppTests(unittest.TestCase):
|
||||||
|
def make_database(self, directory: str, at: datetime = BASE_TIME) -> Path:
|
||||||
|
db_path = Path(directory) / "sss.db"
|
||||||
|
app.initialize_database(db_path, at)
|
||||||
|
return db_path
|
||||||
|
|
||||||
|
def bind(self, connection, device="device-test0001", actor="妈妈", at=BASE_TIME):
|
||||||
|
app.bind_device(connection, device, actor, at)
|
||||||
|
return device
|
||||||
|
|
||||||
|
def play_and_complete(
|
||||||
|
self,
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
song_id,
|
||||||
|
at,
|
||||||
|
study_date="2026-10-12",
|
||||||
|
media_type="video",
|
||||||
|
):
|
||||||
|
play_id = app.start_playback_event(
|
||||||
|
connection, device, song_id, study_date, media_type, at
|
||||||
|
)
|
||||||
|
result = app.complete_playback_event(
|
||||||
|
connection, device, play_id, 90, at + timedelta(minutes=1)
|
||||||
|
)
|
||||||
|
return play_id, result
|
||||||
|
|
||||||
|
def test_curriculum_has_all_three_asset_types(self):
|
||||||
|
self.assertEqual(app.CURRICULUM["meta"]["week_count"], 50)
|
||||||
|
self.assertEqual(app.CURRICULUM["meta"]["song_count"], 100)
|
||||||
|
song = app.CURRICULUM["songs_by_id"]["28-3"]
|
||||||
|
self.assertEqual(song["video_file"], "28-3 The Shape Song.mp4")
|
||||||
|
self.assertEqual(song["audio_file"], "28-3 The Shape Song.mp3")
|
||||||
|
self.assertEqual(song["lyrics_file"], "28-3 The Shape Song.jpg")
|
||||||
|
|
||||||
|
def test_active_asset_root_finds_macos_suffixed_study_mount(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
volumes_root = Path(temp_dir) / "Volumes"
|
||||||
|
configured_root = volumes_root / "study" / "Assets" / "SSS50"
|
||||||
|
fallback_root = volumes_root / "study-1" / "Assets" / "SSS50"
|
||||||
|
(fallback_root / "视频").mkdir(parents=True)
|
||||||
|
self.assertEqual(
|
||||||
|
app.active_asset_root(configured_root, volumes_root), fallback_root
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_resource_catalog_lists_every_song_and_three_lazy_assets(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
payload = app.resources_payload(Path(temp_dir))
|
||||||
|
self.assertEqual(payload["summary"]["songs"], 100)
|
||||||
|
self.assertEqual(len(payload["songs"]), 100)
|
||||||
|
first = payload["songs"][0]
|
||||||
|
self.assertEqual(first["id"], "1-1")
|
||||||
|
self.assertEqual(first["week"], 1)
|
||||||
|
self.assertEqual(set(first["urls"]), {"video", "audio", "lyrics"})
|
||||||
|
self.assertFalse(any(first["available"].values()))
|
||||||
|
|
||||||
|
resource_html = (app.PUBLIC_DIR / "resources.html").read_text(encoding="utf-8")
|
||||||
|
resource_js = (app.PUBLIC_DIR / "resources.js").read_text(encoding="utf-8")
|
||||||
|
self.assertNotIn('id="resource-viewer"', resource_html)
|
||||||
|
self.assertIn('data-resource-detail', resource_js)
|
||||||
|
self.assertIn('data-resource-video data-video-url=', resource_js)
|
||||||
|
self.assertIn('data-resource-audio data-audio-url=', resource_js)
|
||||||
|
self.assertIn('video.src = video.dataset.videoUrl', resource_js)
|
||||||
|
self.assertIn('audio.src = audio.dataset.audioUrl', resource_js)
|
||||||
|
self.assertNotIn('mode: "info"', resource_js)
|
||||||
|
self.assertNotIn('songs[0]?.id', resource_js)
|
||||||
|
|
||||||
|
def test_home_uses_one_lazy_media_card_per_song(self):
|
||||||
|
home_html = (app.PUBLIC_DIR / "index.html").read_text(encoding="utf-8")
|
||||||
|
home_js = (app.PUBLIC_DIR / "app.js").read_text(encoding="utf-8")
|
||||||
|
resource_js = (app.PUBLIC_DIR / "resources.js").read_text(encoding="utf-8")
|
||||||
|
stats_js = (app.PUBLIC_DIR / "stats.js").read_text(encoding="utf-8")
|
||||||
|
self.assertIn('id="song-cards"', home_html)
|
||||||
|
self.assertNotIn('id="current-song-id"', home_html)
|
||||||
|
self.assertNotIn('id="audio-previous"', home_html)
|
||||||
|
self.assertNotIn('id="loop-toggle"', home_html)
|
||||||
|
self.assertIn('data-video-url="${song.video_url}"', home_js)
|
||||||
|
self.assertIn('data-audio-url="${song.audio_url}"', home_js)
|
||||||
|
self.assertIn('player.src = player.dataset[urlKey]', home_js)
|
||||||
|
self.assertIn('const urlKey = mediaType === "audio" ? "audioUrl" : "videoUrl"', home_js)
|
||||||
|
self.assertNotIn("独立播放", home_html)
|
||||||
|
self.assertNotIn("一首歌一个窗口", home_html)
|
||||||
|
self.assertIn('id="round-hint"', home_html)
|
||||||
|
self.assertIn('"上午领取", "下午领取", "晚上领取"', home_js)
|
||||||
|
self.assertIn('id="playlist-loop-button"', home_html)
|
||||||
|
self.assertIn('id="weekly-loop-player"', home_html)
|
||||||
|
self.assertIn('loop playsinline webkit-playsinline', home_html)
|
||||||
|
self.assertIn('id="child-mode"', home_html)
|
||||||
|
self.assertIn("async function startPlaylistAt", home_js)
|
||||||
|
self.assertIn('playCardMedia(song.id, "audio", "single")', home_js)
|
||||||
|
self.assertIn('player.src = `/api/week-audio/${weekNumber}`', home_js)
|
||||||
|
self.assertIn('mode: "weekly-loop"', home_js)
|
||||||
|
self.assertIn('elements.weeklyLoopPlayer.pause()', home_js)
|
||||||
|
self.assertIn('function isIPhone5sOnIOS10()', home_js)
|
||||||
|
self.assertIn('function childSongCardMarkup(song, index)', home_js)
|
||||||
|
self.assertIn('appState.childMode ? "audio"', home_js)
|
||||||
|
self.assertIn('course_week: appState.data.week.number', home_js)
|
||||||
|
self.assertIn('data-week-number=', home_js)
|
||||||
|
self.assertIn('<title>SSS 50 周打卡</title>', home_html)
|
||||||
|
self.assertIn('id="identity-button"', home_html)
|
||||||
|
self.assertIn('id="bottom-settings-button"', home_html)
|
||||||
|
self.assertIn('id="start-date" name="start_date" type="date" value="2026-10-12" disabled', home_html)
|
||||||
|
self.assertNotIn('id="settings-button"', home_html)
|
||||||
|
self.assertNotIn('if (mode !== "video") video.pause()', home_js)
|
||||||
|
self.assertNotIn('if (mode !== "audio") audio.pause()', home_js)
|
||||||
|
self.assertNotIn("<dialog", home_html)
|
||||||
|
self.assertIn('class="modal identity-dialog"', home_html)
|
||||||
|
self.assertIn("webkit-playsinline", home_js)
|
||||||
|
self.assertIn("function forEachNode", home_js)
|
||||||
|
self.assertNotIn("querySelectorAll(\"[data-actor]\").forEach", home_js)
|
||||||
|
for script in (home_js, resource_js, stats_js):
|
||||||
|
self.assertNotIn("?.", script)
|
||||||
|
self.assertNotIn("??", script)
|
||||||
|
self.assertNotIn(".replaceAll(", script)
|
||||||
|
self.assertNotIn("...", script)
|
||||||
|
self.assertNotIn("URLSearchParams", home_js)
|
||||||
|
|
||||||
|
def test_future_week_can_be_previewed_without_checkin_progress(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
state = app.state_payload(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME,
|
||||||
|
view_week_value=2,
|
||||||
|
)
|
||||||
|
self.assertEqual(state["week"]["number"], 2)
|
||||||
|
self.assertTrue(state["viewing_future"])
|
||||||
|
self.assertFalse(state["can_checkin"])
|
||||||
|
self.assertTrue(all(not song["can_checkin"] for song in state["week"]["songs"]))
|
||||||
|
self.assertTrue(all(week["unlocked"] for week in state["weeks"]))
|
||||||
|
|
||||||
|
def test_future_preview_play_is_recorded_but_never_unlocks_checkin(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
play_id = app.start_playback_event(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"2-1",
|
||||||
|
"2026-10-12",
|
||||||
|
"audio",
|
||||||
|
BASE_TIME,
|
||||||
|
course_week_value=2,
|
||||||
|
)
|
||||||
|
result = app.complete_playback_event(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
play_id,
|
||||||
|
90,
|
||||||
|
BASE_TIME + timedelta(minutes=1),
|
||||||
|
)
|
||||||
|
row = connection.execute(
|
||||||
|
"SELECT course_week, study_date FROM playback_events WHERE id = ?",
|
||||||
|
(play_id,),
|
||||||
|
).fetchone()
|
||||||
|
with self.assertRaisesRegex(ValueError, "not part"):
|
||||||
|
app.claim_song_checkin(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"2-1",
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME + timedelta(minutes=2),
|
||||||
|
)
|
||||||
|
self.assertEqual((row["course_week"], row["study_date"]), (2, "2026-10-12"))
|
||||||
|
self.assertFalse(result["checkin_eligible"])
|
||||||
|
self.assertFalse(result["round_ready"])
|
||||||
|
|
||||||
|
def test_course_week_is_computed_from_start_date(self):
|
||||||
|
start = date(2026, 9, 28)
|
||||||
|
self.assertEqual(app.week_for_date(start, date(2026, 9, 28)), 1)
|
||||||
|
self.assertEqual(app.week_for_date(start, date(2026, 10, 4)), 1)
|
||||||
|
self.assertEqual(app.week_for_date(start, date(2026, 10, 5)), 2)
|
||||||
|
self.assertEqual(app.week_for_date(start, date(2027, 12, 31)), 50)
|
||||||
|
|
||||||
|
def test_database_migration_is_idempotent_and_sets_start_date(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
app.initialize_database(db_path, BASE_TIME)
|
||||||
|
with sqlite3.connect(db_path) as connection:
|
||||||
|
settings = connection.execute(
|
||||||
|
"SELECT start_date, checkin_window_minutes FROM household_settings"
|
||||||
|
).fetchall()
|
||||||
|
tables = {
|
||||||
|
row[0]
|
||||||
|
for row in connection.execute(
|
||||||
|
"SELECT name FROM sqlite_master WHERE type = 'table'"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
round_columns = {
|
||||||
|
row[1] for row in connection.execute("PRAGMA table_info(round_checkins)")
|
||||||
|
}
|
||||||
|
self.assertEqual(settings, [("2026-10-12", 60)])
|
||||||
|
self.assertIn("song_checkins", tables)
|
||||||
|
self.assertIn("round_checkins", tables)
|
||||||
|
self.assertIn("round_number", round_columns)
|
||||||
|
|
||||||
|
def test_device_identity_can_be_changed(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
app.bind_device(connection, "device-12345678", "妈妈", BASE_TIME)
|
||||||
|
app.bind_device(connection, "device-12345678", "爸爸", BASE_TIME)
|
||||||
|
state = app.state_payload(
|
||||||
|
connection,
|
||||||
|
"device-12345678",
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME,
|
||||||
|
)
|
||||||
|
self.assertEqual(state["device"]["actor"], "爸爸")
|
||||||
|
self.assertEqual(state["settings"]["current_week"], 1)
|
||||||
|
self.assertEqual(state["study_date"], "2026-10-12")
|
||||||
|
|
||||||
|
def test_completed_play_unlocks_manual_flower_but_does_not_claim_it(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
self.play_and_complete(connection, device, "1-1", BASE_TIME)
|
||||||
|
progress = app.song_progress(
|
||||||
|
connection, "1-1", 1, date(2026, 10, 12), BASE_TIME, 60
|
||||||
|
)
|
||||||
|
count = connection.execute("SELECT COUNT(*) FROM song_checkins").fetchone()[0]
|
||||||
|
self.assertEqual(count, 0)
|
||||||
|
self.assertEqual(progress["ready_count"], 1)
|
||||||
|
self.assertTrue(progress["can_checkin"])
|
||||||
|
|
||||||
|
def test_manual_flowers_are_throttled_per_song_not_globally(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
self.play_and_complete(connection, device, "1-1", BASE_TIME)
|
||||||
|
first = app.claim_song_checkin(
|
||||||
|
connection, device, "1-1", "2026-10-12", BASE_TIME + timedelta(minutes=2)
|
||||||
|
)
|
||||||
|
self.play_and_complete(
|
||||||
|
connection, device, "1-1", BASE_TIME + timedelta(minutes=10)
|
||||||
|
)
|
||||||
|
with self.assertRaisesRegex(ValueError, "等待"):
|
||||||
|
app.claim_song_checkin(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"1-1",
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME + timedelta(minutes=12),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.play_and_complete(
|
||||||
|
connection, device, "1-2", BASE_TIME + timedelta(minutes=10)
|
||||||
|
)
|
||||||
|
second_song = app.claim_song_checkin(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"1-2",
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME + timedelta(minutes=12),
|
||||||
|
)
|
||||||
|
self.assertEqual(first["checkin_count"], 1)
|
||||||
|
self.assertEqual(second_song["checkin_count"], 1)
|
||||||
|
|
||||||
|
def test_song_can_collect_three_flowers_with_three_plays_and_intervals(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
for index in range(3):
|
||||||
|
moment = BASE_TIME + timedelta(minutes=index * 61)
|
||||||
|
self.play_and_complete(connection, device, "1-1", moment)
|
||||||
|
result = app.claim_song_checkin(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"1-1",
|
||||||
|
"2026-10-12",
|
||||||
|
moment + timedelta(minutes=1),
|
||||||
|
)
|
||||||
|
count = connection.execute(
|
||||||
|
"SELECT COUNT(*) FROM song_checkins WHERE song_id = '1-1'"
|
||||||
|
).fetchone()[0]
|
||||||
|
self.assertEqual(result["checkin_count"], 3)
|
||||||
|
self.assertEqual(count, 3)
|
||||||
|
|
||||||
|
def test_full_playlist_unlocks_round_flower_for_manual_claim(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
results = []
|
||||||
|
for index, song_id in enumerate(("1-1", "1-2", "1-3")):
|
||||||
|
_, result = self.play_and_complete(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
song_id,
|
||||||
|
BASE_TIME + timedelta(minutes=index * 3),
|
||||||
|
)
|
||||||
|
results.append(result)
|
||||||
|
count = connection.execute("SELECT COUNT(*) FROM round_checkins").fetchone()[0]
|
||||||
|
claimed = app.claim_round_checkin(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME + timedelta(minutes=10),
|
||||||
|
)
|
||||||
|
claimed_count = connection.execute(
|
||||||
|
"SELECT COUNT(*) FROM round_checkins"
|
||||||
|
).fetchone()[0]
|
||||||
|
self.assertFalse(results[0]["round_ready"])
|
||||||
|
self.assertFalse(results[1]["round_ready"])
|
||||||
|
self.assertTrue(results[2]["round_ready"])
|
||||||
|
self.assertEqual(count, 0)
|
||||||
|
self.assertEqual(claimed["round_number"], 1)
|
||||||
|
self.assertEqual(claimed_count, 1)
|
||||||
|
|
||||||
|
def test_three_full_playlists_can_collect_three_round_flowers(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
for round_index in range(3):
|
||||||
|
start = BASE_TIME + timedelta(minutes=round_index * 64)
|
||||||
|
for song_index, song_id in enumerate(("1-1", "1-2", "1-3")):
|
||||||
|
self.play_and_complete(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
song_id,
|
||||||
|
start + timedelta(minutes=song_index),
|
||||||
|
)
|
||||||
|
result = app.claim_round_checkin(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"2026-10-12",
|
||||||
|
start + timedelta(minutes=4),
|
||||||
|
)
|
||||||
|
rows = connection.execute(
|
||||||
|
"SELECT round_number FROM round_checkins ORDER BY round_number"
|
||||||
|
).fetchall()
|
||||||
|
self.assertEqual(result["round_number"], 3)
|
||||||
|
self.assertEqual([row["round_number"] for row in rows], [1, 2, 3])
|
||||||
|
|
||||||
|
def test_round_cooldown_is_shared_across_devices(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
dad = self.bind(connection, "device-dad00001", "爸爸")
|
||||||
|
mom = self.bind(connection, "device-mom00001", "妈妈")
|
||||||
|
for song_index, song_id in enumerate(("1-1", "1-2", "1-3")):
|
||||||
|
self.play_and_complete(
|
||||||
|
connection,
|
||||||
|
dad,
|
||||||
|
song_id,
|
||||||
|
BASE_TIME + timedelta(minutes=song_index),
|
||||||
|
)
|
||||||
|
app.claim_round_checkin(
|
||||||
|
connection, dad, "2026-10-12", BASE_TIME + timedelta(minutes=4)
|
||||||
|
)
|
||||||
|
for song_index, song_id in enumerate(("1-1", "1-2", "1-3")):
|
||||||
|
self.play_and_complete(
|
||||||
|
connection,
|
||||||
|
mom,
|
||||||
|
song_id,
|
||||||
|
BASE_TIME + timedelta(minutes=10 + song_index),
|
||||||
|
)
|
||||||
|
with self.assertRaisesRegex(ValueError, "等待"):
|
||||||
|
app.claim_round_checkin(
|
||||||
|
connection,
|
||||||
|
mom,
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME + timedelta(minutes=14),
|
||||||
|
)
|
||||||
|
count = connection.execute(
|
||||||
|
"SELECT COUNT(*) FROM round_checkins"
|
||||||
|
).fetchone()[0]
|
||||||
|
self.assertEqual(count, 1)
|
||||||
|
|
||||||
|
def test_round_cooldown_cannot_be_bypassed_with_another_study_date(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
connection.execute(
|
||||||
|
"UPDATE household_settings SET start_date = '2026-10-05' WHERE id = 1"
|
||||||
|
)
|
||||||
|
connection.commit()
|
||||||
|
dad = self.bind(connection, "device-dad00001", "爸爸")
|
||||||
|
mom = self.bind(connection, "device-mom00001", "妈妈")
|
||||||
|
|
||||||
|
for song_index, song in enumerate(
|
||||||
|
app.playlist_for_week(app.CURRICULUM["weeks_by_no"][2])
|
||||||
|
):
|
||||||
|
self.play_and_complete(
|
||||||
|
connection,
|
||||||
|
dad,
|
||||||
|
song["id"],
|
||||||
|
BASE_TIME + timedelta(minutes=song_index),
|
||||||
|
"2026-10-12",
|
||||||
|
)
|
||||||
|
app.claim_round_checkin(
|
||||||
|
connection, dad, "2026-10-12", BASE_TIME + timedelta(minutes=4)
|
||||||
|
)
|
||||||
|
|
||||||
|
for song_index, song in enumerate(
|
||||||
|
app.playlist_for_week(app.CURRICULUM["weeks_by_no"][1])
|
||||||
|
):
|
||||||
|
self.play_and_complete(
|
||||||
|
connection,
|
||||||
|
mom,
|
||||||
|
song["id"],
|
||||||
|
BASE_TIME + timedelta(minutes=10 + song_index),
|
||||||
|
"2026-10-11",
|
||||||
|
)
|
||||||
|
with self.assertRaisesRegex(ValueError, "等待"):
|
||||||
|
app.claim_round_checkin(
|
||||||
|
connection,
|
||||||
|
mom,
|
||||||
|
"2026-10-11",
|
||||||
|
BASE_TIME + timedelta(minutes=14),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_pending_flower_is_recovered_on_next_state_load(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
self.play_and_complete(connection, device, "1-1", BASE_TIME)
|
||||||
|
state = app.state_payload(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME + timedelta(minutes=2),
|
||||||
|
recover=True,
|
||||||
|
)
|
||||||
|
self.assertEqual(state["week"]["songs"][0]["checkin_count"], 1)
|
||||||
|
self.assertEqual(state["recovered_awards"][0]["kind"], "song")
|
||||||
|
|
||||||
|
def test_makeup_flower_is_recovered_when_next_visit_opens_today(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
connection.execute(
|
||||||
|
"UPDATE household_settings SET start_date = '2026-09-21' WHERE id = 1"
|
||||||
|
)
|
||||||
|
connection.commit()
|
||||||
|
device = self.bind(connection)
|
||||||
|
self.play_and_complete(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"3-1",
|
||||||
|
BASE_TIME - timedelta(hours=2),
|
||||||
|
study_date="2026-10-11",
|
||||||
|
)
|
||||||
|
state = app.state_payload(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME,
|
||||||
|
recover=True,
|
||||||
|
)
|
||||||
|
recovered = connection.execute(
|
||||||
|
"SELECT song_id, study_date, source FROM song_checkins"
|
||||||
|
).fetchone()
|
||||||
|
self.assertEqual(state["week"]["number"], 4)
|
||||||
|
self.assertEqual(
|
||||||
|
(recovered["song_id"], recovered["study_date"], recovered["source"]),
|
||||||
|
("3-1", "2026-10-11", "recovery"),
|
||||||
|
)
|
||||||
|
self.assertEqual(state["recovered_awards"][0]["study_date"], "2026-10-11")
|
||||||
|
|
||||||
|
def test_progress_calendar_has_two_dynamic_rows_ending_today(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
connection.execute(
|
||||||
|
"UPDATE household_settings SET start_date = '2026-09-21' WHERE id = 1"
|
||||||
|
)
|
||||||
|
connection.commit()
|
||||||
|
state = app.state_payload(
|
||||||
|
connection,
|
||||||
|
None,
|
||||||
|
"2026-10-05",
|
||||||
|
BASE_TIME,
|
||||||
|
recover=False,
|
||||||
|
)
|
||||||
|
self.assertEqual(len(state["progress_14d"]), 14)
|
||||||
|
self.assertEqual(state["week"]["number"], 3)
|
||||||
|
self.assertEqual(state["progress_14d"][-1]["date"], "2026-10-12")
|
||||||
|
self.assertEqual(state["progress_14d"][-1]["weekday"], "一")
|
||||||
|
self.assertTrue(any(day["status"] == "missed" for day in state["progress_14d"]))
|
||||||
|
|
||||||
|
def test_statistics_include_song_and_round_flowers(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
db_path = self.make_database(temp_dir)
|
||||||
|
with closing(app.connect_db(db_path)) as connection:
|
||||||
|
device = self.bind(connection)
|
||||||
|
for index, song_id in enumerate(("1-1", "1-2", "1-3")):
|
||||||
|
self.play_and_complete(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
song_id,
|
||||||
|
BASE_TIME + timedelta(minutes=index * 3),
|
||||||
|
)
|
||||||
|
app.claim_song_checkin(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"1-1",
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME + timedelta(minutes=12),
|
||||||
|
)
|
||||||
|
app.claim_round_checkin(
|
||||||
|
connection,
|
||||||
|
device,
|
||||||
|
"2026-10-12",
|
||||||
|
BASE_TIME + timedelta(minutes=12),
|
||||||
|
)
|
||||||
|
stats = app.statistics_payload(connection, BASE_TIME + timedelta(minutes=15))
|
||||||
|
song = next(item for item in stats["songs"] if item["id"] == "1-1")
|
||||||
|
self.assertEqual(stats["summary"]["song_checkins"], 1)
|
||||||
|
self.assertEqual(stats["summary"]["round_checkins"], 1)
|
||||||
|
self.assertEqual(stats["summary"]["checkins"], 2)
|
||||||
|
self.assertEqual(song["checkins"], 1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user