diff --git a/src/pages/ReportEditor.tsx b/src/pages/ReportEditor.tsx index 5bdeca1..f9f57f0 100644 --- a/src/pages/ReportEditor.tsx +++ b/src/pages/ReportEditor.tsx @@ -60,14 +60,16 @@ export default function ReportEditor() { if (!editorRef.current) return; const allFields = editorRef.current.querySelectorAll('.field-value'); allFields.forEach(el => { - (el as HTMLElement).style.backgroundColor = '#f8fafc'; - (el as HTMLElement).style.boxShadow = 'none'; + (el as HTMLElement).style.backgroundColor = ''; + (el as HTMLElement).style.outline = ''; + (el as HTMLElement).style.outlineOffset = ''; }); if (activeFieldKey) { const targetEl = editorRef.current.querySelector(`.field-value[data-bind="${activeFieldKey}"]`) as HTMLElement; if (targetEl) { - targetEl.style.backgroundColor = '#eff6ff'; - targetEl.style.boxShadow = '0 0 0 2px #3b82f6'; + targetEl.style.backgroundColor = '#f1f5f9'; + targetEl.style.outline = '1px solid #94a3b8'; + targetEl.style.outlineOffset = '1px'; targetEl.scrollIntoView({ behavior: 'smooth', block: 'center' }); } } @@ -432,6 +434,9 @@ export default function ReportEditor() { return; } + // 点击空白处清除高亮 + setActiveFieldKey(null); + const placeholder = targetEl.closest('.image-placeholder') as HTMLElement | null; if (!placeholder) return; diff --git a/src/pages/TemplateManage.tsx b/src/pages/TemplateManage.tsx index 730df4d..0490086 100644 --- a/src/pages/TemplateManage.tsx +++ b/src/pages/TemplateManage.tsx @@ -499,6 +499,19 @@ export default function TemplateManage() { setFormFields(updated); storage.set('formFieldsConfig', updated); setEditingFieldKey(null); + + // 同步更新编辑器中已插入字段的 classList + if (editorRef.current) { + const els = editorRef.current.querySelectorAll(`.field-value[data-bind="${key}"]`); + els.forEach(el => { + if (editFieldHasUnderline) { + el.classList.remove('no-underline'); + } else { + el.classList.add('no-underline'); + } + }); + saveTemplateContent(); + } }; const addField = () => { diff --git a/src/utils/print.ts b/src/utils/print.ts index 5d7ff2e..e977e2a 100644 --- a/src/utils/print.ts +++ b/src/utils/print.ts @@ -42,7 +42,7 @@ export const printDocument = (htmlContent: string, docTitle: string = '图文报 .smart-field-wrapper .field-value { min-width: 24px; padding: 0 2px; margin: 0; border: 1px solid #cbd5e1; border-radius: 2px; display: inline-block; background: #f8fafc; color: #0f172a; line-height: inherit; font-size: inherit; vertical-align: baseline; box-sizing: border-box; outline: none; text-align: center; } .report-signature-img { max-width: 120px; max-height: 40px; width: auto; height: auto; object-fit: contain; vertical-align: middle; display: inline-block; } @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 0px 2px !important; } + .smart-field-wrapper .field-value { outline: none !important; box-shadow: none !important; border: none !important; border-bottom: 1px solid #000 !important; border-radius: 0 !important; background: transparent !important; padding: 0 2px 0px 2px !important; } .smart-field-wrapper .field-value.no-underline { border-bottom: none !important; } } diff --git a/工程分析/实现方案-2026-04-19-00-01-50.md b/工程分析/实现方案-2026-04-19-00-01-50.md new file mode 100644 index 0000000..8685832 --- /dev/null +++ b/工程分析/实现方案-2026-04-19-00-01-50.md @@ -0,0 +1,65 @@ +# 实现方案 —— 2026-04-19-00-01-50 + +## 方案目标 +修复高亮样式、实现点击空白取消、阻断打印高亮、同步字段下划线配置到已插入的 DOM。 + +## 需求 1 & 2:优化高亮样式、点击空白取消、阻断打印 + +### 修改文件 1:`src/pages/ReportEditor.tsx` + +1. **点击空白取消高亮**:在 `handleEditorClick` 中,如果点击目标不是 `.field-value`,则设置 `setActiveFieldKey(null)`。 + +2. **柔和高亮样式**:修改 `activeFieldKey` 的 `useEffect`: + - 清除样式时:恢复为 `''`(空字符串)而非硬编码颜色,让 CSS 类重新接管 + - 高亮时:`backgroundColor: '#f1f5f9'`(浅灰)、`outline: '1px solid #94a3b8'`(细灰边框)、`outlineOffset: '1px'` + - 不再使用 `box-shadow` + +### 修改文件 2:`src/utils/print.ts` + +在 `@media print` 中强制抹除 `outline` 和 `box-shadow`: +```css +@media print { + .smart-field-wrapper .field-value { + outline: none !important; + box-shadow: none !important; + border: none !important; + border-bottom: 1px solid #000 !important; + border-radius: 0 !important; + background: transparent !important; + padding: 0 2px 1px 2px !important; + } + .smart-field-wrapper .field-value.no-underline { border-bottom: none !important; } +} +``` + +## 需求 3:修复下划线勾选无效 + +### 修改文件:`src/pages/TemplateManage.tsx` + +在 `saveFieldEdit` 函数中,保存字段配置后,扫描编辑器中所有 `data-bind` 匹配的 `.field-value`,根据新的 `hasUnderline` 值动态添加/移除 `.no-underline` 类: +```ts +if (editorRef.current) { + const els = editorRef.current.querySelectorAll(`.field-value[data-bind="${editingFieldId}"]`); + els.forEach(el => { + if (editFieldHasUnderline) { + el.classList.remove('no-underline'); + } else { + el.classList.add('no-underline'); + } + }); + saveTemplateContent(); +} +``` + +## 涉及文件及修改点 +| 文件 | 修改点 | +|------|--------| +| `src/pages/ReportEditor.tsx` | handleEditorClick 点击空白取消高亮;useEffect 柔和高亮样式 | +| `src/utils/print.ts` | @media print 强制抹除 outline/box-shadow | +| `src/pages/TemplateManage.tsx` | saveFieldEdit 同步更新已插入字段的 classList | + +## 风险与注意事项 +1. `handleEditorClick` 中增加 `setActiveFieldKey(null)` 时,需确保不会影响 `.image-placeholder` 的点击处理逻辑(placeholder 点击在 field-value 判断之后)。 +2. `useEffect` 中清除样式时使用 `style.backgroundColor = ''` 而非 `= '#f8fafc'`,这样可以让元素的 CSS 类样式重新生效,避免硬编码颜色与 CSS 类冲突。 +3. `saveFieldEdit` 中扫描 DOM 并修改 classList 后,必须调用 `saveTemplateContent()` 将变更持久化到 localStorage。 +4. 打印样式中 `outline: none !important` 和 `box-shadow: none !important` 的优先级需确保高于任何内联样式。 diff --git a/工程分析/测试方案-2026-04-19-00-01-50.md b/工程分析/测试方案-2026-04-19-00-01-50.md new file mode 100644 index 0000000..d565620 --- /dev/null +++ b/工程分析/测试方案-2026-04-19-00-01-50.md @@ -0,0 +1,48 @@ +# 测试方案 —— 2026-04-19-00-01-50 + +## 测试目标 +验证高亮样式修复、点击空白取消、打印纯净度、下划线同步的有效性。 + +## 测试用例 + +### TC-1:高亮样式柔和 +**前置条件**:ReportEditor 已加载默认模板。 +**步骤**: +1. 点击中间模板中的任意字段。 +**预期结果**:字段显示浅灰色背景和细灰边框(不再是刺眼的蓝色)。 + +### TC-2:点击空白取消高亮 +**前置条件**:ReportEditor 中某个字段已被高亮。 +**步骤**: +1. 点击模板中的空白区域(非字段、非占位符)。 +**预期结果**:字段高亮样式消失,恢复为默认状态。 + +### TC-3:打印不带高亮框 +**前置条件**:ReportEditor 中某个字段处于高亮状态。 +**步骤**: +1. 点击打印预览。 +**预期结果**:打印内容中不显示任何高亮框、outline 或 box-shadow,字段显示正常。 + +### TC-4:勾选下划线后打印生效 +**前置条件**:TemplateManage 中某字段已插入模板,且未勾选下划线。 +**步骤**: +1. 在字段管理中勾选该字段的「打印时显示下划线」。 +2. 保存字段编辑。 +3. 在 ReportEditor 中打印预览。 +**预期结果**:该字段显示下划线。 + +### TC-5:取消下划线后打印不显示 +**前置条件**:TemplateManage 中某字段已勾选下划线并保存。 +**步骤**: +1. 取消勾选该字段的「打印时显示下划线」。 +2. 保存字段编辑。 +3. 在 ReportEditor 中打印预览。 +**预期结果**:该字段不显示下划线。 + +## 回归测试 +- 确保字段插入、编辑、删除功能正常。 +- 确保双向联动(中间点击→右侧高亮、右侧点击→中间高亮)正常。 +- 确保打印样式整体正常。 + +## 测试通过标准 +所有用例均通过,无控制台报错,打印内容纯净无高亮残留。 diff --git a/工程分析/经验记录.md b/工程分析/经验记录.md index c2f87aa..c4b05ab 100644 --- a/工程分析/经验记录.md +++ b/工程分析/经验记录.md @@ -1185,3 +1185,41 @@ if ((settings.autoInsertDelay || 0) > 0) { - iframe 打印的文件名行为在不同浏览器间存在差异(Chrome 用父窗口 title,Safari 可能用 iframe title),最稳妥的方案是同时设置父窗口 `document.title` 和 iframe 内部 `