From 1305d1656d56fb7b81096dd6cb8beb3f1ce52666 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Mon, 6 Jan 2020 17:19:32 +0800 Subject: [PATCH] =?UTF-8?q?wizard=20=E6=B7=BB=E5=8A=A0=E8=81=94=E5=8A=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=97=E8=80=85=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Wizard.tsx | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/renderers/Wizard.tsx b/src/renderers/Wizard.tsx index b221b61f..3d837ed9 100644 --- a/src/renderers/Wizard.tsx +++ b/src/renderers/Wizard.tsx @@ -246,6 +246,76 @@ export default class Wizard extends React.Component { throw new Error('Please implements this!'); } + reload(query?: any, silent?: boolean) { + if (query) { + return this.receive(query); + } + + const { + initApi, + initAsyncApi, + initFinishedField, + store, + messages: {fetchSuccess, fetchFailed} + } = this.props; + + if (isEffectiveApi(initApi, store.data) && this.state.currentStep === 1) { + store + .fetchInitData(initApi, store.data, { + successMessage: fetchSuccess, + errorMessage: fetchFailed, + onSuccess: () => { + if ( + !isEffectiveApi(initAsyncApi, store.data) || + store.data[initFinishedField || 'finished'] + ) { + return; + } + + return until( + () => store.checkRemote(initAsyncApi, store.data), + (ret: any) => ret && ret[initFinishedField || 'finished'], + cancel => (this.asyncCancel = cancel) + ); + } + }) + .then(value => { + const state = { + currentStep: 1 + }; + + if ( + value && + value.data && + (typeof value.data.step === 'number' || + (typeof value.data.step === 'string' && + /^\d+$/.test(value.data.step))) + ) { + state.currentStep = parseInt(value.data.step, 10); + } + + this.setState(state, () => { + // 如果 initApi 返回的状态是正在提交,则进入轮顺状态。 + if ( + value && + value.data && + (value.data.submiting || value.data.submited) + ) { + this.checkSubmit(); + } + }); + return value; + }); + } + } + + receive(values: object) { + const {store} = this.props; + + store.updateData(values); + this.reload(); + } + domRef(ref: any) { this.dom = ref; }