feat: field hover highlight, e-signature upload, surgeon signature linkage

- Add signature?: string to User type and 'signature' to FieldType
- Add surgeonSignature field to DEFAULT_FORM_FIELDS (category: 图片)
- UserManage: add canvas-based image compression (max 500px) and signature upload UI
- TemplateManage: add hover highlight on field buttons via direct DOM style manipulation
- TemplateManage: add '图片' category to field library for surgeonSignature insertion
- ReportEditor: auto-fill surgeonSignature with currentUser.signature image or placeholder text
- index.css & print.ts: add .report-signature-img styling (height 2.4em, vertical-align middle)
- Update experience record (#18)
This commit is contained in:
2026-04-17 12:04:23 +08:00
parent 0ff1cbe5f0
commit 424407a17e
10 changed files with 445 additions and 4 deletions

View File

@@ -409,6 +409,50 @@ if ((settings.autoInsertDelay || 0) > 0) {
---
## 记录 18字段悬浮高亮、电子签上传与手术者签名联动
**A. 具体问题**
1. `TemplateManage` 中右侧字段库按钮与编辑器中的字段缺乏视觉关联,用户难以快速定位字段位置。
2. `UserManage` 缺少电子签名上传功能,无法为医生绑定个人签名图。
3. 模板中缺少"手术者签名"字段,报告编辑时无法自动带入医生签名。
4. 签名图片若直接放入 `.field-value` 中,容易撑大行高,影响排版和打印效果。
**B. 产生问题原因**
1. 字段库按钮没有任何与编辑器 DOM 联动的交互反馈机制。
2. 早期设计未考虑医疗文书中的电子签需求,`User` 模型和 `DEFAULT_FORM_FIELDS` 均缺少签名相关定义。
3. 没有针对签名图片设计专门的 CSS 尺寸约束,导致浏览器按原图尺寸渲染,破坏行高。
**C. 解决问题方案**
1. **悬浮高亮**:在 `TemplateManage.tsx` 的字段库按钮上增加 `onMouseEnter` / `onMouseLeave`,直接操作编辑器中对应 `data-bind` 的 `.field-value` 的 `style.boxShadow` 和 `style.backgroundColor`,实现蓝色外发光/背景变浅蓝色的即时高亮反馈。
2. **电子签上传与压缩**
- 在 `UserManage.tsx` 中增加 `compressImage(file, maxSize=500)` 工具函数,利用 Canvas 等比例缩放并填充白色背景,输出 JPEG base64质量 0.8)。
- 在用户编辑/新增弹窗中增加"电子签名"区块:预览图、上传按钮、清除按钮。
- 编辑当前登录用户时同步更新 `storage.set('currentUser', ...)`,确保 ReportEditor 能读取最新签名。
3. **手术者签名字段**
- `types.ts` 中 `User` 增加 `signature?: string``FieldType` 增加 `'signature'``DEFAULT_FORM_FIELDS` 追加 `surgeonSignature`(分类"图片",系统锁定)。
- `TemplateManage` 插入字段分类增加"图片"`surgeonSignature` 自动出现在该分类下。
- `ReportEditor` 的"表单 → 编辑器"同步 `useEffect` 中,对 `fieldKey === 'surgeonSignature'` 做特殊分支:有签名则填充 `<img class="report-signature-img" src="..." />`,无签名则填充文本"【请上传电子签】"。
4. **签名排版优化**
- 在 `index.css` 和 `print.ts` 中定义 `.report-signature-img`
```css
.report-signature-img {
height: 2.4em;
width: auto;
vertical-align: middle;
display: inline-block;
margin: -0.3em 0;
}
```
- 打印媒体查询中同步使用 `!important` 确保打印输出也保持同样尺寸。
**D. 后续如何避免问题**
- 当需要在 React 之外直接操作 DOM 样式实现即时反馈时,优先使用原生事件 + inline style避免触发组件重渲染导致光标丢失
- 任何新增的持久化字段应在类型定义TypeScript interface、默认值DEFAULT_xxx、以及所有相关读写逻辑中同步补齐防止类型不一致。
- 在 `contentEditable` 中插入图片时,务必通过 CSS 对 `height`/`width`/`vertical-align` 做严格约束,避免原图尺寸破坏文本流。
- 涉及打印的样式必须在 iframe 打印模板和 `@media print` 中双端同步,防止打印效果与屏幕预览不一致。
---
## 记录 14智能字段插入间距修复与 Backspace 防误删
**A. 具体问题**