本文引用的文件
本指南聚焦于内容管理功能,涵盖收藏、历史记录、评论系统、内容组织(分类与标签)、以及用户行为分析与个性化推荐的实现要点与最佳实践。文档基于仓库现有代码进行梳理,帮助开发者与产品人员快速理解并优化内容管理体验。
后端采用模块化路由与服务分离的设计,前端通过 uni-app 页面承载交互逻辑。数据库使用 Prisma 定义模型,统一管理用户、收藏、历史、评论、偏好等数据。
graph TB
subgraph "前端(uni-app)"
FE_Search["搜索页<br/>search/index.vue"]
FE_History["历史页<br/>history/index.vue"]
FE_Fav["收藏页<br/>favorites/index.vue"]
end
subgraph "后端(Koa)"
API_Search["搜索控制器<br/>search.controller.ts"]
API_History["历史控制器<br/>history.controller.ts"]
API_History_Batch["历史批量控制器<br/>history-batch.controller.ts"]
API_Comments["评论控制器<br/>comments.controller.ts"]
API_Categories["分类控制器<br/>categories.controller.ts"]
API_Player["播放控制器<br/>player.controller.ts"]
API_Preferences["偏好服务<br/>preferences.service.ts"]
end
DB["数据库模型<br/>schema.prisma"]
FE_Search --> API_Search
FE_History --> API_History
FE_History --> API_History_Batch
FE_Fav --> API_Search
API_Search --> DB
API_History --> DB
API_History_Batch --> DB
API_Comments --> DB
API_Categories --> DB
API_Player --> DB
API_Preferences --> DB
图表来源
章节来源
章节来源
后端模块通过 Koa 路由暴露 REST 接口,服务层封装业务逻辑,Prisma 作为 ORM 访问 MySQL。前端页面通过统一请求工具调用接口,完成内容管理相关操作。
sequenceDiagram
participant U as "用户"
participant FE as "前端页面"
participant API as "后端控制器"
participant S as "服务层"
participant DB as "数据库"
U->>FE : 触发收藏/历史/搜索/评论等操作
FE->>API : 发起HTTP请求
API->>S : 调用服务层处理业务
S->>DB : 查询/插入/更新/删除
DB-->>S : 返回数据
S-->>API : 返回处理结果
API-->>FE : 返回JSON响应
FE-->>U : 展示结果/更新UI
图表来源
最佳实践
对批量收藏/取消场景,可在服务层增加幂等接口以提升稳定性。
flowchart TD
Start(["开始"]) --> CheckExist["检查是否已收藏"]
CheckExist --> Exists{"已收藏?"}
Exists --> |是| ReturnExisting["返回现有记录"]
Exists --> |否| Create["创建收藏记录"]
Create --> ReturnCreated["返回新建记录"]
ReturnExisting --> End(["结束"])
ReturnCreated --> End
图表来源
章节来源
清理策略
历史记录按时间范围与关键词过滤,便于用户自助清理。
sequenceDiagram
participant FE as "前端历史页"
participant API as "历史控制器"
participant Batch as "历史批量控制器"
participant DB as "数据库"
FE->>API : GET /history?page&pageSize&startDate&keyword
API->>DB : 查询AudioRecord并计数
DB-->>API : 返回列表与总数
API-->>FE : 返回分页结果
FE->>Batch : POST /history/batch-delete {ids}
Batch->>DB : deleteMany(audioId in ids)
DB-->>Batch : 返回删除数量
Batch-->>FE : 返回成功与删除数量
图表来源
章节来源
前端交互
搜索页展示历史与热门词,支持点击回填与搜索。
sequenceDiagram
participant FE as "前端搜索页"
participant API as "搜索控制器"
participant DB as "数据库"
FE->>API : GET /search/hot?limit
API->>DB : 查询热门词
DB-->>API : 返回热门词列表
API-->>FE : 返回热门词
FE->>API : POST /search/history {userId, keyword}
API->>DB : 插入搜索历史
DB-->>API : 返回成功
API-->>FE : 返回成功
FE->>API : GET /search/history?userId&limit
API->>DB : 查询历史
DB-->>API : 返回历史列表
API-->>FE : 返回历史
图表来源
章节来源
前端交互
前端页面可展示评论列表,结合章节详情页进行评论发布与查看。
sequenceDiagram
participant FE as "前端评论页"
participant API as "评论控制器"
participant S as "评论服务"
participant DB as "数据库"
FE->>API : GET /api/comments/ : chapterId
API->>S : getCommentsByChapterId
S->>DB : 查询评论
DB-->>S : 返回评论列表
S-->>API : 返回评论
API-->>FE : 返回评论数据
FE->>API : POST /api/comments {chapterId, content, rating}
API->>S : addComment
S->>DB : 插入评论
DB-->>S : 返回评论
S-->>API : 返回评论
API-->>FE : 返回成功与评论
图表来源
章节来源
标签映射
服务层提供分类到标签的映射逻辑,便于前端展示。
sequenceDiagram
participant FE as "前端分类页"
participant API as "分类控制器"
participant S as "分类服务"
participant DB as "数据库"
FE->>API : GET /api/categories
API->>S : 获取分类列表
S->>DB : 查询分类
DB-->>S : 返回分类
S-->>API : 返回分类列表
API-->>FE : 返回分类
FE->>API : GET /api/categories/ : id?page&pageSize
API->>S : 按分类获取音频
S->>DB : 查询音频
DB-->>S : 返回音频列表
S-->>API : 返回音频
API-->>FE : 返回音频列表
图表来源
章节来源
个性化推荐
可在播放器页或首页展示“为你推荐”卡片,引导用户发现内容。
sequenceDiagram
participant FE as "前端播放器/首页"
participant API as "播放控制器"
participant Pref as "偏好服务"
participant DB as "数据库"
FE->>API : GET /api/player/progress?audioId
API->>DB : 查询播放进度
DB-->>API : 返回进度
API-->>FE : 返回进度
FE->>API : POST /api/player/progress {audioId, progress, duration}
API->>DB : 保存/更新进度
DB-->>API : 返回记录
API-->>FE : 返回成功
FE->>Pref : GET /api/preferences
Pref->>DB : upsert用户偏好
DB-->>Pref : 返回偏好
Pref-->>FE : 返回偏好
图表来源
章节来源
外部依赖
前端通过统一请求工具调用后端接口,接口风格一致,便于扩展。
erDiagram
USER {
int id PK
string phone
string openid
int memberLevel
int dailyUsage
string lastUsageDate
}
FAVORITE {
int id PK
int userId FK
int bookId FK
datetime createdAt
}
COMMENT {
int id PK
int userId FK
int chapterId FK
int rating
text content
datetime createdAt
}
PLAYRECORD {
int id PK
int userId FK
int chapterId FK
float progress
float duration
datetime createdAt
datetime updatedAt
}
USERPREFERENCE {
int id PK
int userId FK
float playSpeed
string quality
string theme
string defaultVoiceId
int defaultVolume
bool autoPlayNext
bool wifiOnlyDownload
}
AUDIORECORD {
int id PK
int userId
string audioId
string title
int wordCount
string voiceId
int audioDuration
int audioSize
string status
int bookId
datetime createdAt
datetime updatedAt
}
BOOKCHAPTER {
int id PK
int bookId FK
int parentId
int level
int number
string title
int wordCount
string audioUrl
int audioDuration
bool isPublic
}
BOOK {
int id PK
int userId
string title
string description
int totalChapters
int estimatedWords
bool isPublished
}
USER ||--o{ FAVORITE : "收藏"
USER ||--o{ COMMENT : "发表评论"
USER ||--o{ PLAYRECORD : "播放记录"
USER ||--o{ AUDIORECORD : "生成历史"
USER ||--o{ USERPREFERENCE : "偏好设置"
BOOK ||--o{ FAVORITE : "被收藏"
BOOK ||--o{ BOOKCHAPTER : "包含章节"
BOOKCHAPTER ||--o{ COMMENT : "被评论"
BOOKCHAPTER ||--o{ PLAYRECORD : "被播放"
图表来源
章节来源
章节来源
本项目在内容管理方面具备清晰的模块划分与完善的数据库模型支撑。收藏、历史、搜索、评论、分类与偏好等功能均已具备基础实现,建议后续在以下方面持续优化: