vue-axios-optimize 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -2
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -427,14 +427,26 @@ export function useUserStoreHook() {
|
|
|
427
427
|
this.loading = false
|
|
428
428
|
}).catch(err => {
|
|
429
429
|
// 此处需要添加 如果是取消请求 或者是 阻止请求时 不进行操作
|
|
430
|
-
if (err.
|
|
430
|
+
if (err.isPrevent || err?.message?.isCancel) {
|
|
431
431
|
return
|
|
432
432
|
}
|
|
433
433
|
this.loading = false
|
|
434
434
|
})
|
|
435
435
|
```
|
|
436
436
|
|
|
437
|
+
## 特别注意
|
|
437
438
|
|
|
439
|
+
vue2项目的vue.config.js 需要添加如下配置,对插件包进行编译。
|
|
440
|
+
|
|
441
|
+
```js
|
|
442
|
+
module.exports = {
|
|
443
|
+
...
|
|
444
|
+
transpileDependencies: [
|
|
445
|
+
"vue-axios-optimize"
|
|
446
|
+
],
|
|
447
|
+
...
|
|
448
|
+
}
|
|
449
|
+
```
|
|
438
450
|
|
|
439
451
|
## 总结
|
|
440
452
|
|
|
@@ -454,9 +466,12 @@ export function useUserStoreHook() {
|
|
|
454
466
|
|
|
455
467
|
[vue2-water-marker水印插件](https://www.npmjs.com/package/vue2-water-marker)
|
|
456
468
|
|
|
457
|
-
|
|
458
469
|
## 更新日志
|
|
459
470
|
|
|
471
|
+
### 1.0.1
|
|
472
|
+
|
|
473
|
+
1. 修复单词错误问题 isPervent 修改为 isPrevent
|
|
474
|
+
|
|
460
475
|
### 1.0.0
|
|
461
476
|
|
|
462
477
|
1. 初始版本
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class e{instance;requestObj={};requestingNum=0;authErrorArr=[];queue=[];isRefresh=!1;isShowReLoginDialog=!1;constructor(e,s,r){this.instance=s,this.instance.interceptors.request.use((s=>{s.noShowLoading||(this.requestingNum++,r.showLoadingFun&&r.showLoadingFun(s,this.requestingNum));const i=s.url;if(r.openRefresh){-1===this.authErrorArr.indexOf(i)&&this.isRefresh&&i!==r.refreshApiUrl&&this.authErrorArr.push(i)}if(i&&s.preventDuplicateRequestsType)if("cancel"===s.preventDuplicateRequestsType){this.requestObj[i]&&this.requestObj[i].cancel({config:s,isCancel:!0});const r=e.CancelToken;this.requestObj[i]=r.source(),s.cancelToken=this.requestObj[i].token}else if("prevent"===s.preventDuplicateRequestsType){if("requesting"===this.requestObj[i])return Promise.reject({config:s,
|
|
1
|
+
class e{instance;requestObj={};requestingNum=0;authErrorArr=[];queue=[];isRefresh=!1;isShowReLoginDialog=!1;constructor(e,s,r){this.instance=s,this.instance.interceptors.request.use((s=>{s.noShowLoading||(this.requestingNum++,r.showLoadingFun&&r.showLoadingFun(s,this.requestingNum));const i=s.url;if(r.openRefresh){-1===this.authErrorArr.indexOf(i)&&this.isRefresh&&i!==r.refreshApiUrl&&this.authErrorArr.push(i)}if(i&&s.preventDuplicateRequestsType)if("cancel"===s.preventDuplicateRequestsType){this.requestObj[i]&&this.requestObj[i].cancel({config:s,isCancel:!0});const r=e.CancelToken;this.requestObj[i]=r.source(),s.cancelToken=this.requestObj[i].token}else if("prevent"===s.preventDuplicateRequestsType){if("requesting"===this.requestObj[i])return Promise.reject({config:s,isPrevent:!0});this.requestObj[i]="requesting"}return s}),(e=>Promise.reject(e))),this.instance.interceptors.response.use((async e=>{const{config:s,responseErr:i}=e;if(s.noShowLoading||(this.requestingNum--,this.requestingNum<=0&&r.hideLoadingFun&&r.hideLoadingFun(s,this.requestingNum)),s&&this.requestObj[s.url]&&delete this.requestObj[s.url],i){if(r.openRefresh){const i=this.authErrorArr.indexOf(s.url);if(-1!==i)return this.authErrorArr.splice(i,1),new Promise((e=>{this.queue.push((i=>{r.setAccessTokenFun(s,i),e(this.instance.request(s))}))}));const t=r.accessTokenExpirationCode||401;if(Number(e.code)===t){const i=r.getRefreshTokenFun();if(!i){if(this.isShowReLoginDialog)return;return this.isShowReLoginDialog=!0,r.reloginFun(e),Promise.reject(new Error(e.message||"Error"))}if(this.isRefresh)return new Promise((e=>{this.queue.push((i=>{r.setAccessTokenFun(s,i),e(this.instance.request(s))}))}));this.isRefresh=!0;try{const e=await r.refreshTokenStore(i);let t=null;return t=r.formatAccessTokenFun?r.formatAccessTokenFun(e):e.data.accessToken,this.queue.forEach((e=>e(t))),this.instance.request(s)}catch{if(this.isShowReLoginDialog)return;return this.isShowReLoginDialog=!0,r.reloginFun(e),Promise.reject(new Error(e.message||"Error"))}finally{this.queue=[],this.isRefresh=!1}}const n=r.refreshTokenExpirationCode||403;if(Number(e.code)===n){if(this.isShowReLoginDialog)return;return this.isShowReLoginDialog=!0,r.reloginFun(e),Promise.reject(new Error(e.message||"Error"))}}return Promise.reject(new Error(e.message||"Error"))}const t=JSON.parse(JSON.stringify(e));return delete t.responseErr,r.responseResultFun?r.responseResultFun(t):t}),(e=>{const s=e.config||e?.message?.config||{};return s.noShowLoading||(this.requestingNum--,this.requestingNum<=0&&r.hideLoadingFun&&r.hideLoadingFun(s,this.requestingNum)),e.isPrevent||e?.message?.isCancel||delete this.requestObj[s.url],Promise.reject(e)}))}}export default e;
|