diff --git a/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx b/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx index 5f3192c..9fdc324 100644 --- a/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx +++ b/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx @@ -9,7 +9,7 @@ import { listEditorTasksUsingGet, upsertEditorAnnotationUsingPut, checkFileVersionUsingGet, - useNewVersionUsingPost, + applyNewVersionUsingPost, type FileVersionCheckResponse, } from "../annotation.api"; import { AnnotationResultStatus } from "../annotation.model"; @@ -232,6 +232,7 @@ export default function LabelStudioTextEditor() { const origin = useMemo(() => window.location.origin, []); const iframeRef = useRef(null); const initSeqRef = useRef(0); + const fileVersionCheckSeqRef = useRef(0); const expectedTaskIdRef = useRef(null); const prefetchSeqRef = useRef(0); const exportCheckRef = useRef<{ @@ -274,7 +275,7 @@ export default function LabelStudioTextEditor() { // 文件版本相关状态 const [fileVersionInfo, setFileVersionInfo] = useState(null); - const [checkingFileVersion, setCheckingFileVersion] = useState(false); + const [, setCheckingFileVersion] = useState(false); const [usingNewVersion, setUsingNewVersion] = useState(false); const focusIframe = useCallback(() => { @@ -558,9 +559,11 @@ export default function LabelStudioTextEditor() { const checkFileVersion = useCallback(async (fileId: string) => { if (!projectId || !fileId) return; + const seq = ++fileVersionCheckSeqRef.current; setCheckingFileVersion(true); try { const resp = (await checkFileVersionUsingGet(projectId, fileId)) as ApiResponse; + if (seq !== fileVersionCheckSeqRef.current) return; const data = resp?.data; if (data) { setFileVersionInfo(data); @@ -584,9 +587,9 @@ export default function LabelStudioTextEditor() { } catch (e) { console.error("检查文件版本失败", e); } finally { - setCheckingFileVersion(false); + if (seq === fileVersionCheckSeqRef.current) setCheckingFileVersion(false); } - }, [modal, message, projectId]); + }, [modal, projectId]); const handleUseNewVersion = useCallback(async () => { if (!selectedFileId) return; @@ -612,7 +615,7 @@ export default function LabelStudioTextEditor() { if (!projectId || !selectedFileId) return; setUsingNewVersion(true); try { - await useNewVersionUsingPost(projectId, selectedFileId); + await applyNewVersionUsingPost(projectId, selectedFileId); message.success("已使用新版本并清空标注"); setFileVersionInfo(null); await loadTasks({ mode: "reset" }); @@ -985,7 +988,7 @@ export default function LabelStudioTextEditor() { {fileVersionInfo?.hasNewVersion && (
- ⚠ 文件有新版本({fileVersionInfo.currentFileVersion} > {fileVersionInfo.annotationFileVersion}) + ⚠ 文件有新版本({fileVersionInfo.currentFileVersion}{" > "}{fileVersionInfo.annotationFileVersion})
)} + {fileVersionInfo?.annotationVersionUnknown && !fileVersionInfo?.hasNewVersion && ( + + 历史标注缺少文件版本信息,保存后将绑定当前版本({fileVersionInfo.currentFileVersion}) + + )}