# 实现方案 —— 2026-04-18-18-08-37 ## 方案目标 修复并增强编辑器工具栏的字体/字号/行距功能,调整默认模板排版细节。 ## 需求 1:修复字体选择并新增字号、行距功能 ### 修改文件 `src/pages/ReportEditor.tsx` 和 `src/pages/TemplateManage.tsx` ### 实现步骤 1. **修复字体选择**:确保工具栏中的字体选择 ``: ```tsx ``` `execCommand('fontSize')` 使用 1-7 的相对字号,3 对应 12pt,4 对应 14pt,5 对应 18pt。 3. **新增行距选择**:`execCommand` 不支持行距,需手写 `changeLineHeight` 函数: ```tsx const changeLineHeight = (height: string) => { const sel = window.getSelection(); if (!sel || !sel.rangeCount) return; let node = sel.getRangeAt(0).commonAncestorContainer; if (node.nodeType === Node.TEXT_NODE) node = node.parentNode as Node; const block = (node as HTMLElement).closest('p, div, td, h1, h2, h3'); if (block) { (block as HTMLElement).style.lineHeight = height; if (editorRef.current) contentRef.current = editorRef.current.innerHTML; saveDraftToStorage(); } }; ``` 在工具栏增加行距 `