Skip to content

Commit

Permalink
fix: 标签工具结果初始化添加
Browse files Browse the repository at this point in the history
  • Loading branch information
laoluo committed Sep 26, 2021
1 parent b2cf41a commit 4449b2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 11 additions & 3 deletions packages/lb-annotation/src/core/toolOperation/tagOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TagOperation extends BasicToolOperation {
}

public setResult(tagResult: any[], isInitData = false) {
if (isInitData === true) {
if (isInitData === true && tagResult.length === 0) {
// 注意,该获取方式是需要拉取所有的 basicResultList
tagResult = TagUtils.getDefaultTagResult(this.config.inputList, []);
}
Expand All @@ -37,11 +37,14 @@ class TagOperation extends BasicToolOperation {
this.render();
}

/**
* 当前页面的标注结果
*/
public get currentTagResult() {
return this.tagResult.filter((v) => {
const basicSourceID = `${v.sourceID}`;
return basicSourceID === this.sourceID;
})[0];
})[0] || {};
}

public onKeyDown(e: KeyboardEvent) {
Expand Down Expand Up @@ -96,6 +99,11 @@ class TagOperation extends BasicToolOperation {
return;
}

if (!this.basicResult && this.dependToolName) {
// 有依赖情况下无依赖结果则不允许进行标注
return;
}

const labelInfoSet = this.config.inputList;

if (!labelInfoSet[i]) {
Expand Down Expand Up @@ -218,7 +226,7 @@ class TagOperation extends BasicToolOperation {
}

const dom = document.createElement('div');
const tagInfoList = TagUtils.getTagNameList(this.currentTagResult.result, this.config.inputList);
const tagInfoList = TagUtils.getTagNameList(this.currentTagResult.result || {}, this.config.inputList);

dom.innerHTML =
tagInfoList.reduce((acc: string, cur: { keyName: string; value: string[] }) => {
Expand Down
11 changes: 7 additions & 4 deletions packages/lb-components/src/store/annotation/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const calcStepProgress = (fileList: any[], step: number) =>
return pre;
}, 0) / fileList.length;


const updateToolInstance = (annotation: AnnotationState, imgNode: HTMLImageElement) => {
const { step, stepList } = annotation;
const stepConfig = StepUtils.getCurrentStepInfo(step, stepList);
Expand Down Expand Up @@ -206,6 +205,10 @@ export const annotationReducer = (
const dependStepConfig = getStepConfig(stepList, dataSourceStep);
let stepBasicResultList = [];

// 当前步骤结果
const stepResult = fileResult[`step_${step}`];
const isInitData = !stepResult; // 是否为初始化数据

if (dataSourceStep && tool) {
stepBasicResultList = fileResult[`step_${dataSourceStep}`]?.result;

Expand All @@ -219,8 +222,7 @@ export const annotationReducer = (
}
}

toolInstance.setResult(result);

toolInstance.setResult(result, isInitData);
toolInstance.history.initRecord(result, true);

return {
Expand Down Expand Up @@ -366,9 +368,10 @@ export const annotationReducer = (
// 更新当前的结果
const fileResult = jsonParser(newResult);
const stepResult = fileResult[`step_${step}`];
const isInitData = !stepResult;
const result = stepResult?.result || [];

toolInstance.setResult(result);
toolInstance.setResult(result, isInitData);
toolInstance.history.pushHistory(result);

return {
Expand Down

0 comments on commit 4449b2b

Please sign in to comment.