Skip to content

Commit

Permalink
fix: Click next step jump to the first page
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyong1_vendor committed Jun 7, 2022
1 parent 559fe40 commit 83a0335
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions packages/lb-components/src/views/MainView/toolHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ESubmitType, prefix } from '@/constant';
import { EToolName } from '@/data/enums/ToolType';
import useSize from '@/hooks/useSize';
import { AppState } from '@/store';
import { ToNextStep, ToSubmitFileData } from '@/store/annotation/actionCreators';
import { loadImgList, ToNextStep, ToSubmitFileData } from '@/store/annotation/actionCreators';
import { IFileItem } from '@/types/data';
import { Header } from '@/types/main';
import { IStepInfo } from '@/types/step';
Expand All @@ -24,27 +24,44 @@ interface INextStep {
stepProgress: number;
stepList: IStepInfo[];
step: number; // 当前步骤
imgList: IFileItem[];
}

const NextButton: React.FC<{ disabled: boolean }> = ({ disabled }) => {
const NextButton: React.FC<{ disabled: boolean; imgList: IFileItem[] }> = ({
disabled,
imgList,
}) => {
const { t } = useTranslation();

const toNext = () => {
const { dispatch, getState } = store;
// 点击下一步跳转到第一页 第一页没有图片的话则需要先加载图片
if (imgList[0]) {
dispatch(ToNextStep(0) as any);
} else {
loadImgList(dispatch, getState, 0).then((isSuccess) => {
if (isSuccess) {
dispatch(ToNextStep(0) as any);
}
});
}
};

return (
<Button
type='primary'
style={{
marginLeft: 10,
}}
onClick={() => {
store.dispatch(ToNextStep() as any);
}}
onClick={toNext}
disabled={disabled}
>
{t('NextStep')}
</Button>
);
};

const NextStep: React.FC<INextStep> = ({ step, stepProgress, stepList }) => {
const NextStep: React.FC<INextStep> = ({ step, stepProgress, stepList, imgList }) => {
const { t } = useTranslation();
// 最后一步不显示下一步按钮
const lastStep = last(stepList)?.step;
Expand All @@ -59,13 +76,13 @@ const NextStep: React.FC<INextStep> = ({ step, stepProgress, stepList }) => {
return (
<Tooltip title={t('StepNotFinishedNotify')}>
<span>
<NextButton disabled={disabled} />
<NextButton disabled={disabled} imgList={imgList} />
</span>
</Tooltip>
);
}

return <NextButton disabled={disabled} />;
return <NextButton disabled={disabled} imgList={imgList} />;
};

interface IToolHeaderProps {
Expand Down Expand Up @@ -132,7 +149,7 @@ const ToolHeader: React.FC<IToolHeaderProps> = ({
const stepListNode = stepList.length > 1 && (
<>
<StepSwitch stepProgress={stepProgress} />
<NextStep step={step} stepProgress={stepProgress} stepList={stepList} />
<NextStep step={step} stepProgress={stepProgress} stepList={stepList} imgList={imgList} />
</>
);

Expand Down

0 comments on commit 83a0335

Please sign in to comment.