--- author: AI Assistant created_at: 2026-07-26 purpose: 修复 ScriptLibraryView 章节数展示为 0 的问题 --- # 章节数展示修复设计 ## 问题 ScriptLibraryView 列表页中所有剧本的章节数均显示为"0章"。 **根因**:前端 `getChapterCount` 函数读取 `script.chapterCount || script.chapters || 0`,但后端未返回 `chapterCount` 或 `chapters` 字段;老剧本的 `plotJson` 仅包含 `title` 和 `fullContent`,不存在 `stages.outline.beats` 结构。 ## 目标 - 新剧本(Task 1-5 部署后生成):从 `plotJson.stages.outline.beats.length` 获取真实章节数 - 老剧本:根据 `script.length` 字段(short/medium/long)估算合理的章节数 - 短篇显示"1章"(符合业务预期) ## 方案 修改 `mini-program/src/pages/main/ScriptLibraryView.vue` 中的 `getChapterCount` 函数: ```javascript const getChapterCount = (script) => { // 优先从 beats 数组长度获取(新剧本结构) const beats = script?.plotJson?.stages?.outline?.beats if (Array.isArray(beats) && beats.length > 0) return beats.length // Fallback:根据 length 字段估算 const length = script?.length if (length === 'short') return 1 if (length === 'medium') return 2 if (length === 'long') return 4 return 1 } ``` ## 影响范围 - 仅修改 `ScriptLibraryView.vue` 的 `getChapterCount` 函数 - 不涉及后端改动 - 不涉及其他前端文件 ## 验收标准 - 短篇剧本列表卡片显示"1章" - 中篇剧本列表卡片显示"2章" - 长篇剧本列表卡片显示"4章" - 新剧本(有 beats 数据)显示真实 beats 数量 - Console 无新增错误