- 在开发过程中有种特殊需求,提交给后端的数据,后端异步处理,然而接口返回的却不是前端期望的状态,那么即可实现递归请求,有点轮询的意思
submitTo(data) {
return axios
.post(`xxxxxxx`, {})
.then(function(res) {
return res.data
})
},
getProcessInfo(id) {
return axios
.get(`xxxx`, {
params: {
id: id,
},
})
.then(function(res) {
return res.data
})
},
afterDispatch(data) {
const that = this
return new Promise((resolve, reject) => {
const fun = () => {
return this.submitTo(data).then((res) => {
if (res.status !== 3) {
fun()
} else {
resolve(res)
}
})
}
fun()
}).then((res) => {
if (!JSON.parse(res.remark).activeSteps.length) {
Modal.success({
title: '提交成功!',
content: (
<div>
<p>流程结束</p>
</div>
),
onOk() {
},
})
} else {
const stepId = JSON.parse(res.remark).id
this.getProcessInfo(id).then((res) => {
Modal.success({
title: '提交成功!',
content: (
<div>
<p>下一环节:{res.xxx} </p>
<p>处理人:{res.xxx} </p>
</div>
),
onOk() {
},
})
})
}
})
}