From 7cd178a12418b7fdd0b0226523332865f5e64505 Mon Sep 17 00:00:00 2001 From: liuxingyun Date: Tue, 7 Sep 2021 17:17:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E9=92=88=E5=AF=B9?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=E8=AF=B7=E6=B1=82,=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E6=8A=A5=E9=94=99,=E5=8A=A0=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http.ts | 30 ++++++++++++++++++++++++++++-- types/custom.d.ts | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/http.ts b/lib/http.ts index 151e936..655da8e 100644 --- a/lib/http.ts +++ b/lib/http.ts @@ -40,6 +40,12 @@ if (!uuid) { localStorage.setItem('_app_uuid_', uuid); } +// 拦截多次请求弹出重复错误问题 +// 目前整体看下来,只有200008这个场景会出现这种情况,其他类型的错误都会被catch掉 +// 在同一批接口中统一传入相同的_xuuids_参数 最好是随机数 +window._cblock_ = {}; +let xuuids: string = ''; + /** * 配置axios */ @@ -116,6 +122,12 @@ http.interceptors.request.use(config => { } } + xuuids = (config.params && config.params._xuuids_) || (config.data && config.data._xuuids_); + if (xuuids && window._cblock_[xuuids] === void 0) { + delete config.params._xuuids_; + window._cblock_[xuuids] = false; + } + (config as any).____t = new Date().valueOf(); return config; @@ -156,7 +168,14 @@ http.interceptors.response.use( cc.onLogin('200008'); } else { clearToken(); - toLogin(); + if (!xuuids) { + toLogin(); + } else { + if (window._cblock_[xuuids] === false) { + window._cblock_[xuuids] = true; + toLogin(); + } + } } return {}; } @@ -187,7 +206,14 @@ http.interceptors.response.use( cc.onLogin(data.resCode); } else { clearToken(); - toLogin(); + if (!xuuids) { + toLogin(); + } else { + if (window._cblock_[xuuids] === false) { + window._cblock_[xuuids] = true; + toLogin(); + } + } } return {}; } diff --git a/types/custom.d.ts b/types/custom.d.ts index 175ee6e..256d1fa 100644 --- a/types/custom.d.ts +++ b/types/custom.d.ts @@ -13,6 +13,7 @@ interface Window { swan: any; atzuche: any; NativeJsBridge: any; + _cblock_: any; } interface Window {