2026-04-16-20-24-11 - 从 Ref 读取修复 saveDraftToStorage 闭包陷阱和 DOM 失效导致的内容丢失
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user