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
This commit is contained in:
29
工程分析/经验记录.md
29
工程分析/经验记录.md
@@ -345,6 +345,35 @@ if ((settings.autoInsertDelay || 0) > 0) {
|
||||
|
||||
---
|
||||
|
||||
## 记录 15:默认模板新增术后 4 个字段并自动补全老用户配置
|
||||
|
||||
**A. 具体问题**
|
||||
需要在默认手术报告模板中新增 4 个字段(手术后情况、切除标本描述、是否送检病理、冰冻病理结果),使其与右侧【基本信息】动态表单双向联动。同时,老用户浏览器 localStorage 中已存在的 `formFieldsConfig` 不包含这 4 个字段,直接发版会导致老用户看不到新控件。
|
||||
|
||||
**B. 产生问题原因**
|
||||
1. `DEFAULT_FORM_FIELDS` 和 `defaultContent.ts` 是代码层面的默认值,但 `ReportEditor.tsx` 和 `TemplateManage.tsx` 的初始化逻辑是"若 localStorage 中已存在 `formFieldsConfig`,则直接使用,不再回退到代码默认值"。
|
||||
2. 因此,新增字段只对新用户(localStorage 为空)生效,老用户的字段列表会永远停留在旧版本。
|
||||
|
||||
**C. 解决问题方案**
|
||||
1. 在 `src/types.ts` 的 `Report` 接口中追加 4 个新字段;在 `DEFAULT_FORM_FIELDS` 末尾追加 4 条配置(含 `options`)。
|
||||
2. 在 `src/utils/defaultContent.ts` 中,将模板底部对应 4 处静态文本/占位色 `<span>` 替换为 `${smartField('key')}`。
|
||||
3. 在 `ReportEditor.tsx` 和 `TemplateManage.tsx` 的初始化 `useEffect` 中,读取 `formFieldsConfig` 后增加**缺失字段自动补全逻辑**:
|
||||
```ts
|
||||
const missing = DEFAULT_FORM_FIELDS.filter(def => !savedFields.some(f => f.key === def.key));
|
||||
if (missing.length > 0) {
|
||||
mergedFields = [...savedFields, ...missing];
|
||||
storage.set('formFieldsConfig', mergedFields);
|
||||
}
|
||||
```
|
||||
这样老用户首次进入页面时,缺失字段会自动追加到列表末尾,同时保留用户已有的自定义字段和显隐设置。
|
||||
|
||||
**D. 后续如何避免问题**
|
||||
- 任何依赖 `localStorage` 持久化配置的"字段/菜单/权限"列表,在后续版本新增默认值时,都应提供**自动合并/升级逻辑**,而不是简单依赖"有值则跳过"。
|
||||
- 合并策略推荐:以代码层 `DEFAULT_xxx` 为基准,检测缺失 key 并追加,保留用户已有的自定义项和状态,实现无痛升级。
|
||||
- 对于模板 HTML 的变更,若旧模板已存入 `templates` localStorage,则默认模板只影响新建报告;若需要更新已有模板,需额外提供模板升级脚本或管理员手动维护机制。
|
||||
|
||||
---
|
||||
|
||||
## 记录 14:智能字段插入间距修复与 Backspace 防误删
|
||||
|
||||
**A. 具体问题**
|
||||
|
||||
Reference in New Issue
Block a user