fix(ui): 打印隐藏AI区域蓝框 + diff弹窗字体统一

- print.ts的iframe样式中增加.ai-region隐藏规则:去除边框/背景/内边距,隐藏右上角标签
- diffModal右侧AI提议版本容器增加style属性:fontFamily SimSun、fontSize 12pt、lineHeight 1.5
- 确保打印输出和diff对比的视觉一致性
This commit is contained in:
2026-04-19 18:25:38 +08:00
parent 6abd7d1e3a
commit b24ba08658
6 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
# 实现方案
## 修改文件 1`src/utils/print.ts`
在 iframe 的 `<style>` 标签中,增加 `.ai-region` 的打印隐藏样式。
**原代码**line 23-48 的 style 块):
```css
.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 { 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; line-height: 1 !important; }
.smart-field-wrapper .field-value.no-underline { border-bottom: none !important; }
}
```
**新代码**
```css
.report-signature-img { max-width: 120px; max-height: 40px; width: auto; height: auto; object-fit: contain; vertical-align: middle; display: inline-block; }
.ai-region { border: none !important; background: transparent !important; padding: 0 !important; margin: 0 !important; }
.ai-region > [contenteditable="false"] { display: none !important; }
@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 0px 2px !important; line-height: 1 !important; }
.smart-field-wrapper .field-value.no-underline { border-bottom: none !important; }
}
```
**变更点**
1. 新增 `.ai-region` 样式:去除边框、背景、内边距、外边距
2. 新增 `.ai-region > [contenteditable="false"]` 样式:隐藏右上角标签
## 修改文件 2`src/pages/ReportEditor.tsx`
在 diffModal 右侧「AI 提议版本」容器上增加 `style` 属性。
**原代码**line 2630-2636
```tsx
<div
className="p-4 flex-1 overflow-y-auto outline-none custom-scrollbar"
contentEditable
suppressContentEditableWarning
onBlur={(e) => setDiffModal(prev => prev ? { ...prev, newHtml: e.target.innerHTML } : null)}
dangerouslySetInnerHTML={{ __html: diffModal.newHtml }}
></div>
```
**新代码**
```tsx
<div
className="p-4 flex-1 overflow-y-auto outline-none custom-scrollbar"
contentEditable
suppressContentEditableWarning
onBlur={(e) => setDiffModal(prev => prev ? { ...prev, newHtml: e.target.innerHTML } : null)}
dangerouslySetInnerHTML={{ __html: diffModal.newHtml }}
style={{ fontFamily: 'SimSun, "Microsoft YaHei", serif', fontSize: '12pt', lineHeight: '1.5' }}
></div>
```
**变更点**:增加 `style` 属性,指定宋体 12pt、行高 1.5,与编辑器正文样式一致。

View File

@@ -0,0 +1,41 @@
# 测试方案
## 测试环境
- 浏览器访问 `http://localhost:4173/`
- 进入「图文报告生成」→ 新建报告
## 测试用例 1打印时 AI 区域蓝框隐藏
**步骤**
1. 编辑器中插入 AI 可编辑区域,写入一些内容
2. 点击「打印」按钮(或导出/下载)
3. 观察打印预览或生成的 PDF
**预期结果**
- AI 可编辑区域的蓝色虚线边框不显示
- 右上角「XX-AI可编辑区域」标签不显示
- 灰色背景不显示
- 文字正常显示,排版整洁
## 测试用例 2diff 弹窗字体统一
**步骤**
1. 编辑器中插入 AI 可编辑区域,写入带宋体 12pt 样式的内容
2. 勾选「允许修改正文」→ 发送修改指令
3. 观察 diff 弹窗左右两侧
**预期结果**
- 左侧「原始版本」显示宋体 12pt
- 右侧「AI 提议版本」也应显示宋体 12pt与左侧视觉一致
- 行高一致1.5
## 测试用例 3编译与部署
**步骤**
1. 执行 `npm run build`
2. 确认无 TypeScript 编译错误
3. 预览服务正常启动并返回 200
**预期结果**
- `vite build` 成功完成
- 预览页面可正常访问

View File

@@ -0,0 +1,31 @@
# 需求分析
## 时间戳
2026-04-19 18:22
## 需求来源
用户希望优化两个视觉问题:
1. 点击下载或打印时,不显示 AI 可编辑区域的蓝色虚线框和标签
2. AI 修改确认弹窗中右侧「AI 提议版本」的字体和大小与左侧「原始版本」统一
## 问题 1打印/下载时 AI 区域蓝框未隐藏
**现象**打印或下载报告时AI 可编辑区域的蓝色虚线边框和右上角标签仍然显示。
**根因分析**
- `src/utils/print.ts` 使用 iframe 生成打印文档,其 `<style>` 中没有针对 `.ai-region` 的隐藏样式
- `src/index.css` 中有 `.print-content .ai-region` 的样式,但 `print.ts` 中实际使用的是 `.content`CSS 选择器不匹配
- `@media print``index.css` 中只影响浏览器打印预览,不影响 `print.ts` 的 iframe
## 问题 2diff 弹窗右侧字体不一致
**现象**:左侧「原始版本」显示宋体 12pt右侧「AI 提议版本」显示默认字体(无衬线体),视觉不一致。
**根因分析**
- 左侧原始版本的文本带有内联样式(如 `<span style="font-family: SimSun; font-size: 12pt;">`
- 右侧 AI 返回的是纯净的 `<p>` 标签,没有内联样式
- diff 弹窗右侧容器没有设置默认字体样式,导致浏览器使用默认字体
## 解决方向
1.`print.ts` 的 iframe `<style>` 中增加 `.ai-region` 的打印隐藏样式
2. 在 diff 弹窗右侧容器的 `style` 属性中指定与正文一致的字体和字号