# 实现方案 — 2026-04-17-00-13-09 ## 根因分析 当前系统存在三个核心问题: 1. **时间字段未联动**:`defaultContent.ts` 中手术开始/终止时间是纯文本占位符,无 `data-bind`,导致右侧表单与正文内容无法同步。 2. **表单硬编码不可扩展**:`ReportEditor.tsx` 右侧的基本信息表单是写死的 JSX,每新增一个字段都需要改代码;`TemplateManage.tsx` 的字段库也是静态数组,无法按医院实际需求自定义。 3. **方格 UI 破坏排版**:`field-value` 使用了较大的 `min-width` 和上下 `padding`,在 `inline-block` 布局下撑大了行高,导致段落行间距明显变大。 ## 修改文件清单 | 文件 | 修改类型 | 说明 | |------|---------|------| | `src/types.ts` | 修改 | 新增 `FieldType`、`FormField`、`FormFieldsConfig` 类型 | | `src/utils/defaultContent.ts` | 修改 | 手术时间替换为 `startTime`/`endTime` 智能方格 | | `src/index.css` | 修改 | 优化 `.field-value` 紧凑样式 | | `src/utils/print.ts` | 修改 | 同步打印样式 | | `src/pages/TemplateManage.tsx` | 修改 | 字段库重构为 Tab 结构,支持分类、新增、显隐控制 | | `src/pages/ReportEditor.tsx` | 修改 | 右侧表单动态渲染 + 时间解析拼接双向转换 | | `src/pages/Login.tsx` | 修改 | 首次登录时初始化默认字段配置到 localStorage | --- ## 具体代码变更 ### 变更 1:`src/types.ts` — 动态字段类型定义 **在 `BINDABLE_FIELDS` 之后追加:** ```typescript export type FieldType = 'text' | 'single_select' | 'multi_select' | 'time' | 'date'; export interface FormField { key: string; label: string; category: string; // 如 '填空'、'单选'、'多选'、'时间' type: FieldType; visibleInForm: boolean; isSystemLocked: boolean; options?: string[]; } export const DEFAULT_FORM_FIELDS: FormField[] = [ { key: 'patientName', label: '患者姓名', category: '填空', type: 'text', visibleInForm: true, isSystemLocked: true }, { key: 'hospitalId', label: '住院号', category: '填空', type: 'text', visibleInForm: true, isSystemLocked: true }, { key: 'title', label: '手术名称', category: '填空', type: 'text', visibleInForm: true, isSystemLocked: false }, { key: 'patientGender', label: '患者性别', category: '单选', type: 'single_select', visibleInForm: true, isSystemLocked: false, options: ['男', '女'] }, { key: 'patientAge', label: '患者年龄', category: '填空', type: 'text', visibleInForm: true, isSystemLocked: false }, { key: 'department', label: '科别', category: '填空', type: 'text', visibleInForm: true, isSystemLocked: false }, { key: 'bedNumber', label: '床号', category: '填空', type: 'text', visibleInForm: true, isSystemLocked: false }, { key: 'surgeryDate', label: '手术日期', category: '时间', type: 'date', visibleInForm: true, isSystemLocked: false }, { key: 'startTime', label: '手术开始时间', category: '时间', type: 'time', visibleInForm: true, isSystemLocked: false }, { key: 'endTime', label: '手术终止时间', category: '时间', type: 'time', visibleInForm: true, isSystemLocked: false }, { key: 'surgeon', label: '手术者', category: '多选', type: 'multi_select', visibleInForm: true, isSystemLocked: false, options: ['张医生', '李医生', '王医生'] }, { key: 'assistant', label: '助手', category: '多选', type: 'multi_select', visibleInForm: true, isSystemLocked: false, options: ['赵医生', '钱医生', '孙医生'] }, { key: 'anesthesiologist', label: '麻醉师', category: '多选', type: 'multi_select', visibleInForm: true, isSystemLocked: false, options: ['周医生', '吴医生', '郑医生'] }, { key: 'anesthesiaType', label: '麻醉方式', category: '单选', type: 'single_select', visibleInForm: true, isSystemLocked: false, options: ['全麻', '局麻', '腰麻', '硬膜外麻醉', '静脉麻醉', '吸入麻醉'] }, ]; ``` ### 变更 2:`src/utils/defaultContent.ts` — 手术时间方框化 **替换手术时间相关段落:** ```typescript

手术开始时间:${smartField('startTime')} 手术终止时间:${smartField('endTime')}

``` > 注意:同时需要把 `smartField` 函数的样式字符串更新为紧凑版本(见变更 4)。 ### 变更 3:`src/utils/defaultContent.ts` — 更新 `smartField` 紧凑样式 **替换现有的 `smartField` 函数:** ```typescript const smartField = (key: string) => ` `; ``` ### 变更 4:`src/index.css` — 同步优化 `.field-value` 样式 **在 `.smart-field-wrapper` 相关样式区块中更新 `.field-value`:** ```css .smart-field-wrapper .field-value { min-width: 32px; padding: 0 4px; margin: 0 2px; border: 1px solid #cbd5e1; border-radius: 2px; display: inline-block; background: #f8fafc; color: #0f172a; line-height: 1.2; font-size: inherit; vertical-align: text-bottom; box-sizing: border-box; min-height: 1.2em; outline: none; } ``` **打印样式同步更新:** ```css @media print { .smart-field-wrapper .field-value { border: none !important; border-bottom: 1px solid #000 !important; border-radius: 0 !important; background: transparent !important; padding: 0 2px !important; } } ``` ### 变更 5:`src/utils/print.ts` — 同步打印样式 在 iframe 内联 `