diff --git a/src/pages/ReportEditor.tsx b/src/pages/ReportEditor.tsx index 90a452b..a31d823 100644 --- a/src/pages/ReportEditor.tsx +++ b/src/pages/ReportEditor.tsx @@ -356,11 +356,24 @@ export default function ReportEditor() { const reader = new FileReader(); reader.onload = (event) => { const src = event.target?.result as string; + const mw = placeholder.style.maxWidth || placeholder.style.width || '200px'; + const mh = placeholder.style.maxHeight || placeholder.style.height || '200px'; placeholder.innerHTML = ` × - + `; placeholder.classList.add('has-image'); + placeholder.style.border = 'none'; + placeholder.style.background = 'transparent'; + placeholder.style.width = 'auto'; + placeholder.style.height = 'auto'; + placeholder.style.lineHeight = 'normal'; + placeholder.style.maxWidth = mw; + placeholder.style.maxHeight = mh; + placeholder.style.textAlign = 'left'; + placeholder.style.verticalAlign = 'top'; + placeholder.style.justifyContent = 'flex-start'; + placeholder.style.alignItems = 'flex-start'; if (editorRef.current) contentRef.current = editorRef.current.innerHTML; saveDraftToStorage(); }; @@ -409,12 +422,25 @@ export default function ReportEditor() { e.preventDefault(); if (placeholder.classList.contains('has-image')) { placeholder.classList.remove('has-image'); + const w = parseInt(placeholder.style.maxWidth || placeholder.style.width || '0'); + const text = w > 0 && w < 80 ? '插图' : '插入/点击放置图片'; placeholder.innerHTML = ` × - 插入/点击放置图片 + ${text} `; placeholder.style.border = '1px dashed #cbd5e1'; placeholder.style.background = '#f8fafc'; + 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'; if (editorRef.current) contentRef.current = editorRef.current.innerHTML; saveDraftToStorage(); } else { @@ -532,6 +558,19 @@ export default function ReportEditor() { } }; + const changeAlignment = (align: 'left' | 'center' | 'right' | 'justify') => { + 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, li'); + if (block) { + (block as HTMLElement).style.textAlign = align; + if (editorRef.current) contentRef.current = editorRef.current.innerHTML; + saveDraftToStorage(); + } + }; + const insertTable = () => { editorRef.current?.focus(); setTableModal({ isOpen: true, rows: '2', cols: '3' }); @@ -1413,9 +1452,9 @@ export default function ReportEditor() {
- - - + + +