在 annotation-view.tsx 中,编辑器初始化时:
as.createAnnotation())保存标注时:
// 在 loadData 函数中添加
const existingAnnotations = await getTaskAnnotations(id);
console.log('Existing annotations:', existingAnnotations);
// Store existing annotations for later use
if (existingAnnotations.length > 0) {
// Use the most recent annotation
const latestAnnotation = existingAnnotations[0];
annotationResultRef.current = latestAnnotation.result;
console.log('Loaded existing annotation:', latestAnnotation);
}
onStorageInitialized: (LS: any) => {
const initAnnotation = () => {
const as = LS.annotationStore;
// Check if we have existing annotation data
const existingResult = annotationResultRef.current;
if (existingResult && existingResult.result && Array.isArray(existingResult.result)) {
console.log('Loading existing annotation:', existingResult);
// Create annotation with existing data
const annotation = as.createAnnotation({
userGenerate: false,
result: existingResult.result,
});
as.selectAnnotation(annotation.id);
// Set up snapshot listener
// ...
} else {
console.log('Creating new annotation');
// Create new empty annotation
const annotation = as.createAnnotation();
as.selectAnnotation(annotation.id);
// ...
}
};
setTimeout(initAnnotation, 100);
}
// Check if annotation already exists for this task
const existingAnnotations = await getTaskAnnotations(id);
if (existingAnnotations.length > 0) {
// Update existing annotation
const existingAnnotation = existingAnnotations[0];
await updateAnnotation(existingAnnotation.id, {
result: resultData,
});
console.log('Updated existing annotation:', existingAnnotation.id);
} else {
// Create new annotation
await createAnnotation({
task_id: id,
user_id: 'current_user',
result: resultData,
});
console.log('Created new annotation');
}
// Update task status to completed
await updateTask(id, {
status: 'completed',
});
console.log('Task marked as completed');
import {
getTask,
getProject,
createAnnotation,
updateTask,
getTaskAnnotations, // 新增
updateAnnotation // 新增
} from '../../services/api';
创建新任务并标注
重新打开已标注的任务
检查数据库
annotations 表updated_at 字段在修改后正确更新web/apps/lq_label/src/views/annotation-view/annotation-view.tsx - 标注视图组件web/apps/lq_label/src/services/api.ts - API 服务层backend/routers/annotation.py - 标注 API 路由backend/routers/task.py - 任务 API 路由LabelStudio 数据格式
createAnnotation() 的 userGenerate: false 参数表示使用预加载的数据result 字段必须是数组格式并发问题
性能优化
添加用户认证
'current_user'支持多人标注
添加自动保存
添加版本历史