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; }