wizard 添加联动接受者逻辑

This commit is contained in:
2betop 2020-01-06 17:19:32 +08:00
parent de8e90762f
commit 1305d1656d
1 changed files with 70 additions and 0 deletions

View File

@ -246,6 +246,76 @@ export default class Wizard extends React.Component<WizardProps, WizardState> {
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;
}