2026-04-16-20-24-11 - 从 Ref 读取修复 saveDraftToStorage 闭包陷阱和 DOM 失效导致的内容丢失

This commit is contained in:
2026-04-16 20:29:06 +08:00
parent 39ecdf2b71
commit 85080e5630
5 changed files with 259 additions and 7 deletions

View File

@@ -85,17 +85,18 @@ export default function ReportEditor() {
const user = storage.get<User | null>('currentUser', null);
const key = user ? `reportEditorDraft_${user.username}` : '';
if (key) {
const currentContent = contentRef.current || editorRef.current?.innerHTML || '';
storage.set(key, {
content: editorRef.current?.innerHTML || '',
content: currentContent,
draftReportId: reportId || null,
reportData,
videos,
capturedFrames,
activeTab,
loadedTemplateId
reportData: stateRef.current.reportData,
videos: stateRef.current.videos,
capturedFrames: stateRef.current.capturedFrames,
activeTab: stateRef.current.activeTab,
loadedTemplateId: stateRef.current.loadedTemplateId
});
}
}, [reportData, videos, capturedFrames, activeTab, loadedTemplateId, reportId]);
}, [reportId]);
useEffect(() => {
const user = storage.get<User | null>('currentUser', null);
@@ -300,6 +301,7 @@ export default function ReportEditor() {
sel?.removeAllRanges();
sel?.addRange(range);
document.execCommand('delete');
if (editorRef.current) contentRef.current = editorRef.current.innerHTML;
saveDraftToStorage();
}
return;