防止重复请求

msb_beta
ch 3 years ago
parent a703ad6a04
commit 4dd21d976c

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-17 16:36:59
* @LastEditors: ch
* @LastEditTime: 2022-04-19 18:46:25
* @LastEditTime: 2022-04-20 10:41:17
* @Description: 针对uniapp request请求做了一次封装使用思维参考axios
*
*
@ -69,15 +69,36 @@ class MsbUniRequest {
return option
}
return new Promise((resolve, reject)=>{
uni.request(option).then(res => {
const response = res[1];
if(response.statusCode >= 200 && response.statusCode < 400){
resolve(this.hook.success ? this.hook.success(response, option) : response);
return false;
uni.request({
...option,
success: res => {
const response = res || res[1];
// 200 - 399状态为正常
if(response.statusCode >= 200 && response.statusCode < 400){
if(!this.hook.success){
resolve(response);
}else{
let newRes = this.hook.success(response, option);
// 业务结果处理可能为一个Promise对象根据结果调用错误或正确状态
if(newRes.constructor === Promise){
newRes.then(res => {
resolve(res);
}, error =>{
reject(error);
})
}else{
resolve(newRes);
}
}
return false;
}
reject(this.hook.error ? this.hook.error(response, option) : response);
},
fail: error =>{
reject(this.hook.error ? this.hook.error(error, option) : error);
}
reject(this.hook.error ? this.hook.error(response, option) : response);
}).catch(error => {
reject(this.hook.error ? this.hook.error(error, option) : error);
});
});
}

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-03-17 17:42:32
* @LastEditors: ch
* @LastEditTime: 2022-04-19 18:54:15
* @LastEditTime: 2022-04-20 11:03:08
* @Description: 项目接口请求统一处理器返回一个需要token和不需要token的请求封装方法
*/
@ -11,8 +11,8 @@ import $store from '@/common/store';
const ENV = 'test';
const BASE_URL = {
// 'test' : 'http://k8s-horse-gateway.mashibing.cn',
'test' : '',
'test' : 'http://k8s-horse-gateway.mashibing.cn',
// 'test' : '',
'release' : '',
'prod' : ''
};
@ -74,6 +74,7 @@ const MsbRequest = new MsbUniRequest();
MsbRequest.baseUrl = BASE_URL[ENV];
MsbRequest.use('request', (option) => {
console.log('option',option);
if(option.header.repeat){
// 如果当前请求不允许重复调用,则检查重复请求,当前接口有正在请求则不发起请求
const isRepeatVerify = repeatVerify(option);

@ -1,2 +1,2 @@
<!DOCTYPE html><html lang=zh-CN><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><title>马士兵严选</title><script>var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=/static/index.a5c69d49.css></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=/static/js/chunk-vendors.a572362a.js></script><script src=/static/js/index.c845cec7.js></script></body></html>
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=/static/index.a5c69d49.css></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=/static/js/chunk-vendors.b5602bf5.js></script><script src=/static/js/index.70f3e4b8.js></script></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1 @@
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["pages-cart-cart"],{"0ba2":function(n,t,a){"use strict";var e=a("4ea4");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=e(a("734f")),c={components:{PageCtx:r.default},onShow:function(){this.$refs.page&&this.$refs.page.open()},mounted:function(){this.$refs.page.open()}};t.default=c},"0ddb":function(n,t,a){var e=a("24fb");t=e(!1),t.push([n.i,'@charset "UTF-8";\n/**\n * 这里是uni-app内置的常用样式变量\n *\n * uni-app 官方扩展插件及插件市场https://ext.dcloud.net.cn上很多三方插件均使用了这些样式变量\n * 如果你是插件开发者建议你使用scss预处理并在插件代码中直接使用这些变量无需 import 这个文件方便用户通过搭积木的方式开发整体风格一致的App\n *\n */\n/**\n * 如果你是App开发者插件使用者你可以通过修改这些变量来定制自己的插件主题实现自定义主题功能\n *\n * 如果你的项目同样使用了scss预处理你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件\n */\n/* 颜色变量 */\n/* 行为相关颜色 */\n/* 文字基本颜色 */\n/* 背景颜色 */\n/* 边框颜色 */\n/* 透明度 */\n/* 尺寸变量 */\n/* 文字尺寸 */\n/* 间距 */\n/* 图片尺寸 */\n/* Border Radius */\n/* 水平间距 */\n/* 垂直间距 */uni-page-body[data-v-529a9cda]{background:#f5f5f5;padding-bottom:%?120?%}body.?%PAGE?%[data-v-529a9cda]{background:#f5f5f5}',""]),n.exports=t},"4a3c":function(n,t,a){"use strict";var e=a("c267"),r=a.n(e);r.a},b408:function(n,t,a){"use strict";var e;a.d(t,"b",(function(){return r})),a.d(t,"c",(function(){return c})),a.d(t,"a",(function(){return e}));var r=function(){var n=this,t=n.$createElement,a=n._self._c||t;return a("PageCtx",{ref:"page",staticClass:"page",attrs:{type:"inner"}})},c=[]},c267:function(n,t,a){var e=a("0ddb");"string"===typeof e&&(e=[[n.i,e,""]]),e.locals&&(n.exports=e.locals);var r=a("4f06").default;r("1edb3d4a",e,!0,{sourceMap:!1,shadowMode:!1})},e81f:function(n,t,a){"use strict";a.r(t);var e=a("0ba2"),r=a.n(e);for(var c in e)"default"!==c&&function(n){a.d(t,n,(function(){return e[n]}))}(c);t["default"]=r.a},f662:function(n,t,a){"use strict";a.r(t);var e=a("b408"),r=a("e81f");for(var c in r)"default"!==c&&function(n){a.d(t,n,(function(){return r[n]}))}(c);a("4a3c");var o,u=a("f0c5"),s=Object(u["a"])(r["default"],e["b"],e["c"],!1,null,"529a9cda",null,!1,e["a"],o);t["default"]=s.exports}}]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1 @@
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["pages-cart-tabBarCart"],{1266:function(n,t,e){"use strict";e.r(t);var a=e("bcdd"),r=e("fb42");for(var f in r)"default"!==f&&function(n){e.d(t,n,(function(){return r[n]}))}(f);e("9a1ff");var o,u=e("f0c5"),s=Object(u["a"])(r["default"],a["b"],a["c"],!1,null,"761ed496",null,!1,a["a"],o);t["default"]=s.exports},1952:function(n,t,e){var a=e("24fb");t=a(!1),t.push([n.i,'@charset "UTF-8";\n/**\n * 这里是uni-app内置的常用样式变量\n *\n * uni-app 官方扩展插件及插件市场https://ext.dcloud.net.cn上很多三方插件均使用了这些样式变量\n * 如果你是插件开发者建议你使用scss预处理并在插件代码中直接使用这些变量无需 import 这个文件方便用户通过搭积木的方式开发整体风格一致的App\n *\n */\n/**\n * 如果你是App开发者插件使用者你可以通过修改这些变量来定制自己的插件主题实现自定义主题功能\n *\n * 如果你的项目同样使用了scss预处理你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件\n */\n/* 颜色变量 */\n/* 行为相关颜色 */\n/* 文字基本颜色 */\n/* 背景颜色 */\n/* 边框颜色 */\n/* 透明度 */\n/* 尺寸变量 */\n/* 文字尺寸 */\n/* 间距 */\n/* 图片尺寸 */\n/* Border Radius */\n/* 水平间距 */\n/* 垂直间距 */uni-page-body[data-v-761ed496]{background:#f5f5f5;padding-bottom:%?240?%}body.?%PAGE?%[data-v-761ed496]{background:#f5f5f5}',""]),n.exports=t},"26d2":function(n,t,e){var a=e("1952");"string"===typeof a&&(a=[[n.i,a,""]]),a.locals&&(n.exports=a.locals);var r=e("4f06").default;r("73cf590f",a,!0,{sourceMap:!1,shadowMode:!1})},"9a1ff":function(n,t,e){"use strict";var a=e("26d2"),r=e.n(a);r.a},bcdd:function(n,t,e){"use strict";var a;e.d(t,"b",(function(){return r})),e.d(t,"c",(function(){return f})),e.d(t,"a",(function(){return a}));var r=function(){var n=this,t=n.$createElement,e=n._self._c||t;return e("PageCtx",{ref:"page",staticClass:"page",attrs:{type:"tabBar"}})},f=[]},e625:function(n,t,e){"use strict";var a=e("4ea4");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var r=a(e("734f")),f={components:{PageCtx:r.default},onShow:function(){this.$refs.page&&this.$refs.page.open()},mounted:function(){this.$refs.page.open()}};t.default=f},fb42:function(n,t,e){"use strict";e.r(t);var a=e("e625"),r=e.n(a);for(var f in a)"default"!==f&&function(n){e.d(t,n,(function(){return a[n]}))}(f);t["default"]=r.a}}]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save