Files
Mdeical_Sur_Report/工程分析/需求分析-2026-04-16-16-51-00.md

37 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 需求分析 — 2026-04-16-16-51-00
## 需求背景
用户在进入 **report-editor**(图文报告生成)页面时,期望编辑器能够自动加载在 **system-settings** 中配置的"图文报告生成默认模板"。但目前存在以下异常现象:
1. 超级管理员进入 report-editor 时,顶部模板选择器显示 **"无"**,编辑区域(`editor-content-wrapper print-wrapper`)为纯白色空白,没有加载任何模板内容。
2. 在 system-settings 中已正确设置默认模板为 **"腹腔镜胆囊切除术报告"**,但 report-editor 未按预期加载。
3. 用户从 `/dashboard` 等其他页面返回 `/report-editor` 后,若之前未进行过有效编辑,也可能出现白色空白模板的情况。
## 功能目标
修复 report-editor 页面初始化时的模板加载逻辑,确保:
- 新建报告(无 `reportId`)时,优先加载系统设置中的默认模板。
- 只有当用户确实在编辑器中有过有效编辑内容时才从本地草稿draft恢复。
- 模板选择器中的"当前模板(及重置模板):"应正确反映当前加载的模板名称,而不是显示"无"。
- 从其他页面返回或重新进入 report-editor 时,未编辑状态下不应出现空白模板。
## 涉及页面/模块
- `src/pages/ReportEditor.tsx` —— 核心问题所在,草稿恢复与默认模板加载逻辑
- `src/pages/SystemSettings.tsx` —— 默认模板设置页面(验证配置读取逻辑)
- `src/utils/storage.ts` —— localStorage 读写封装(辅助确认)
## 问题根因(预分析)
通过代码审阅,发现以下导致空白的根因:
1. **空字符串草稿被当作有效内容加载**`saveDraftToStorage` 在组件卸载时自动保存草稿。如果用户未在编辑器中输入任何内容,保存的 `content` 会是空字符串 `""`。在初始化 effect 中,判断条件 `typeof draft.content === 'string'` 对空字符串也返回 `true`,导致编辑器被填充为空白 HTML跳过了后续默认模板加载逻辑。
2. **草稿中未记录模板 ID**`loadedTemplateId` 没有被存入 draft。当从 draft 恢复时,即使内容非空,模板选择器也因缺少 `loadedTemplateId` 而显示"无"。
3. **默认模板加载逻辑被空白草稿截断**:由于空草稿提前将 `contentLoadedRef.current` 设为 `true`,真正的默认模板分支 (`settings.defaultTemplate`) 永远不会执行。
## 验收标准
- [ ] 超级管理员进入 report-editor 时,编辑区域正确显示 system-settings 中设置的默认模板内容。
- [ ] 模板选择器显示当前已加载的默认模板名称,而非"无"。
- [ ] 从 dashboard 等其他页面返回 report-editor未编辑情况下不显示空白模板。
- [ ] `npm run lint` 类型检查零错误。
- [ ] `npm run build` 构建通过。