Commit 9a0c7c9c by 黑潮

update: 修复重复请求

parent ffc67a7c
......@@ -89,6 +89,8 @@ function handlerErr(code, message = '请求错误', alertError = true) {
}
}
const pendingRequest = new Map();
/**
* 请求地址,请求数据,是否静默,请求方法
*/
......@@ -111,6 +113,16 @@ const requests = (url, data = {}, contentTypeIsJSON = false, isSilence = false,
} else {
_opts.params = _query;
}
let key = JSON.stringify(_opts);
if (!pendingRequest.has(key)) {
pendingRequest.set(key, Date.now());
} else if (Date.now() - pendingRequest.get(key) > 1000) {
pendingRequest.delete(key);
} else {
return Promise.reject();
}
return new Promise((resolve, reject) => {
let _random = { stamp: Date.now(), url: `${_apiHost + url}` };
if (!isSilence) {
......@@ -138,6 +150,7 @@ const requests = (url, data = {}, contentTypeIsJSON = false, isSilence = false,
.catch(res => {
clearTimeout(_timer);
popRequest(_random);
pendingRequest.delete(key);
if (res) {
handlerErr(res.response.status, '接口异常', alertError);
}
......
......@@ -626,6 +626,7 @@ export default {
if (this.$route.meta.type === 'edit') {
params.coupCardPutOnId = this.$route.params.id; // 投放主键ID, 新建不传; 修改传
}
this.loading = true;
saveUpdatePutonCard(params)
.then(res => {
if (res.errorCode === 0) {
......@@ -639,16 +640,19 @@ export default {
this.$router.push('/card/record/send?new=1');
})
.catch(err => {
this.loading = false;
this.getCardPutonDetail();
});
} else {
this.$router.push('/card/record/send?new=1');
}
} else {
this.loading = false;
this.$tips({ type: 'error', message: '操作失败' });
}
})
.catch(err => {
this.loading = false;
this.$tips({ type: 'error', message: '操作失败' });
});
},
......
......@@ -992,7 +992,6 @@ export default {
this.loading = true;
saveEcmInfo(params)
.then(res => {
this.loading = false;
if (res.errorCode === 0) {
if (this.isEdit) {
this.$confirm('操作成功, 是否返回列表?', '提示', {
......@@ -1004,12 +1003,14 @@ export default {
this.$router.push('/ecm/list');
})
.catch(err => {
this.loading = false;
this.getEcmInfo();
});
} else {
this.$router.push('/ecm/list');
}
} else {
this.loading = false;
this.$tips({ type: 'error', message: res.message || '操作失败' });
}
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment