From 61c1ef1f74d50f2db28d78b6b8b8e156c7097448 Mon Sep 17 00:00:00 2001 From: laoluo Date: Wed, 28 Sep 2022 19:46:52 +0800 Subject: [PATCH] feat(lb-components): Add action like updateValid and beforeRotate --- packages/lb-components/src/App.tsx | 5 +++ .../src/components/customResizeHook/index.tsx | 5 +++ packages/lb-components/src/store/Actions.ts | 7 ++-- .../src/store/annotation/actionCreators.ts | 27 ++++++++++++++- .../src/store/annotation/reducer.ts | 34 ++++++++++++++++++- .../src/store/annotation/types.ts | 1 + 6 files changed, 74 insertions(+), 5 deletions(-) diff --git a/packages/lb-components/src/App.tsx b/packages/lb-components/src/App.tsx index c6fbff293..fc63a7ac5 100644 --- a/packages/lb-components/src/App.tsx +++ b/packages/lb-components/src/App.tsx @@ -63,6 +63,7 @@ export interface AppProps { // data Correction skipBeforePageTurning?: (pageTurning: Function) => void; + beforeRotate?: () => boolean; drawLayerSlot?: (props: { zoom: number; @@ -97,6 +98,7 @@ const App: React.FC = (props) => { loadFileList, defaultLang = 'cn', skipBeforePageTurning, + beforeRotate, } = props; useEffect(() => { @@ -112,6 +114,7 @@ const App: React.FC = (props) => { onPageChange, onStepChange, skipBeforePageTurning, + beforeRotate, }), ); @@ -131,6 +134,7 @@ const App: React.FC = (props) => { onSave, onPageChange, onStepChange, + beforeRotate, }), ); @@ -145,6 +149,7 @@ const App: React.FC = (props) => { onPageChange, onStepChange, defaultLang, + beforeRotate, ]); useEffect(() => { diff --git a/packages/lb-components/src/components/customResizeHook/index.tsx b/packages/lb-components/src/components/customResizeHook/index.tsx index e0447ebc6..d9eca6416 100644 --- a/packages/lb-components/src/components/customResizeHook/index.tsx +++ b/packages/lb-components/src/components/customResizeHook/index.tsx @@ -15,6 +15,7 @@ import { PageForward, UpdateToolInstance, CopyBackWordResult, + UpdateValid, } from '@/store/annotation/actionCreators'; import { ISize } from '@/types/main'; import { message } from 'antd'; @@ -68,6 +69,10 @@ export const ViewportProviderComponent = (props: any) => { if (e.keyCode === EKeyCode.C && e.altKey === true) { dispatch(CopyBackWordResult()); } + + if (e.keyCode === EKeyCode.Y) { + dispatch(UpdateValid()); + } } /** diff --git a/packages/lb-components/src/store/Actions.ts b/packages/lb-components/src/store/Actions.ts index 37e584590..571d73e52 100644 --- a/packages/lb-components/src/store/Actions.ts +++ b/packages/lb-components/src/store/Actions.ts @@ -25,12 +25,13 @@ export const ANNOTATION_ACTIONS = { CALC_STEP_PROGRESS: '@@CALC_STEP_PROGRESS', SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED: '@@SET_TRIGGER_EVENT_AFTER_INDEX_CHANGED', SKIP_BEFORE_PAGE_TURNING: '@@SKIP_BEFORE_PAGE_TURNING', + UPDATE_BEFORE_ROTATE: '@@UPDATE_BEFORE_ROTATE', SET_LOADING: '@@SET_LOADING', SET_POINT_CLOUD_LOADING: '@@SET_POINT_CLOUD_LOADING', - - - SET_TASK_STEP_LIST: '@@SET_TASK_STEP_LIST' + SET_TASK_STEP_LIST: '@@SET_TASK_STEP_LIST', + + UPDATE_ANNOTATION_VALID: '@@UPDATE_ANNOTATION_VALID', }; export const IMAGE_ATTRIBUTE_ACTIONS = { diff --git a/packages/lb-components/src/store/annotation/actionCreators.ts b/packages/lb-components/src/store/annotation/actionCreators.ts index b1edea1fd..25cae6004 100644 --- a/packages/lb-components/src/store/annotation/actionCreators.ts +++ b/packages/lb-components/src/store/annotation/actionCreators.ts @@ -167,6 +167,12 @@ export function UpdateRotate(): AnnotationActionTypes { }; } +export function UpdateValid(): AnnotationActionTypes { + return { + type: ANNOTATION_ACTIONS.UPDATE_ANNOTATION_VALID, + }; +} + export function UpdateSkipBeforePageTurning(skipBeforePageTurning: (pageTurning: Function) => {}): AnnotationActionTypes { return { type: ANNOTATION_ACTIONS.SKIP_BEFORE_PAGE_TURNING, @@ -176,6 +182,15 @@ export function UpdateSkipBeforePageTurning(skipBeforePageTurning: (pageTurning: }; } +export function UpdateBeforeRotate(beforeRotate: () => {}): AnnotationActionTypes { + return { + type: ANNOTATION_ACTIONS.UPDATE_BEFORE_ROTATE, + payload: { + beforeRotate, + }, + }; +} + export function CopyBackWordResult(): AnnotationActionTypes { return { type: ANNOTATION_ACTIONS.COPY_BACKWARD_RESULT, @@ -196,7 +211,8 @@ export function InitTaskData({ loadFileList, step, stepList, - skipBeforePageTurning + skipBeforePageTurning, + beforeRotate }: any): any { const tasks: any[] = []; @@ -230,6 +246,10 @@ export function InitTaskData({ tasks.push(UpdateSkipBeforePageTurning(skipBeforePageTurning)); } + if (beforeRotate) { + tasks.push(UpdateBeforeRotate(beforeRotate)); + } + tasks.push(SetTaskConfig({ stepList, step })); tasks.push({ @@ -256,6 +276,7 @@ export function UpdateInjectFunc({ pageSize, loadFileList, stepList, + beforeRotate }: any): any { const tasks: any[] = []; @@ -285,6 +306,10 @@ export function UpdateInjectFunc({ tasks.push(UpdatePageSize(pageSize)); } + if (beforeRotate) { + tasks.push(UpdateBeforeRotate(beforeRotate)); + } + tasks.push(SetTaskStepList({ stepList })); return (dispatch: any) => dispatchTasks(dispatch, tasks); diff --git a/packages/lb-components/src/store/annotation/reducer.ts b/packages/lb-components/src/store/annotation/reducer.ts index 9229da60e..023e24ee0 100644 --- a/packages/lb-components/src/store/annotation/reducer.ts +++ b/packages/lb-components/src/store/annotation/reducer.ts @@ -9,6 +9,7 @@ import StepUtils from '@/utils/StepUtils'; import ToolUtils from '@/utils/ToolUtils'; import { AnnotationEngine, CommonToolUtils, ImgUtils } from '@labelbee/lb-annotation'; import { i18n } from '@labelbee/lb-utils'; +import { Modal } from 'antd'; import { message } from 'antd/es'; import _ from 'lodash'; import { SetAnnotationLoading } from './actionCreators'; @@ -545,6 +546,13 @@ export const annotationReducer = ( }; } + case ANNOTATION_ACTIONS.UPDATE_BEFORE_ROTATE: { + return { + ...state, + beforeRotate: action.payload.beforeRotate, + }; + } + case ANNOTATION_ACTIONS.SKIP_BEFORE_PAGE_TURNING: { return { ...state, @@ -565,8 +573,32 @@ export const annotationReducer = ( } case ANNOTATION_ACTIONS.UPDATE_ROTATE: { - const { toolInstance } = state; + const { toolInstance, beforeRotate } = state; + + // DataCheck before rotate. + if (beforeRotate) { + if (beforeRotate() === false) { + return state; + } + } + toolInstance?.updateRotate(); + return state; + } + + case ANNOTATION_ACTIONS.UPDATE_ANNOTATION_VALID: { + const { toolInstance } = state; + const valid = toolInstance?.valid ?? true; + + Modal.destroyAll(); + Modal.confirm({ + content: `是否确认${valid ? '标为无效' : '取消无效'}文件`, + onOk: () => { + toolInstance?.setValid(!valid); + }, + okText: '确认', + cancelText: '取消', + }); return state; } diff --git a/packages/lb-components/src/store/annotation/types.ts b/packages/lb-components/src/store/annotation/types.ts index 005e00ee3..153f2db88 100644 --- a/packages/lb-components/src/store/annotation/types.ts +++ b/packages/lb-components/src/store/annotation/types.ts @@ -60,6 +60,7 @@ export interface AnnotationState { triggerEventAfterIndexChanged: boolean; skipBeforePageTurning?: (pageTurning: Function) => void; + beforeRotate?: () => boolean; pointCloudLoading: boolean; }