Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48337c382c | ||
|
|
726bbc5bac | ||
|
|
c5648077e8 | ||
|
|
9c09e6cccc |
@@ -426,7 +426,7 @@ export default function ReportEditor() {
|
||||
const text = w > 0 && w < 80 ? '插图' : '插入/点击放置图片';
|
||||
placeholder.innerHTML = `
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${text}</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${text}</span>
|
||||
`;
|
||||
placeholder.style.border = '1px dashed #cbd5e1';
|
||||
placeholder.style.background = '#f8fafc';
|
||||
@@ -2036,13 +2036,13 @@ export default function ReportEditor() {
|
||||
let html: string;
|
||||
if (inTable) {
|
||||
const styleStr = 'position:relative;display:flex;align-items:center;justify-content:center;border:1px dashed #cbd5e1;background:#f8fafc;cursor:pointer;width:100%;height:100%;max-width:200px;max-height:200px;min-height:60px;margin:0 auto;';
|
||||
html = `<div id="${id}" class="image-placeholder" data-placeholder="true" contenteditable="false"${modeAttr} style="${styleStr}"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${hintText}</span></div>`;
|
||||
html = `<div id="${id}" class="image-placeholder" data-placeholder="true" contenteditable="false"${modeAttr} style="${styleStr}"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${hintText}</span></div>`;
|
||||
} else {
|
||||
let styleStr = 'display:inline-block;text-align:center;border:1px dashed #cbd5e1;background:#f8fafc;vertical-align:middle;margin:0 4px;cursor:pointer;position:relative;';
|
||||
styleStr += `width:${w}px;height:${h}px;max-width:${w}px;max-height:${h}px;line-height:${h}px;`;
|
||||
const showShortText = w > 0 && w < 80;
|
||||
const text = showShortText ? '插图' : hintText;
|
||||
html = `<span id="${id}" class="image-placeholder" data-placeholder="true" contenteditable="false"${modeAttr} style="${styleStr}"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${text}</span></span>​`;
|
||||
html = `<span id="${id}" class="image-placeholder" data-placeholder="true" contenteditable="false"${modeAttr} style="${styleStr}"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${text}</span></span>​`;
|
||||
}
|
||||
execCmd('insertHTML', html);
|
||||
setPlaceholderModal({...placeholderModal, isOpen: false});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import Sidebar from '../components/Sidebar';
|
||||
import { Plus, Edit, Trash2, Save, Printer, Undo, Redo, Bold, Italic, Underline, AlignLeft, AlignCenter, AlignRight, Table, Image as ImageIcon, Check, Download } from 'lucide-react';
|
||||
import { Plus, Edit, Trash2, Save, Printer, Undo, Redo, Bold, Italic, Underline, AlignLeft, AlignCenter, AlignRight, Table, Image as ImageIcon, Check, Download, Upload } from 'lucide-react';
|
||||
import { User, Template, FormField, FieldType, DEFAULT_FORM_FIELDS } from '../types';
|
||||
import { defaultReportContent } from '../utils/defaultContent';
|
||||
import { printDocument } from '../utils/print';
|
||||
@@ -16,6 +16,8 @@ export default function TemplateManage() {
|
||||
const [exportModalOpen, setExportModalOpen] = useState(false);
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [formData, setFormData] = useState({ name: '', desc: '' });
|
||||
const [importedContent, setImportedContent] = useState<{content: string; fields: FormField[]} | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const [isSaved, setIsSaved] = useState(false);
|
||||
const editorRef = useRef<HTMLDivElement>(null);
|
||||
const savedRangeRef = useRef<Range | null>(null);
|
||||
@@ -35,11 +37,11 @@ export default function TemplateManage() {
|
||||
const [editFieldTimeFormat, setEditFieldTimeFormat] = useState('');
|
||||
const [editFieldTimeDefault, setEditFieldTimeDefault] = useState<'current' | 'specific'>('specific');
|
||||
const [editFieldFixedTimeValue, setEditFieldFixedTimeValue] = useState('');
|
||||
const [editFieldHasUnderline, setEditFieldHasUnderline] = useState(true);
|
||||
const [editFieldHasUnderline, setEditFieldHasUnderline] = useState(false);
|
||||
const [newFieldTimeFormat, setNewFieldTimeFormat] = useState('YYYY年MM月DD日');
|
||||
const [newFieldTimeDefault, setNewFieldTimeDefault] = useState<'current' | 'specific'>('specific');
|
||||
const [newFieldFixedTimeValue, setNewFieldFixedTimeValue] = useState('');
|
||||
const [newFieldHasUnderline, setNewFieldHasUnderline] = useState(true);
|
||||
const [newFieldHasUnderline, setNewFieldHasUnderline] = useState(false);
|
||||
const [customTimeFormats, setCustomTimeFormats] = useState<string[]>([]);
|
||||
const [formatDropdownOpen, setFormatDropdownOpen] = useState(false);
|
||||
const [newFormatDropdownOpen, setNewFormatDropdownOpen] = useState(false);
|
||||
@@ -128,6 +130,10 @@ export default function TemplateManage() {
|
||||
const template = templates.find(t => t.id === currentTemplateId);
|
||||
if (template) {
|
||||
editorRef.current.innerHTML = template.content;
|
||||
if (template.fields && template.fields.length > 0) {
|
||||
setFormFields(template.fields);
|
||||
storage.set('formFieldsConfig', template.fields);
|
||||
}
|
||||
}
|
||||
setTimeout(() => updatePageHeight(), 0);
|
||||
}
|
||||
@@ -416,7 +422,7 @@ export default function TemplateManage() {
|
||||
}
|
||||
pushHistory();
|
||||
|
||||
const underlineClass = field.hasUnderline === false ? ' no-underline' : '';
|
||||
const underlineClass = field.hasUnderline !== true ? ' no-underline' : '';
|
||||
const html = `<span class="smart-field-wrapper" contenteditable="false" style="white-space:nowrap;position:relative;"><span class="field-value${underlineClass}" data-bind="${field.key}" contenteditable="true" style="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;"> </span><span class="delete-btn" contenteditable="false">×</span></span>​`;
|
||||
|
||||
const sel = window.getSelection();
|
||||
@@ -598,6 +604,48 @@ export default function TemplateManage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleImportFile = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
const reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
try {
|
||||
const json = JSON.parse(event.target?.result as string);
|
||||
if (json.type !== 'surclaw_template_package') {
|
||||
alert('无效的模板包文件');
|
||||
return;
|
||||
}
|
||||
setFormData({ name: json.title || '', desc: json.description || '' });
|
||||
setImportedContent({
|
||||
content: json.content || '',
|
||||
fields: Array.isArray(json.fields) ? json.fields : []
|
||||
});
|
||||
} catch {
|
||||
alert('文件解析失败,请检查 JSON 格式');
|
||||
}
|
||||
};
|
||||
reader.readAsText(file);
|
||||
if (e.target) e.target.value = '';
|
||||
};
|
||||
|
||||
const handleExportTemplate = (template: Template) => {
|
||||
const exportData = {
|
||||
version: '1.0',
|
||||
type: 'surclaw_template_package',
|
||||
title: template.name,
|
||||
description: template.desc || '',
|
||||
content: template.content,
|
||||
fields: template.fields || formFields
|
||||
};
|
||||
const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `模板导出-${template.name}.json`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const handleModalSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const allTemplates = storage.get<Template[]>('templates', []);
|
||||
@@ -615,14 +663,19 @@ export default function TemplateManage() {
|
||||
id: 'tpl_' + Date.now(),
|
||||
name: formData.name,
|
||||
desc: formData.desc,
|
||||
content: defaultReportContent,
|
||||
content: importedContent?.content || defaultReportContent,
|
||||
createdAt: new Date().toISOString(),
|
||||
author: currentUser?.username || 'admin'
|
||||
author: currentUser?.username || 'admin',
|
||||
fields: importedContent?.fields || formFields
|
||||
};
|
||||
const updated = [...allTemplates, newTpl];
|
||||
setTemplates([...templates, newTpl]);
|
||||
storage.set('templates', updated);
|
||||
setCurrentTemplateId(newTpl.id);
|
||||
if (importedContent?.fields && importedContent.fields.length > 0) {
|
||||
setFormFields(importedContent.fields);
|
||||
storage.set('formFieldsConfig', importedContent.fields);
|
||||
}
|
||||
|
||||
const savedUsers = storage.get<User[]>('users', []);
|
||||
let updatedUsers = savedUsers;
|
||||
@@ -663,6 +716,7 @@ export default function TemplateManage() {
|
||||
}
|
||||
}
|
||||
setIsModalOpen(false);
|
||||
setImportedContent(null);
|
||||
};
|
||||
|
||||
if (!currentUser) return null;
|
||||
@@ -708,6 +762,12 @@ export default function TemplateManage() {
|
||||
>
|
||||
编辑
|
||||
</button>
|
||||
<button
|
||||
onClick={(e) => { e.stopPropagation(); handleExportTemplate(tpl); }}
|
||||
className="px-2 py-1 rounded-md bg-blue-50 text-blue-600 text-[10px] font-bold hover:bg-blue-100 transition-colors"
|
||||
>
|
||||
导出
|
||||
</button>
|
||||
{templates.length > 1 && (
|
||||
<button
|
||||
onClick={(e) => { e.stopPropagation(); handleDeleteTemplate(tpl.id); }}
|
||||
@@ -924,7 +984,7 @@ export default function TemplateManage() {
|
||||
setEditFieldTimeFormat(field.timeFormat || '');
|
||||
setEditFieldTimeDefault(field.timeDefault || 'specific');
|
||||
setEditFieldFixedTimeValue(field.fixedTimeValue || '');
|
||||
setEditFieldHasUnderline(field.hasUnderline !== false);
|
||||
setEditFieldHasUnderline(field.hasUnderline ?? false);
|
||||
const target = e.currentTarget;
|
||||
setTimeout(() => {
|
||||
target.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||||
@@ -1291,6 +1351,19 @@ export default function TemplateManage() {
|
||||
<div className="bg-white rounded-2xl p-10 w-full max-w-[500px] shadow-2xl border border-border">
|
||||
<h3 className="text-xl font-bold text-text-main mb-2">{isEditing ? '编辑模板信息' : '新增模板'}</h3>
|
||||
<p className="text-sm text-text-muted mb-8">设置模板的基本名称和描述</p>
|
||||
{!isEditing && (
|
||||
<div className="flex items-center gap-3 mb-6 p-3 bg-slate-50 rounded-xl border border-dashed border-slate-200">
|
||||
<div className="text-xs text-text-muted flex-1">已有模板文件?点击右侧图标导入</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="w-8 h-8 bg-accent text-white rounded-lg flex items-center justify-center hover:bg-blue-700 transition-colors shadow-sm"
|
||||
>
|
||||
<Upload size={16} />
|
||||
</button>
|
||||
<input ref={fileInputRef} type="file" accept=".json" className="hidden" onChange={handleImportFile} />
|
||||
</div>
|
||||
)}
|
||||
<form onSubmit={handleModalSubmit} className="space-y-6">
|
||||
<div className="space-y-1.5">
|
||||
<label className="block text-xs font-bold text-text-main uppercase tracking-wider">模板名称 *</label>
|
||||
@@ -1315,7 +1388,7 @@ export default function TemplateManage() {
|
||||
<div className="flex justify-end gap-3 pt-4 border-t border-border">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsModalOpen(false)}
|
||||
onClick={() => { setIsModalOpen(false); setImportedContent(null); }}
|
||||
className="px-6 py-2.5 bg-slate-100 text-text-muted rounded-lg text-sm font-semibold hover:bg-slate-200 transition-colors"
|
||||
>
|
||||
取消
|
||||
@@ -1376,13 +1449,13 @@ export default function TemplateManage() {
|
||||
let html: string;
|
||||
if (inTable) {
|
||||
const styleStr = 'position:relative;display:flex;align-items:center;justify-content:center;border:1px dashed #cbd5e1;background:#f8fafc;cursor:pointer;width:100%;height:100%;max-width:200px;max-height:200px;min-height:60px;margin:0 auto;';
|
||||
html = `<div id="${id}" class="image-placeholder" data-placeholder="true" contenteditable="false"${modeAttr} style="${styleStr}"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${hintText}</span></div>`;
|
||||
html = `<div id="${id}" class="image-placeholder" data-placeholder="true" contenteditable="false"${modeAttr} style="${styleStr}"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${hintText}</span></div>`;
|
||||
} else {
|
||||
let styleStr = 'display:inline-block;text-align:center;border:1px dashed #cbd5e1;background:#f8fafc;vertical-align:middle;margin:0 4px;cursor:pointer;position:relative;';
|
||||
styleStr += `width:${w}px;height:${h}px;max-width:${w}px;max-height:${h}px;line-height:${h}px;`;
|
||||
const showShortText = w > 0 && w < 80;
|
||||
const text = showShortText ? '插图' : hintText;
|
||||
html = `<span id="${id}" class="image-placeholder" data-placeholder="true" contenteditable="false"${modeAttr} style="${styleStr}"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${text}</span></span>​`;
|
||||
html = `<span id="${id}" class="image-placeholder" data-placeholder="true" contenteditable="false"${modeAttr} style="${styleStr}"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">${text}</span></span>​`;
|
||||
}
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.innerHTML = html;
|
||||
|
||||
@@ -67,6 +67,7 @@ export interface Template {
|
||||
createdAt: string;
|
||||
updatedAt?: string;
|
||||
author: string;
|
||||
fields?: FormField[];
|
||||
}
|
||||
|
||||
export interface SystemSettings {
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
const noUnderlineKeys = ['patientName', 'patientGender', 'patientAge', 'department', 'bedNumber', 'hospitalId'];
|
||||
const smartField = (key: string) => {
|
||||
const noUlClass = noUnderlineKeys.includes(key) ? ' no-underline' : '';
|
||||
return `<span class="smart-field-wrapper" contenteditable="false" style="white-space:nowrap;position:relative;"><span class="field-value${noUlClass}" data-bind="${key}" contenteditable="true" style="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;"> </span><span class="delete-btn" contenteditable="false">×</span></span>​`;
|
||||
return `<span class="smart-field-wrapper" contenteditable="false" style="white-space:nowrap;position:relative;"><span class="field-value no-underline" data-bind="${key}" contenteditable="true" style="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;"> </span><span class="delete-btn" contenteditable="false">×</span></span>​`;
|
||||
};
|
||||
|
||||
export const defaultReportContent = `
|
||||
<div style="display: flex; justify-content: center; align-items: center; gap: 12px; margin-bottom: 4px;">
|
||||
<span class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="manual" style="position:relative;display:inline-flex;align-items:center;justify-content:center;width:65px;height:65px;border:1px dashed #cbd5e1;background:#f8fafc;vertical-align:middle;cursor:pointer;">
|
||||
<span class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="manual" style="display:inline-block;text-align:center;width:65px;height:65px;line-height:65px;border:1px dashed #cbd5e1;background:#f8fafc;vertical-align:middle;margin:0 4px;cursor:pointer;position:relative;">
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入图片</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">LOGO</span>
|
||||
</span>
|
||||
<div style="text-align: center;">
|
||||
<div style="font-size: 14pt; font-family: SimSun; border-bottom: 1px solid #000; padding-bottom: 0; margin-bottom: 8px; display: inline-block; line-height: 1;">西 安 交 通 大 学 第 一 附 属 医 院</div>
|
||||
@@ -83,21 +81,21 @@ export const defaultReportContent = `
|
||||
<td style="width: 33%; text-align: center; padding: 10px; vertical-align: top; border: 1px solid #e2e8f0;">
|
||||
<div class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="frame" style="position:relative;border: 1px dashed #cbd5e1; background: #f8fafc; width: 100%; height: 100%; max-width: 200px; max-height: 200px; min-height: 60px; margin: 0px auto; display: flex; align-items: center; justify-content: center; cursor: pointer;">
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
</div>
|
||||
<p style="color: #64748b; font-size: 13px; margin: 0; padding: 0; line-height: 1.5;">图A 腹腔镜探查</p>
|
||||
</td>
|
||||
<td style="width: 33%; text-align: center; padding: 10px; vertical-align: top; border: 1px solid #e2e8f0;">
|
||||
<div class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="frame" style="position:relative;border: 1px dashed #cbd5e1; background: #f8fafc; width: 100%; height: 100%; max-width: 200px; max-height: 200px; min-height: 60px; margin: 0px auto; display: flex; align-items: center; justify-content: center; cursor: pointer;">
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
</div>
|
||||
<p style="color: #64748b; font-size: 13px; margin: 0; padding: 0; line-height: 1.5;">图B 胆囊管夹闭与离断</p>
|
||||
</td>
|
||||
<td style="width: 33%; text-align: center; padding: 10px; vertical-align: top; border: 1px solid #e2e8f0;">
|
||||
<div class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="frame" style="position:relative;border: 1px dashed #cbd5e1; background: #f8fafc; width: 100%; height: 100%; max-width: 200px; max-height: 200px; min-height: 60px; margin: 0px auto; display: flex; align-items: center; justify-content: center; cursor: pointer;">
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
</div>
|
||||
<p style="color: #64748b; font-size: 13px; margin: 0; padding: 0; line-height: 1.5;">图C 胆囊动脉夹闭与离断</p>
|
||||
</td>
|
||||
@@ -106,21 +104,21 @@ export const defaultReportContent = `
|
||||
<td style="width: 33%; text-align: center; padding: 10px; vertical-align: top; border: 1px solid #e2e8f0;">
|
||||
<div class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="frame" style="position:relative;border: 1px dashed #cbd5e1; background: #f8fafc; width: 100%; height: 100%; max-width: 200px; max-height: 200px; min-height: 60px; margin: 0px auto; display: flex; align-items: center; justify-content: center; cursor: pointer;">
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
</div>
|
||||
<p style="color: #64748b; font-size: 13px; margin: 0; padding: 0; line-height: 1.5;">图D 胆囊剥离与床面止血</p>
|
||||
</td>
|
||||
<td style="width: 33%; text-align: center; padding: 10px; vertical-align: top; border: 1px solid #e2e8f0;">
|
||||
<div class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="frame" style="position:relative;border: 1px dashed #cbd5e1; background: #f8fafc; width: 100%; height: 100%; max-width: 200px; max-height: 200px; min-height: 60px; margin: 0px auto; display: flex; align-items: center; justify-content: center; cursor: pointer;">
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
</div>
|
||||
<p style="color: #64748b; font-size: 13px; margin: 0; padding: 0; line-height: 1.5;">图E 胆囊取出与钛夹确认</p>
|
||||
</td>
|
||||
<td style="width: 33%; text-align: center; padding: 10px; vertical-align: top; border: 1px solid #e2e8f0;">
|
||||
<div class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="frame" style="position:relative;border: 1px dashed #cbd5e1; background: #f8fafc; width: 100%; height: 100%; max-width: 200px; max-height: 200px; min-height: 60px; margin: 0px auto; display: flex; align-items: center; justify-content: center; cursor: pointer;">
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span>
|
||||
</div>
|
||||
<p style="color: #64748b; font-size: 13px; margin: 0; padding: 0; line-height: 1.5;">图F 止血材料覆盖及检查</p>
|
||||
</td>
|
||||
@@ -145,7 +143,7 @@ export const defaultReportContent = `
|
||||
</p>
|
||||
|
||||
<p style="text-align: right; font-family: SimSun; font-size: 12pt; line-height: 1.5; margin: 0; padding: 0; white-space: nowrap;">
|
||||
手术者签名:<span class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="manual" style="display:inline-block;text-align:center;width:200px;height:40px;line-height:40px;border:1px dashed #cbd5e1;background:#f8fafc;vertical-align:middle;margin:0 4px;cursor:pointer;position:relative;"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span></span>
|
||||
手术者签名:<span class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="manual" style="display:inline-block;text-align:center;width:200px;height:40px;line-height:40px;border:1px dashed #cbd5e1;background:#f8fafc;vertical-align:middle;margin:0 4px;cursor:pointer;position:relative;"><span class="delete-btn" contenteditable="false">×</span><span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">插入/点击放置图片</span></span>
|
||||
</p>
|
||||
|
||||
<p style="margin: 0; padding: 0; line-height: 1.5;"> </p>
|
||||
|
||||
130
工程分析/实现方案-2026-04-18-20-03-44.md
Normal file
130
工程分析/实现方案-2026-04-18-20-03-44.md
Normal file
@@ -0,0 +1,130 @@
|
||||
# 实现方案 —— 2026-04-18-20-03-44
|
||||
|
||||
## 方案目标
|
||||
实现模板的导入/导出迁移能力,统一默认模板 Logo 的交互行为。
|
||||
|
||||
## 需求 1:模板导出功能
|
||||
|
||||
### 修改文件
|
||||
`src/pages/TemplateManage.tsx`
|
||||
|
||||
### 修改内容
|
||||
在模板列表的每个模板行操作列中增加「导出」按钮(使用 Download 图标)。点击时:
|
||||
```ts
|
||||
const handleExportTemplate = (template: Template) => {
|
||||
const exportData = {
|
||||
version: '1.0',
|
||||
type: 'surclaw_template_package',
|
||||
title: template.title,
|
||||
description: template.description,
|
||||
content: template.content,
|
||||
fields: template.fields || []
|
||||
};
|
||||
const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `模板导出-${template.title}.json`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
```
|
||||
|
||||
## 需求 2:模板导入功能
|
||||
|
||||
### 修改文件
|
||||
`src/pages/TemplateManage.tsx`
|
||||
|
||||
### 修改内容
|
||||
1. **新增状态**:
|
||||
```ts
|
||||
const [importedContent, setImportedContent] = useState<{content: string, fields: FormField[]} | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
```
|
||||
|
||||
2. **新增导入处理函数**:
|
||||
```ts
|
||||
const handleImportFile = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) return;
|
||||
const reader = new FileReader();
|
||||
reader.onload = (event) => {
|
||||
try {
|
||||
const json = JSON.parse(event.target?.result as string);
|
||||
if (json.type !== 'surclaw_template_package') {
|
||||
alert('无效的模板包文件');
|
||||
return;
|
||||
}
|
||||
setNewTemplateTitle(json.title || '');
|
||||
setNewTemplateDescription(json.description || '');
|
||||
setImportedContent({
|
||||
content: json.content || '',
|
||||
fields: Array.isArray(json.fields) ? json.fields : []
|
||||
});
|
||||
} catch {
|
||||
alert('文件解析失败,请检查 JSON 格式');
|
||||
}
|
||||
};
|
||||
reader.readAsText(file);
|
||||
};
|
||||
```
|
||||
|
||||
3. **修改创建逻辑**:在 `handleCreateTemplate` 中,如果有 `importedContent`,优先使用导入的内容和字段:
|
||||
```ts
|
||||
const newTemplate: Template = {
|
||||
id: 'tmpl_' + Date.now(),
|
||||
title: newTemplateTitle,
|
||||
description: newTemplateDescription,
|
||||
content: importedContent?.content || `<div style="font-size:12pt;line-height:1.5;"><p>请输入模板内容...</p></div>`,
|
||||
fields: importedContent?.fields || [],
|
||||
createdAt: new Date().toISOString()
|
||||
};
|
||||
```
|
||||
|
||||
4. **UI 调整**:在新增模板 Modal 中标题下方加入导入区域:
|
||||
```tsx
|
||||
<div className="flex items-center gap-3 mb-4 p-3 bg-slate-50 rounded-xl border border-dashed border-slate-200">
|
||||
<div className="text-xs text-text-muted flex-1">已有模板文件?点击右侧图标导入</div>
|
||||
<button
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="w-8 h-8 bg-accent text-white rounded-lg flex items-center justify-center hover:bg-blue-700 transition-colors shadow-sm"
|
||||
>
|
||||
<Upload size={16} />
|
||||
</button>
|
||||
<input ref={fileInputRef} type="file" accept=".json" className="hidden" onChange={handleImportFile} />
|
||||
</div>
|
||||
```
|
||||
|
||||
5. **关闭 Modal 时重置**:`setImportedContent(null)`
|
||||
|
||||
## 需求 3:Logo 替换为可交互占位符
|
||||
|
||||
### 修改文件
|
||||
`src/utils/defaultContent.ts`
|
||||
|
||||
### 修改内容
|
||||
将默认模板顶部的 Logo HTML 替换为标准 `image-placeholder`:
|
||||
```html
|
||||
<span class="image-placeholder" data-placeholder="true" contenteditable="false" data-mode="manual" style="display:inline-block;text-align:center;width:65px;height:65px;line-height:65px;border:1px dashed #cbd5e1;background:#f8fafc;vertical-align:middle;margin:0 4px;cursor:pointer;position:relative;">
|
||||
<span class="delete-btn" contenteditable="false">×</span>
|
||||
<span class="placeholder-text" style="color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">LOGO</span>
|
||||
</span>
|
||||
```
|
||||
|
||||
关键点:
|
||||
- `class="image-placeholder"`:触发编辑器中的占位符交互逻辑
|
||||
- `data-mode="manual"`:标记为静态图片占位,不支持自动帧插入
|
||||
- `position:relative` + `position:absolute` 居中:确保提示文字绝对居中
|
||||
- `delete-btn`:支持点击右上方的「×」删除
|
||||
|
||||
## 涉及文件及修改点
|
||||
| 文件 | 修改点 |
|
||||
|------|--------|
|
||||
| `src/pages/TemplateManage.tsx` | 新增 `handleExportTemplate`;新增 `importedContent` 状态和 `handleImportFile`;修改 `handleCreateTemplate` 使用导入数据;新增模板 Modal 中增加导入 UI;模板列表操作列增加导出按钮 |
|
||||
| `src/utils/defaultContent.ts` | 顶部 Logo 替换为标准 `image-placeholder` |
|
||||
|
||||
## 风险与注意事项
|
||||
1. 导入的 JSON 中 `fields` 数组需要与 `FormField` 类型结构兼容。由于 JSON 导入的是纯数据,直接赋值给 `template.fields` 即可(TypeScript 编译时类型校验通过)。
|
||||
2. 导出文件名中包含模板标题,需注意标题中的特殊字符可能影响文件名(但浏览器通常会自动处理)。
|
||||
3. Logo 占位符替换后,原有「西安交通大学第一附属医院」的样式应保持不变,仅替换 Logo 部分。
|
||||
4. 新增模板弹窗关闭时,需同步重置 `importedContent` 为 `null`,避免影响下一次创建。
|
||||
66
工程分析/实现方案-2026-04-18-22-59-10.md
Normal file
66
工程分析/实现方案-2026-04-18-22-59-10.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# 实现方案 —— 2026-04-18-22-59-10
|
||||
|
||||
## 方案目标
|
||||
将字段下划线默认行为改为「默认不显示」,修复占位符提示文字居中问题。
|
||||
|
||||
## 需求 1:所有字段默认打印时不显示下划线
|
||||
|
||||
### 修改文件 1:`src/pages/TemplateManage.tsx`
|
||||
|
||||
1. **新增字段默认状态**:
|
||||
```ts
|
||||
const [newFieldHasUnderline, setNewFieldHasUnderline] = useState(false);
|
||||
```
|
||||
|
||||
2. **编辑字段回显默认值**:在 `startEditField` 或等效函数中:
|
||||
```ts
|
||||
setEditFieldHasUnderline(field.hasUnderline ?? false);
|
||||
```
|
||||
|
||||
3. **插入字段类名判断**:在 `insertSmartField` 中:
|
||||
```ts
|
||||
const underlineClass = field.hasUnderline !== true ? ' no-underline' : '';
|
||||
```
|
||||
|
||||
### 修改文件 2:`src/utils/defaultContent.ts`
|
||||
|
||||
移除 `noUnderlineKeys` 数组,直接在 `smartField()` 中给所有字段加 `.no-underline`:
|
||||
```ts
|
||||
const smartField = (key: string) => {
|
||||
return `<span class="smart-field-wrapper" contenteditable="false" style="white-space:nowrap;position:relative;"><span class="field-value no-underline" data-bind="${key}" contenteditable="true" style="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;"> </span><span class="delete-btn" contenteditable="false">×</span></span>​`;
|
||||
};
|
||||
```
|
||||
|
||||
## 需求 2:修复占位符文字偏左
|
||||
|
||||
### 修改文件
|
||||
`src/pages/ReportEditor.tsx`、`src/pages/TemplateManage.tsx`、`src/utils/defaultContent.ts`
|
||||
|
||||
### 修改内容
|
||||
在所有 `.placeholder-text` 的 `style` 属性中追加 `text-align:center;`。
|
||||
|
||||
需要修改的位置:
|
||||
1. `defaultContent.ts`:Logo 占位符 + 6 个表格占位符 + 签名占位符
|
||||
2. `ReportEditor.tsx`:
|
||||
- `handleEditorClick` 删除恢复逻辑中的 `.placeholder-text`
|
||||
- `placeholderModal` 确认插入时的 `.placeholder-text`(table 内 + inline-block)
|
||||
3. `TemplateManage.tsx`:
|
||||
- `handleEditorClick` 删除恢复逻辑中的 `.placeholder-text`
|
||||
- `placeholderModal` 确认插入时的 `.placeholder-text`(table 内 + inline-block)
|
||||
|
||||
统一的新样式:
|
||||
```
|
||||
color:#94a3b8;font-size:11px;pointer-events:none;position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);display:block;width:100%;text-align:center;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;
|
||||
```
|
||||
|
||||
## 涉及文件及修改点
|
||||
| 文件 | 修改点 |
|
||||
|------|--------|
|
||||
| `src/pages/TemplateManage.tsx` | `newFieldHasUnderline` 默认 `false`;编辑回显默认 `false`;`insertSmartField` 判断逻辑;placeholder-text 样式 |
|
||||
| `src/utils/defaultContent.ts` | `smartField()` 直接加 `.no-underline`;所有 placeholder-text 加 `text-align:center` |
|
||||
| `src/pages/ReportEditor.tsx` | 所有 placeholder-text 加 `text-align:center` |
|
||||
|
||||
## 风险与注意事项
|
||||
1. `smartField()` 中移除 `noUnderlineKeys` 后,所有默认模板字段将统一无下划线。此前通过 `hasUnderline` 配置自定义下划线的机制仍然保留(`field.hasUnderline === true` 时不加 `.no-underline`),只是默认值变为 `false`。
|
||||
2. `text-align:center` 追加时需注意不破坏已有的其他样式属性顺序。
|
||||
3. 批量替换 `placeholder-text` 样式时,应使用精确的字符串匹配,避免误伤其他元素。
|
||||
62
工程分析/测试方案-2026-04-18-20-03-44.md
Normal file
62
工程分析/测试方案-2026-04-18-20-03-44.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# 测试方案 —— 2026-04-18-20-03-44
|
||||
|
||||
## 测试目标
|
||||
验证模板导入/导出功能和默认模板 Logo 替换的正确性。
|
||||
|
||||
## 测试用例
|
||||
|
||||
### TC-1:模板导出
|
||||
**前置条件**:模板列表中已有至少一个模板,且该模板有内容和字段配置。
|
||||
**步骤**:
|
||||
1. 在模板列表中找到目标模板。
|
||||
2. 点击操作列的「导出」按钮。
|
||||
**预期结果**:
|
||||
- 浏览器下载一个 JSON 文件,文件名为 `模板导出-{模板名称}.json`。
|
||||
- JSON 内容包含 `version`、`type`、`title`、`description`、`content`、`fields` 字段。
|
||||
- `fields` 数组与模板原有的字段配置一致。
|
||||
|
||||
### TC-2:模板导入(自动填充名称和描述)
|
||||
**前置条件**:已有一个有效的模板导出 JSON 文件。
|
||||
**步骤**:
|
||||
1. 点击「新增模板」按钮。
|
||||
2. 在弹窗中点击导入图标,选择 JSON 文件。
|
||||
**预期结果**:
|
||||
- 模板名称输入框自动填充为 JSON 中的 `title`。
|
||||
- 模板描述输入框自动填充为 JSON 中的 `description`。
|
||||
- 无控制台报错。
|
||||
|
||||
### TC-3:模板导入后创建
|
||||
**前置条件**:已完成 TC-2 的导入操作。
|
||||
**步骤**:
|
||||
1. 点击「创建」按钮。
|
||||
2. 在新创建的模板中点击「编辑模板」。
|
||||
**预期结果**:
|
||||
- 编辑器中显示的内容与导入 JSON 中的 `content` 一致。
|
||||
- 字段管理中的配置与导入 JSON 中的 `fields` 一致。
|
||||
|
||||
### TC-4:导入无效文件
|
||||
**前置条件**:准备一个非 JSON 文件或格式错误的 JSON。
|
||||
**步骤**:
|
||||
1. 在新增模板弹窗中选择无效文件。
|
||||
**预期结果**:
|
||||
- 弹出提示「文件解析失败,请检查 JSON 格式」或「无效的模板包文件」。
|
||||
- 表单保持空白,不填充任何数据。
|
||||
|
||||
### TC-5:Logo 占位符交互
|
||||
**前置条件**:新建报告,默认模板已加载。
|
||||
**步骤**:
|
||||
1. 查看顶部 Logo 区域。
|
||||
2. 点击 Logo 占位符右上方的「×」。
|
||||
3. 再次点击 Logo 区域。
|
||||
**预期结果**:
|
||||
- Logo 区域显示为虚线框,提示文字「LOGO」居中显示。
|
||||
- 点击「×」后 Logo 占位符被删除。
|
||||
- 再次点击可打开图片选择器插入图片。
|
||||
|
||||
## 回归测试
|
||||
- 确保模板列表的加载、编辑、删除功能正常。
|
||||
- 确保默认模板的其他部分(基础信息、手术步骤、图片表格等)不受影响。
|
||||
- 确保打印样式正常。
|
||||
|
||||
## 测试通过标准
|
||||
所有用例均通过,无控制台报错,导入/导出数据完整准确。
|
||||
54
工程分析/测试方案-2026-04-18-22-59-10.md
Normal file
54
工程分析/测试方案-2026-04-18-22-59-10.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# 测试方案 —— 2026-04-18-22-59-10
|
||||
|
||||
## 测试目标
|
||||
验证字段下划线默认行为和占位符文字居中修复。
|
||||
|
||||
## 测试用例
|
||||
|
||||
### TC-1:新增字段默认不下划线
|
||||
**前置条件**:进入模板管理 → 字段管理 → 新增字段。
|
||||
**步骤**:
|
||||
1. 点击「添加字段」。
|
||||
2. 观察「打印时显示下划线」复选框状态。
|
||||
**预期结果**:复选框默认未勾选。
|
||||
|
||||
### TC-2:插入字段默认带 no-underline 类
|
||||
**前置条件**:模板管理中已有字段(默认或新增)。
|
||||
**步骤**:
|
||||
1. 在编辑器中插入任意字段。
|
||||
2. 检查生成的 HTML。
|
||||
**预期结果**:`.field-value` 带有 `.no-underline` 类。
|
||||
|
||||
### TC-3:显式勾选下划线后打印正常显示
|
||||
**前置条件**:某个字段的「打印时显示下划线」已勾选。
|
||||
**步骤**:
|
||||
1. 插入该字段。
|
||||
2. 点击打印预览。
|
||||
**预期结果**:该字段显示下划线,其他未勾选字段不显示。
|
||||
|
||||
### TC-4:默认模板所有字段打印无下划线
|
||||
**前置条件**:新建报告,加载默认模板。
|
||||
**步骤**:
|
||||
1. 点击打印预览。
|
||||
2. 检查「姓名、性别、年龄、科别、床号、住院号」等字段。
|
||||
**预期结果**:所有字段均不显示下划线。
|
||||
|
||||
### TC-5:删除图片后占位符文字居中
|
||||
**前置条件**:模板中有图片占位符,已插入图片。
|
||||
**步骤**:
|
||||
1. 点击图片右上角的「×」删除。
|
||||
**预期结果**:提示文字(如「插入/点击放置图片」或「LOGO」)在虚线框正中心,不偏左。
|
||||
|
||||
### TC-6:不同尺寸占位符文字均居中
|
||||
**前置条件**:模板中有不同尺寸的占位符(65px Logo、200px 表格占位符)。
|
||||
**步骤**:
|
||||
1. 分别检查各占位符的文字位置。
|
||||
**预期结果**:所有占位符文字均绝对居中。
|
||||
|
||||
## 回归测试
|
||||
- 确保字段插入、编辑、删除功能正常。
|
||||
- 确保图片占位符的插入、删除、拖拽功能正常。
|
||||
- 确保打印样式正常。
|
||||
|
||||
## 测试通过标准
|
||||
所有用例均通过,无控制台报错,排版居中对齐准确。
|
||||
74
工程分析/经验记录.md
74
工程分析/经验记录.md
@@ -1001,3 +1001,77 @@ if ((settings.autoInsertDelay || 0) > 0) {
|
||||
- 填充时是否正确读取并应用这些限制值
|
||||
- 所有填充入口(本地上传、签名插入、系统素材、自动帧插入、拖拽填充)是否同步更新
|
||||
- 默认模板中的占位符如果没有 `max-width`/`max-height`,回退逻辑 `|| placeholder.style.width` 仍能正确获取限制值,但后续修改默认模板时应注意统一添加 `max-width`/`max-height` 以显式声明意图。
|
||||
|
||||
---
|
||||
|
||||
## 记录 33:四项编辑器体验优化集中实施
|
||||
|
||||
**A. 具体问题**
|
||||
1. 视频分析面板中「上传视频」按钮位于视频缩略图列表首位,不符合「先列出现有项,最后提供添加操作」的操作直觉。
|
||||
2. 图片占位符内的提示文字未在框中绝对居中,当占位符高度较大时文字明显偏上。
|
||||
3. 删除占位符内已插入的图片后,占位符保持收缩后的 `width:auto; height:auto` 尺寸,未恢复为原始预设大小。
|
||||
4. 点击「左对齐/居中/右对齐」按钮时,浏览器原生 `execCommand('justifyLeft')` 会用 `<div align="left">` 包裹选区,导致包含 `.field-value` 或 `.image-placeholder` 的段落被肢解,文字与输入框/图片强制换行分离。
|
||||
|
||||
**B. 产生问题原因**
|
||||
1. 上一轮重构视频面板时,将上传按钮移入了缩略图列表,但放在了首位而非末尾。
|
||||
2. 占位符提示文字使用默认的行内流布局居中,依赖于 `line-height` 和父容器的 `align-items: center`,在填充后 `line-height` 被改为 `normal`,导致文字不再居中。
|
||||
3. 删除恢复逻辑仅重置了 `border` 和 `background`,未恢复 `width`、`height`、`lineHeight` 等尺寸属性。
|
||||
4. `execCommand` 的对齐命令实现过于粗暴,会直接修改 DOM 树结构以创建对齐容器,无法安全地处理混合排版(文字 + 交互元素)。
|
||||
|
||||
**C. 解决问题方案**
|
||||
1. **视频按钮位置**:将上传按钮从 `videos.map()` 之前移至之后,保持所有样式和点击逻辑不变。
|
||||
2. **占位符文字绝对居中**:
|
||||
- 将 `.placeholder-text` 的样式统一改为 `position:absolute; top:50%; left:50%; transform:translate(-50%, -50%); display:block; width:100%;`
|
||||
- 给所有表格内的 `.image-placeholder` 父容器添加 `position:relative;`(inline-block 和签名占位符原本已有)
|
||||
- 修改范围覆盖 `defaultContent.ts`(8 个占位符)、`ReportEditor.tsx`(Modal 插入 + 删除恢复)、`TemplateManage.tsx`(Modal 插入 + 删除恢复)
|
||||
3. **删除后恢复尺寸**:在删除恢复逻辑中增加:
|
||||
```ts
|
||||
const mw = placeholder.style.maxWidth;
|
||||
const mh = placeholder.style.maxHeight;
|
||||
if (mw) placeholder.style.width = mw;
|
||||
if (mh) { placeholder.style.height = mh; placeholder.style.lineHeight = mh; }
|
||||
placeholder.style.textAlign = 'center';
|
||||
placeholder.style.verticalAlign = 'middle';
|
||||
placeholder.style.justifyContent = 'center';
|
||||
placeholder.style.alignItems = 'center';
|
||||
```
|
||||
同时根据占位符原始宽度(`maxWidth || width`)判断显示「插图」(<80px)或「插入/点击放置图片」。
|
||||
4. **安全对齐**:弃用 `execCommand('justifyLeft'/'justifyCenter'/'justifyRight')`,新增 `changeAlignment(align)` 方法:
|
||||
- 通过 `window.getSelection()` 获取选区
|
||||
- 使用 `closest('p, div, td, h1, h2, h3, li')` 找到最近的块级祖先
|
||||
- 直接设置 `(block as HTMLElement).style.textAlign = align`
|
||||
- 同步保存内容快照
|
||||
- 对齐按钮增加 `onMouseDown={(e) => e.preventDefault()}` 防止编辑器失焦
|
||||
|
||||
**D. 后续如何避免问题**
|
||||
- 当修改 `image-placeholder` 的创建或恢复逻辑时,必须在所有入口同步更新:`defaultContent.ts`(静态模板)、`ReportEditor.tsx`(运行时插入/填充/删除恢复)、`TemplateManage.tsx`(模板管理)。
|
||||
- 任何涉及 `execCommand` 的富文本操作都应评估其安全性,优先使用直接 DOM 样式操作(如 `style.textAlign`、`style.lineHeight`)替代,避免浏览器原生命令对复杂 DOM 结构的不可控修改。
|
||||
- 绝对定位的居中方案(`transform: translate(-50%, -50%)`)虽然效果稳定,但要求父容器必须带有 `position: relative`,修改时需同步检查所有父容器的样式。
|
||||
|
||||
---
|
||||
|
||||
## 记录 34:模板导入导出迁移与 Logo 占位符替换
|
||||
|
||||
**A. 具体问题**
|
||||
1. 模板管理模块缺乏数据迁移能力:用户无法将配置好的模板(含字段管理配置)导出为文件,也无法在新建模板时通过文件导入已有配置。
|
||||
2. 默认模板顶部 Logo 虽然已是 `image-placeholder`,但使用的是 `display:inline-flex` 布局,与运行时插入的占位符(`display:inline-block`)样式不一致,导致交互体验不统一。
|
||||
|
||||
**B. 产生问题原因**
|
||||
1. 系统设计初期未考虑模板迁移场景,Template 类型缺少 `fields` 属性,字段配置仅保存在全局 `formFieldsConfig` 中。
|
||||
2. Logo 占位符在默认模板中独立硬编码,未与运行时插入逻辑保持一致的标准结构。
|
||||
|
||||
**C. 解决问题方案**
|
||||
1. **Template 类型扩展**:在 `src/types.ts` 的 `Template` 接口中新增 `fields?: FormField[]`。
|
||||
2. **模板导出功能**:在 `TemplateManage.tsx` 中新增 `handleExportTemplate` 函数,导出 JSON 结构包含 `version`、`type`、`title`、`description`、`content`、`fields`。
|
||||
3. **模板导入功能**:
|
||||
- 新增 `importedContent` 状态(`{content: string; fields: FormField[]}`)和 `fileInputRef`
|
||||
- 新增 `handleImportFile` 函数:解析 JSON,验证 `type === 'surclaw_template_package'`,自动填充名称和描述,暂存内容和字段
|
||||
- 在新增模板 Modal 中增加导入 UI(使用用户指定的 `w-8 h-8 bg-accent...` 样式类名)
|
||||
- 修改 `handleModalSubmit`:新建模板时优先使用 `importedContent.content` 和 `importedContent.fields`,并同步保存到全局 `formFieldsConfig`
|
||||
- 切换模板时(`currentTemplateId` 变化),如果模板有 `fields` 则加载到编辑器并同步保存到全局配置
|
||||
4. **Logo 占位符标准化**:将 `defaultContent.ts` 中 Logo 的 `display:inline-flex` 改为 `display:inline-block`,统一使用 `text-align:center` + `line-height:65px` 的垂直居中方式,提示文字改为「LOGO」。
|
||||
|
||||
**D. 后续如何避免问题**
|
||||
- 当扩展数据类型(如 Template 接口)时,应评估是否需要同步修改所有使用该类型的持久化/序列化逻辑(如 storage 读写、导入/导出)。
|
||||
- 默认模板中的占位符结构必须与运行时插入逻辑保持完全一致(`display`、居中方式、`data-mode` 等),任何差异都可能导致交互体验不一致。
|
||||
- 新增文件上传/导入功能时,必须在 onChange 事件末尾清空 `e.target.value = ''`,否则同一文件无法重复选择。
|
||||
|
||||
52
工程分析/需求分析-2026-04-18-20-03-44.md
Normal file
52
工程分析/需求分析-2026-04-18-20-03-44.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# 需求分析 —— 2026-04-18-20-03-44
|
||||
|
||||
## 需求来源
|
||||
用户希望增强模板管理模块的数据迁移能力和默认模板的交互一致性。
|
||||
|
||||
## 需求概述
|
||||
|
||||
### 需求 1:模板导出功能
|
||||
在 `TemplateManage` 的模板列表中,新增「导出」按钮。导出内容需包含:
|
||||
- 模板名称(`title`)
|
||||
- 模板描述(`description`)
|
||||
- 模板内容(`content`)
|
||||
- 字段管理配置(`fields`)
|
||||
|
||||
导出格式为 JSON,结构如下:
|
||||
```json
|
||||
{
|
||||
"version": "1.0",
|
||||
"type": "surclaw_template_package",
|
||||
"title": "...",
|
||||
"description": "...",
|
||||
"content": "...",
|
||||
"fields": []
|
||||
}
|
||||
```
|
||||
|
||||
### 需求 2:模板导入功能
|
||||
在「新增模板」弹窗中,新增「导入本地模板」选项。用户选择 JSON 文件后:
|
||||
- 自动解析并填充模板名称和描述到表单
|
||||
- 暂存模板内容和字段配置
|
||||
- 点击「创建」时,将暂存的内容和字段一并写入新模板
|
||||
|
||||
导入 UI 使用指定的样式类名:`w-8 h-8 bg-accent text-white rounded-lg flex items-center justify-center hover:bg-blue-700 transition-colors shadow-sm`
|
||||
|
||||
### 需求 3:Logo 替换为可交互占位符
|
||||
默认模板 `defaultContent.ts` 中顶部医院 Logo 当前为硬编码的 `<span>` 结构(非标准 `image-placeholder`),导致:
|
||||
- 无法点击右上方的「×」删除
|
||||
- 无法触发图片上传/选择逻辑
|
||||
- 与编辑器中其他图片占位符的交互不一致
|
||||
|
||||
需将其替换为标准的 65×65 `image-placeholder`(`data-mode="manual"`),使其支持删除、点击插入等完整交互。
|
||||
|
||||
## 涉及文件
|
||||
- `src/pages/TemplateManage.tsx`(需求 1、2)
|
||||
- `src/utils/defaultContent.ts`(需求 3)
|
||||
- `src/types.ts`(确认 Template 类型结构)
|
||||
|
||||
## 需求影响范围
|
||||
- 模板列表操作列新增导出按钮
|
||||
- 新增模板弹窗新增导入 UI 和逻辑
|
||||
- 默认模板头部 Logo 的 HTML 结构
|
||||
- 模板创建流程需支持字段配置写入
|
||||
32
工程分析/需求分析-2026-04-18-22-59-10.md
Normal file
32
工程分析/需求分析-2026-04-18-22-59-10.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# 需求分析 —— 2026-04-18-22-59-10
|
||||
|
||||
## 需求来源
|
||||
用户希望调整字段默认下划线行为,并修复占位符文字居中的样式问题。
|
||||
|
||||
## 需求概述
|
||||
|
||||
### 需求 1:所有字段默认打印时不显示下划线
|
||||
当前字段管理中,新增字段的「打印时显示下划线」复选框默认勾选(`hasUnderline` 默认为 `true`)。用户希望改为默认不勾选,即所有现有字段和新增字段在打印时默认不显示下划线。
|
||||
|
||||
具体改动点:
|
||||
- `newFieldHasUnderline` 状态默认值从 `true` 改为 `false`
|
||||
- 编辑字段回显时,`hasUnderline` 回退值从 `true` 改为 `false`
|
||||
- `insertSmartField` 中类名判断逻辑改为:只要 `hasUnderline !== true` 就加 `.no-underline`
|
||||
- `defaultContent.ts` 中 `smartField()` 直接给所有字段加 `.no-underline`
|
||||
|
||||
### 需求 2:修复删除图片后占位符文字偏左
|
||||
删除图片后,占位符恢复为默认状态,但提示文字(如「插入/点击放置图片」)在虚线框内偏左,未真正居中。
|
||||
|
||||
原因分析:虽然使用了 `position:absolute + transform:translate(-50%, -50%)`,但 `placeholder-text` 是 `display:block; width:100%` 的块级元素,其内部文本流默认 `text-align:left`,导致文字靠左。
|
||||
|
||||
修复方案:在所有 `.placeholder-text` 的 style 中追加 `text-align:center;`。
|
||||
|
||||
## 涉及文件
|
||||
- `src/pages/TemplateManage.tsx`(需求 1、2)
|
||||
- `src/utils/defaultContent.ts`(需求 1、2)
|
||||
- `src/pages/ReportEditor.tsx`(需求 2)
|
||||
|
||||
## 需求影响范围
|
||||
- 字段管理的默认值和插入逻辑
|
||||
- 默认模板中所有 smartField 的下划线行为
|
||||
- 所有图片占位符的提示文字对齐方式
|
||||
Reference in New Issue
Block a user