Files
Mdeical_Sur_Report/工程分析/需求分析-2026-04-17-09-57-08.md
admin 9e75e86454 feat: add 4 post-op fields to default template with auto-merge for existing configs
- Add postOpCondition, specimenDescription, pathologySent, frozenPathology
  to Report type and DEFAULT_FORM_FIELDS
- Replace static placeholders in defaultContent.ts with smartField() calls
- Auto-merge missing fields from DEFAULT_FORM_FIELDS into existing
  formFieldsConfig in ReportEditor and TemplateManage
2026-04-17 10:11:48 +08:00

46 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-17-09-57-08
## 一、需求来源
用户要求在默认手术报告模板中进一步插入 4 个新字段,并使其与右侧【基本信息】动态表单联动。
## 二、具体字段清单
| 序号 | 字段名称 | 字段 key | 类型 | 分类 | 选项 | 表单显隐 |
|------|----------|----------|------|------|------|----------|
| 1 | 手术后情况 | `postOpCondition` | 单选 | 单选 | `患者麻醉恢复后安返病房` | 显示 |
| 2 | 切除标本描述 | `specimenDescription` | 单选 | 单选 | 暂无(空数组) | 显示 |
| 3 | 是否送检病理 | `pathologySent` | 单选 | 单选 | `是`, `否` | 显示 |
| 4 | 冰冻病理结果 | `frozenPathology` | 填空 | text | — | 显示 |
## 三、影响范围分析
1. **`src/types.ts`**
- 需要在 `Report` 接口中新增 4 个字段定义,保持类型安全。
- 需要在 `DEFAULT_FORM_FIELDS` 数组末尾追加 4 条 `FormField` 配置。
2. **`src/utils/defaultContent.ts`**
- 默认模板 HTML 中,当前"手术后情况"、"切除标本描述"、"是否送病理检查"、"冰冻病理结果"均为纯文本或占位色 `<span>`
- 需要将这 4 处替换为 `${smartField('key')}` 调用,使其具备双向绑定能力。
3. **`src/pages/ReportEditor.tsx`**
- 右侧表单已经是"配置驱动渲染"(遍历 `formFieldsConfig``type` switch-case新增字段后无需修改 JSX。
- 表单 → 编辑器的同步 `useEffect` 使用 `(reportData as any)[fieldKey]` 读取,对新字段自动生效。
- 编辑器 → 表单的 `handleEditorInput` 通过 `data-bind` 属性反射,同样自动生效。
4. **`src/pages/TemplateManage.tsx`**
- 字段库侧边栏读取 `formFieldsConfig`,新增配置后自动显示在【插入字段】列表中。
- 无需额外修改。
## 四、兼容性说明
- 旧用户 localStorage 中已存在 `formFieldsConfig`,如果其中不包含新字段,则首次进入 `ReportEditor`/`TemplateManage` 时只会显示旧字段。
- **策略**:由于系统当前逻辑是"若 `formFieldsConfig` 有值则直接使用,不再回退到 `DEFAULT_FORM_FIELDS`",因此需要额外提供一个**字段合并/升级逻辑**,在初始化时检测缺失字段并自动补入,确保老用户也能看到这 4 个新字段。
## 五、验收标准
- [ ] 新建报告时,默认模板中"手术后情况"等 4 处显示为可编辑的智能方框。
- [ ] 右侧【基本信息】表单中出现对应的 4 个输入控件3 个单选下拉 + 1 个文本框)。
- [ ] 表单修改值后,模板中的方框实时同步;在方框中直接输入后,表单也实时同步。
- [ ] 老用户(已有 `formFieldsConfig`)首次进入页面时,自动补全这 4 个缺失字段。