updateEventStatus(paramsList) {
const createPromise = params => () => {
return new Promise((resolve, reject) => {
XXXXXApi.XXXXXDeviceEvent.updateXXXDeviceEventById(params).then(res => {
for (let i = 0; i < this.processParams.selectedList.length; i++) {
if (params.eventid === this.processParams.selectedList[i].eventid) {
this.processParams.selectedList[i].status = { text: '成功', color: '#67c23a' }
}
}
resolve(res)
}).catch(error => {
for (let i = 0; i < this.processParams.selectedList.length; i++) {
if (params.eventid === this.processParams.selectedList[i].eventid) {
this.processParams.selectedList[i].status = { text: '失败', color: '#f56c6c' }
}
}
reject(error)
})
})
}
let tasks = []
paramsList.forEach(item => {
tasks.push(createPromise(item.params))
})
let doTask = tasks.reduce((prev, next) => prev.then(res => next()), Promise.resolve())
doTask.then(res => {
this.$emit('confirm')
}).catch(error => {
console.log(error)
})
},
Promise结合reduce构建顺序执行队列
网友评论